The implementation basically just uses read-only rich text editor with manual handling of all key events and modifying rich text model accordingly. The commands are just delegated to fansh::Shell.
It was a bit tricky to make sys::Obj#echo support in shell, since it writes directly to stdout. I have modified the fansh sources (so I had to copy them into my pod) in that way:
Changed transient class:
added field StrBuf out
added method Void shell_echo(Obj?) which appends arg to buffer
Added code to replace echo in user input with shell_echo
Added code to display contents of this buffer in the UI
There are two problems with this solution, but I think it is reasonable trade-off:
If any code invoked from shell calls echo indirectly, it won't be displayed in the UI
If user input contains echo as substring (like myEcho := "echo"), input will be corrupted
EDIT: corrected bitbucket link
brianFri 10 Sep 2010
That looks really cool.
Regarding echo, what if we changed implementation of echo to route to Env.cur.out? Then you could run with a custom Env that traps all IO to stdout?
ivanFri 10 Sep 2010
So I can create some custom environment which uses proxy output stream to notify about new data in stdout. This will work even in Eclipse environment, where some non-Fantom plugins can write some garbage to stdout, we just won't care about it. Great, this should work!
Great news. Plus it is fwt so online shell for newcomers is in the air ;)
ivanMon 13 Sep 2010
With just 20 lines of code added support for transient types:
ivanMon 13 Sep 2010
More changes:
Transient types are listed in scope output:
Current Usings:
using sh4::Foo
using sh5::Bar
Current Scope:
sys::Int i = 3
sh4::Foo b = fan.sh4.Foo@7a354749
Stdout is being captured now
fansh> echo("hello, shell!")
hello, shell!
fansh>
Stdout capture will work only with the latest version from fantom repo (see patch from Brian above) and with overridden environment (fwtsh::LoggingEnv). The source in bitbucket includes fwtsh script which sets Fantom environment and launches shell.
ivan Fri 10 Sep 2010
Hey,
Today I've made a prototype for fwt-based Fantom shell app, which I plan to include into F4 later, now it looks like this:
Features:
{
,[
and(
have matches, no escape yet supported)Not done yet:
The code is located at http://bitbucket.org/ivan_inozemtsev/fwtsh
The implementation basically just uses read-only rich text editor with manual handling of all key events and modifying rich text model accordingly. The commands are just delegated to
fansh::Shell
.It was a bit tricky to make sys::Obj#echo support in shell, since it writes directly to stdout. I have modified the fansh sources (so I had to copy them into my pod) in that way:
StrBuf out
Void shell_echo(Obj?)
which appends arg to bufferecho
in user input withshell_echo
There are two problems with this solution, but I think it is reasonable trade-off:
echo
indirectly, it won't be displayed in the UIecho
as substring (likemyEcho := "echo"
), input will be corruptedEDIT: corrected bitbucket link
brian Fri 10 Sep 2010
That looks really cool.
Regarding echo, what if we changed implementation of echo to route to
Env.cur.out
? Then you could run with a custom Env that traps all IO to stdout?ivan Fri 10 Sep 2010
So I can create some custom environment which uses proxy output stream to notify about new data in stdout. This will work even in Eclipse environment, where some non-Fantom plugins can write some garbage to stdout, we just won't care about it. Great, this should work!
brian Fri 10 Sep 2010
Try out this patch
katox Fri 10 Sep 2010
Great news. Plus it is fwt so online shell for newcomers is in the air ;)
ivan Mon 13 Sep 2010
With just 20 lines of code added support for transient types:
ivan Mon 13 Sep 2010
More changes:
scope
output:Stdout capture will work only with the latest version from fantom repo (see patch from Brian above) and with overridden environment (
fwtsh::LoggingEnv
). The source in bitbucket includesfwtsh
script which sets Fantom environment and launches shell.ivan Mon 13 Sep 2010
Added copy/paste support though it was tricky:
So I made a hack - added invisible Text control to my shell and implemented paste with it like this: