aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-07-13 09:47:40 +1000
committerSteve Bennett <steveb@workware.net.au>2023-08-13 12:43:28 +1000
commit9784dcf88e8f0204550b4218f1c77bfa510a497b (patch)
treed5fa4adb6dcb2d26dd541a1fc1dcbc134101fdf3
parent3c9587340bcd62eef8e246fcd1c0a2469943898f (diff)
downloadjimtcl-9784dcf88e8f0204550b4218f1c77bfa510a497b.zip
jimtcl-9784dcf88e8f0204550b4218f1c77bfa510a497b.tar.gz
jimtcl-9784dcf88e8f0204550b4218f1c77bfa510a497b.tar.bz2
jimsh, interp, tests: fixes when line editing is disabled
- 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.def6
-rw-r--r--jim-interp.c12
-rw-r--r--jim_tcl.txt4
-rw-r--r--jimsh.c5
-rw-r--r--tests/history.test1
-rw-r--r--tests/interactive.test13
6 files changed, 28 insertions, 13 deletions
diff --git a/auto.def b/auto.def
index 162f7d2..93cbdbf 100644
--- a/auto.def
+++ b/auto.def
@@ -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*+::
diff --git a/jimsh.c b/jimsh.c
index 0ed045f..6104afb 100644
--- a/jimsh.c
+++ b/jimsh.c
@@ -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