diff options
author | Steve Bennett <steveb@workware.net.au> | 2023-07-13 09:47:40 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2023-08-13 10:04:47 +1000 |
commit | 4cfe38ed16abf8a1dce94e450906ae81008f976e (patch) | |
tree | d82c8e4971bf025fd5d437617c99a322e37d8c74 | |
parent | 28570844204707fc01a735104fc89284d9eae766 (diff) | |
download | jimtcl-4cfe38ed16abf8a1dce94e450906ae81008f976e.zip jimtcl-4cfe38ed16abf8a1dce94e450906ae81008f976e.tar.gz jimtcl-4cfe38ed16abf8a1dce94e450906ae81008f976e.tar.bz2 |
fixes when line editing is disabledlineedit-disable
- Set jim::lineedit to indicate if line editing is configured
- Ensure that aio tty works even if line editing is disabled
- Skip some tests if line editing is not configured
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | auto.def | 6 | ||||
-rw-r--r-- | jim-interp.c | 12 | ||||
-rw-r--r-- | jim_tcl.txt | 4 | ||||
-rw-r--r-- | jimsh.c | 5 | ||||
-rw-r--r-- | tests/history.test | 1 | ||||
-rw-r--r-- | tests/interactive.test | 13 |
6 files changed, 28 insertions, 13 deletions
@@ -464,8 +464,10 @@ if {[opt-bool-unless-minimal ssl]} { define-append AS_CFLAGS -DUSE_TLSv1_2_method } } -if {[opt-bool-unless-minimal lineedit]} { - if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} { + +# Still need to check termios.h and isatty even if lineedit is disabled +if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} { + if {[opt-bool-unless-minimal lineedit]} { msg-result "Enabling line editing" define USE_LINENOISE define-append PARSE_UNIDATA_FLAGS -width diff --git a/jim-interp.c b/jim-interp.c index 90e2474..8868076 100644 --- a/jim-interp.c +++ b/jim-interp.c @@ -141,6 +141,10 @@ static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { Jim_Interp *child; char buf[34]; + int i; + static const char * const copyvars[] = { + "argv", "argc", "argv0", "jim::argv0", "jim::exe", "jim::lineedit", NULL + }; if (argc != 1) { Jim_WrongNumArgs(interp, 1, argv, ""); @@ -153,11 +157,9 @@ static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_InitStaticExtensions(child); /* Copy some core variables to the new interpreter */ - JimInterpCopyVariable(child, interp, "argv", NULL); - JimInterpCopyVariable(child, interp, "argc", NULL); - JimInterpCopyVariable(child, interp, "argv0", NULL); - JimInterpCopyVariable(child, interp, "jim::argv0", NULL); - JimInterpCopyVariable(child, interp, "jim::exe", NULL); + for (i = 0; copyvars[i]; i++) { + JimInterpCopyVariable(child, interp, copyvars[i], NULL); + } /* Allow the child interpreter to find the parent */ Jim_SetAssocData(child, "interp.parent", NULL, interp); diff --git a/jim_tcl.txt b/jim_tcl.txt index 67d5adc..83dd9c8 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -5888,6 +5888,10 @@ The following global variables are set by jimsh. +*jim::argv0*+:: The value of argv[0] when jimsh was invoked. ++*jim::lineedit*+:: + This variables is set to 1 if jimsh was configured with line editing support, + or 0 if not. + The following variables have special meaning to Jim Tcl: +*jim::defer*+:: @@ -109,6 +109,11 @@ int main(int argc, char *const argv[]) Jim_SetVariableStrWithStr(interp, "jim::argv0", orig_argv0); Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, argc == 1 ? "1" : "0"); +#ifdef USE_LINENOISE + Jim_SetVariableStrWithStr(interp, "jim::lineedit", "1"); +#else + Jim_SetVariableStrWithStr(interp, "jim::lineedit", "0"); +#endif retcode = Jim_initjimshInit(interp); if (argc == 1) { diff --git a/tests/history.test b/tests/history.test index 9abf0ef..e0ff0e2 100644 --- a/tests/history.test +++ b/tests/history.test @@ -1,6 +1,7 @@ source [file dirname [info script]]/testing.tcl needs cmd {history save} +needs expr "jim::lineedit" {$jim::lineedit} test history-1.1 {history usage} -body { history diff --git a/tests/interactive.test b/tests/interactive.test index a853bc8..8d19512 100644 --- a/tests/interactive.test +++ b/tests/interactive.test @@ -3,6 +3,7 @@ source [file dirname [info script]]/testing.tcl needs constraint jim needs cmd socket needs eval "socket pty" {lmap p [socket pty] { $p close }} +constraint expr lineedit {$jim::lineedit} package require expect @@ -44,7 +45,7 @@ test interactive-1.1 {basic command} -body { wait-for-prompt $p } -test interactive-1.2 {command line completion} { +test interactive-1.2 {command line completion} lineedit { set check 0 set failed 0 $p send "li\t" @@ -62,7 +63,7 @@ test interactive-1.2 {command line completion} { list $check $failed } {3 0} -test interactive-1.3 {history show} -body { +test interactive-1.3 {history show} -constraints lineedit -body { $p send "history show\r" $p expect {\r\n} $p expect {history show\r\n} @@ -71,7 +72,7 @@ test interactive-1.3 {history show} -body { wait-for-prompt $p } -test interactive-1.4 {history getline} -body { +test interactive-1.4 {history getline} -constraints lineedit -body { $p send "history getline {PROMPT> }\r" $p expect {\r\n} sleep 0.25 @@ -83,7 +84,7 @@ test interactive-1.4 {history getline} -body { wait-for-prompt $p } -test interactive-1.4 {history getline} -body { +test interactive-1.5 {history getline} -constraints lineedit -body { $p send "set len \[history getline {PROMPT> } buf\]\r" $p expect {\r\n} sleep 0.25 @@ -100,7 +101,7 @@ test interactive-1.4 {history getline} -body { wait-for-prompt $p } -test interactive-1.5 {insert wide character} -constraints utf8 -body { +test interactive-1.6 {insert wide character} -constraints {utf8 lineedit} -body { $p send "set x a\u1100b" # now arrow left twice over the wide char and insert another char $p send \x1bOD @@ -115,7 +116,7 @@ test interactive-1.5 {insert wide character} -constraints utf8 -body { wait-for-prompt $p } -test interactive-1.6 {insert utf-8 combining character} -constraints utf8 -body { +test interactive-1.7 {insert utf-8 combining character} -constraints {utf8 lineedit} -body { $p send "set x x\u0300" # now arrow left twice over the combining char and "x" and insert another char $p send \x1bOD |