Enhanced shell windows

Joe Allen
3 days ago
3 days ago
  • Joe Allen
    Joe Allen
    3 days ago

    Give the ansi_shell branch in mercurial a try... (hg update -C ansi_shell).

    It has a bunch of ideas I'm trying out:

    Hit F1 - F4 to open and switch between shell windows.

    The terminal emulator is improved so that when you type "man ls" it's formatted correctly (it's improved enough so that some interactive programs will work in it). Even so, the shell window is still an edit buffer.

    More of the keys get passed to the running program. There is a :shell section of the joerc file to indicate which ones. In particular arrow keys and Ctrl-C are passed to the program. It means you can easily step through bash history with the arrow keys, or abort programs the normal way with Ctrl-C.

    On the other hand, loss of Ctrl-C means it's less obvious how to close the window. One way is to move the cursor off of the shell data entry point (with Ctrl-P), and then hit Ctrl-C.

    To quickly position the cursor back to the point where data is entered into the shell, hit ^K V.

    When you open a shell window, a JOE-specific startup-script is sourced. It's located in /etc/joe/shell.sh (also /etc/joe/shell.csh). It contains some aliases which allow you to control JOE with fake shell commands. I have these commands so far:

    Command Action
    clear erase shell window (delete buffer contents)
    edit file edit a file in JOE
    math equation evaluate equation using JOE's calculator
    cd xyz change directory and set current directory in JOE to the new directory

    These work by emitting an escape sequence recognized by the terminal emulator: ESC { joe_macro }. When this is received, the macro is executed. For sure this is a security hole, and I've not worked out how to fix it yet.

    One nice use of the shell window is to use JOE's error parser on grep output. Try this example:

    clear                erase shell window
    grep -n FIXME *.c    generate list of files with line numbers
    ESC x parserr        parse the list
    

    Now use ^P to position the cursor on one of the lines of the list. Hit ESC SPACE to have JOE edit the file and jump to the specified line (also you can use ESC - and ESC = to step through them).

    I'm thinking of somehow making this more automatic, so that you don't have to issue the parserr command.

    How it works..

    1. There is a new mode "ansi". (ESC x mode ansi). When this mode is enabled, the screen updater hides escape sequences which are in the buffer. Otherwise you get a big mess from the sequences surrounding colored output from 'ls'.

    2. There is a new built-in syntax: "ansi". (^T y ansi). This syntax parses the ANSI color control sequences so that text gets colored.

    3. There is a terminal emulator to interpret control sequences from the shell program. It emulates a terminal by modifying the contents of an edit buffer.

    4. When the edit window is resized we tell the shell by issuing the TIOCSSIZE or TIOCSWINSZ ioctl. This way, the program running in the shell knows the window size.

     
    Last edit: Joe Allen 3 days ago