diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-12-06 08:56:35 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-12-09 12:10:33 +1000 |
commit | 8e90299b82be4dc6c8c86dbd206db9e0efdbffc6 (patch) | |
tree | bf75cde4346bec5000f5566cc4421703e912d53a /examples | |
parent | a2fe8bd6794e017117986dfa11619fbf00b62239 (diff) | |
download | jimtcl-8e90299b82be4dc6c8c86dbd206db9e0efdbffc6.zip jimtcl-8e90299b82be4dc6c8c86dbd206db9e0efdbffc6.tar.gz jimtcl-8e90299b82be4dc6c8c86dbd206db9e0efdbffc6.tar.bz2 |
Add the history command
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/jtclsh.tcl | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/jtclsh.tcl b/examples/jtclsh.tcl new file mode 100644 index 0000000..dc92bca --- /dev/null +++ b/examples/jtclsh.tcl @@ -0,0 +1,36 @@ +# Simple example of how the history extension +# can be used to provide line editing and history + +# Build jimsh with the history extension and enable line editing (the default) +# ./configure --with-ext=history + +package require history + +set histfile [env HOME]/.jtclsh +history load $histfile +while 1 { + if {[history getline "jim> " cmd] < 0} { + break + } + if {$cmd eq "h"} { + history show + continue + } + # Don't bother adding single char commands to the history + if {[string length $cmd] > 1} { + history add $cmd + history save $histfile + } + # jimsh also does: + # - check for a complete command: [info complete] + # - handle other non-error return codes and changes the prompt: [info returncodes] + # - displays the complete error message: [errorInfo] + try { + set result [eval $cmd] + if {$result ne {}} { + puts $result + } + } on error msg { + puts $msg + } +} |