Version 0 of A minimal console

Updated 2001-03-21 22:10:13

Richard Suchenwirth -- The following 14-command codelet gives you a window with entry and text widget, where you type commands into the entry, hit Return, and get the results (or error message) of evaluating the entry content in the text widget:

 entry .e -textvar cmd
 bind .e <Key-Return> {go %W}
 text .t -wrap word
 proc go {w} {
    global cmd
    .t insert end "% $cmd\n"
    catch {eval $cmd} res
    .t insert end $res\n
    set cmd ""
 }
 eval pack [winfo children .] -fill both -expand 1
 focus .e

which allows you to source any file and call any Tcl command you might want. Of course, this can be expanded with colors to distinguish stdin/out/err, an entry with a history, menus (see Menus made easy), whatever.

But, in all simplicity, this requires the user to know what he's doing. Nothing prevents this code from evaluating "exec format c:"...

Eh? Why would you care if somebody did that? Does the widget make that do something other than this:

 pehrens@marfik ~:>>tclsh
 % exec format c:
 No permission (or no disks found)!
 %

%-)


See console for Unix for Donald Porter's more elaborated console. Tk for Windows has a built-in console that you can have come up just with the command

 console show

See Windows wish console for hints how to extend that.


Jeffrey Hobbs -- On the subject of consoles, if you don't need lightweight, you might want to check out http://tkcon.sourceforge.net/ for a cross-platform console environment with lots of features. There is a megawidget version at http://www.purl.org/net/hobbs/tcl/ .


Arts and crafts of Tcl-Tk programming