Skip to content

Commit 9784dcf

Browse files
committed
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>
1 parent 3c95873 commit 9784dcf

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

auto.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ if {[opt-bool-unless-minimal ssl]} {
464464
define-append AS_CFLAGS -DUSE_TLSv1_2_method
465465
}
466466
}
467-
if {[opt-bool-unless-minimal lineedit]} {
468-
if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
467+
468+
# Still need to check termios.h and isatty even if lineedit is disabled
469+
if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
470+
if {[opt-bool-unless-minimal lineedit]} {
469471
msg-result "Enabling line editing"
470472
define USE_LINENOISE
471473
define-append PARSE_UNIDATA_FLAGS -width

jim-interp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
141141
{
142142
Jim_Interp *child;
143143
char buf[34];
144+
int i;
145+
static const char * const copyvars[] = {
146+
"argv", "argc", "argv0", "jim::argv0", "jim::exe", "jim::lineedit", NULL
147+
};
144148

145149
if (argc != 1) {
146150
Jim_WrongNumArgs(interp, 1, argv, "");
@@ -153,11 +157,9 @@ static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
153157
Jim_InitStaticExtensions(child);
154158

155159
/* Copy some core variables to the new interpreter */
156-
JimInterpCopyVariable(child, interp, "argv", NULL);
157-
JimInterpCopyVariable(child, interp, "argc", NULL);
158-
JimInterpCopyVariable(child, interp, "argv0", NULL);
159-
JimInterpCopyVariable(child, interp, "jim::argv0", NULL);
160-
JimInterpCopyVariable(child, interp, "jim::exe", NULL);
160+
for (i = 0; copyvars[i]; i++) {
161+
JimInterpCopyVariable(child, interp, copyvars[i], NULL);
162+
}
161163

162164
/* Allow the child interpreter to find the parent */
163165
Jim_SetAssocData(child, "interp.parent", NULL, interp);

jim_tcl.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5888,6 +5888,10 @@ The following global variables are set by jimsh.
58885888
+*jim::argv0*+::
58895889
The value of argv[0] when jimsh was invoked.
58905890

5891+
+*jim::lineedit*+::
5892+
This variables is set to 1 if jimsh was configured with line editing support,
5893+
or 0 if not.
5894+
58915895
The following variables have special meaning to Jim Tcl:
58925896

58935897
+*jim::defer*+::

jimsh.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ int main(int argc, char *const argv[])
109109

110110
Jim_SetVariableStrWithStr(interp, "jim::argv0", orig_argv0);
111111
Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, argc == 1 ? "1" : "0");
112+
#ifdef USE_LINENOISE
113+
Jim_SetVariableStrWithStr(interp, "jim::lineedit", "1");
114+
#else
115+
Jim_SetVariableStrWithStr(interp, "jim::lineedit", "0");
116+
#endif
112117
retcode = Jim_initjimshInit(interp);
113118

114119
if (argc == 1) {

tests/history.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source [file dirname [info script]]/testing.tcl
22

33
needs cmd {history save}
4+
needs expr "jim::lineedit" {$jim::lineedit}
45

56
test history-1.1 {history usage} -body {
67
history

tests/interactive.test

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source [file dirname [info script]]/testing.tcl
33
needs constraint jim
44
needs cmd socket
55
needs eval "socket pty" {lmap p [socket pty] { $p close }}
6+
constraint expr lineedit {$jim::lineedit}
67

78
package require expect
89

@@ -44,7 +45,7 @@ test interactive-1.1 {basic command} -body {
4445
wait-for-prompt $p
4546
}
4647

47-
test interactive-1.2 {command line completion} {
48+
test interactive-1.2 {command line completion} lineedit {
4849
set check 0
4950
set failed 0
5051
$p send "li\t"
@@ -62,7 +63,7 @@ test interactive-1.2 {command line completion} {
6263
list $check $failed
6364
} {3 0}
6465

65-
test interactive-1.3 {history show} -body {
66+
test interactive-1.3 {history show} -constraints lineedit -body {
6667
$p send "history show\r"
6768
$p expect {\r\n}
6869
$p expect {history show\r\n}
@@ -71,7 +72,7 @@ test interactive-1.3 {history show} -body {
7172
wait-for-prompt $p
7273
}
7374

74-
test interactive-1.4 {history getline} -body {
75+
test interactive-1.4 {history getline} -constraints lineedit -body {
7576
$p send "history getline {PROMPT> }\r"
7677
$p expect {\r\n}
7778
sleep 0.25
@@ -83,7 +84,7 @@ test interactive-1.4 {history getline} -body {
8384
wait-for-prompt $p
8485
}
8586

86-
test interactive-1.4 {history getline} -body {
87+
test interactive-1.5 {history getline} -constraints lineedit -body {
8788
$p send "set len \[history getline {PROMPT> } buf\]\r"
8889
$p expect {\r\n}
8990
sleep 0.25
@@ -100,7 +101,7 @@ test interactive-1.4 {history getline} -body {
100101
wait-for-prompt $p
101102
}
102103

103-
test interactive-1.5 {insert wide character} -constraints utf8 -body {
104+
test interactive-1.6 {insert wide character} -constraints {utf8 lineedit} -body {
104105
$p send "set x a\u1100b"
105106
# now arrow left twice over the wide char and insert another char
106107
$p send \x1bOD
@@ -115,7 +116,7 @@ test interactive-1.5 {insert wide character} -constraints utf8 -body {
115116
wait-for-prompt $p
116117
}
117118

118-
test interactive-1.6 {insert utf-8 combining character} -constraints utf8 -body {
119+
test interactive-1.7 {insert utf-8 combining character} -constraints {utf8 lineedit} -body {
119120
$p send "set x x\u0300"
120121
# now arrow left twice over the combining char and "x" and insert another char
121122
$p send \x1bOD

0 commit comments

Comments
 (0)