I recently did some UI experiments, and wanted to share the results
and ask for insights.
It's been long that I've suspected that there must be something
fundamentally wrong about depending on emulation of a 1970's piece of
hardware in order to give power to our command lines. So far I've only
been trying out ideas on paper and in my head, thinking what could
work the best. A few days ago I saw TermKit announced, also saw the
thread on this list. So I've decided to turn some of my ideas into
code and over the past few days came up with mret. Grab the code,
it depends on Python and Tkinter.
Basically, it's just a working prototype. It's a frankenstein made up
of bits of Python, shell and Tcl. A quick and dirty hack that gave
interesting results. And I believe that a rewrite in C or Tcl will be
necessary - it seems that Python doesn't really give you complete
control over Tk.
So, what you get is something like a terminal emulator, but not
exactly. There's a window with two buffers, one for input and one for
output. You type in shell commands into one and see their results in
the other. You could choose which shell to run - so far tested only
with dash, but it might work unchanged with python, rc, whatever.
Surprisingly, many standard Unix commands either Just Work, or fail
gracefully (like su, complaining that it isn't attached to a
terminal). I even did an "aptitude dist-upgrade": when it asked
questions interactively, it worked, and it didn't mess up the output
buffer trying to "draw" progress bars during download.
However, this isn't really what is interesting here. (As a matter of
fact, mret is incredibly crappy as a typical terminal emulator.) The
nice thing is that Tk's text widget is actually a real editor widget.
Features like: dynamic line wrapping upon resize, X selection,
scrolling - those all work out of the box with no additional code. But
the one thing I really like about Tk is that the text widget can embed
arbitrary stuff in it: images, drawable canvases, buttons, progress
bars, entire windows, whatever you wish.
So I've been trying to come up with a sane interface exposing this
capability to programs and scripts running under mret. I thought about
creating an ad-hoc language of escape codes, but that would probably
end up being a total mess and still wouldn't expose full capabilities
of Tk. So, why not simply pipe Tcl commands right into the interpreter
governing the Tk GUI?
In the end, you are able to run scripts like this:
[ -z "$WISHPIPE" ] && exit 1
echo "image create photo mypic -file mypic.gif" >&$WISHPIPE
echo ".mret.output image create end -image mypic" >&$WISHPIPE
WISHPIPE is exported by mret and holds a file descriptor, pointing to
a pipe. At the other end of that pipe is the same Tcl interpreter that
Python uses to draw the Tk GUI. The interface seems fairly nice to me,
and properly written programs should be always able to detect if they
can take advantage of mret's capabilities.
There are a few simple scripts in the distribution. Try typing these
commands into mret's input:
./image.sh sr sr.gif
I imagine that if this thing would take off, there could be a standard
library of scripts for displaying and manipulating thumbnails,
progress bars, canvases, whatever we could come up with. Also, it
seems that there's much more you could do with Tcl&Tk: I'm thinking,
dynamically adding a statusbar widget to the window, hacking the input
buffer to do history/command completion, things like this. But I'm a
Tcl newbie so no idea.
Feedback is very welcome.
Received on Wed May 25 2011 - 16:50:36 CEST
This archive was generated by hypermail 2.2.0 : Wed May 25 2011 - 17:00:05 CEST