#1205 Fantom shell with history and highlighting

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:

Fantom UI Shell

Features:

  • Up/Down arrows to browse for a history
  • Multiline commands support (right now it just checks that all {, [ and ( have matches, no escape yet supported)
  • Primitive coloring - prompts are green, commands are blue, errors are red and output is black.

Not done yet:

  • copy/paste support
  • selection management - removal of selected text, usage of shift+arrows to modify selection

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:

  • 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:

  1. If any code invoked from shell calls echo indirectly, it won't be displayed in the UI
  2. If user input contains echo as substring (like myEcho := "echo"), input will be corrupted

EDIT: 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:

Types in the shell

ivan Mon 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 Mon 13 Sep 2010

Added copy/paste support though it was tricky:

  • since my rich text is read-only, fwt::TextWidget#paste is not working
  • there's no direct access to clipboard

So I made a hack - added invisible Text control to my shell and implemented paste with it like this:

invisible.paste
text := invisible.text
invisible.text = ""
... //use text 

Login or Signup to reply.