mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Fix upstream Lua test breakage due to Linenoise
This commit is contained in:
parent
65f32fad52
commit
d5a37de435
2 changed files with 28 additions and 18 deletions
15
third_party/linenoise/linenoise.c
vendored
15
third_party/linenoise/linenoise.c
vendored
|
@ -289,7 +289,7 @@ static int isUnsupportedTerm(void) {
|
||||||
/* Raw mode: 1960's magic. */
|
/* Raw mode: 1960's magic. */
|
||||||
static int enableRawMode(int fd) {
|
static int enableRawMode(int fd) {
|
||||||
struct termios raw;
|
struct termios raw;
|
||||||
if (!isatty(STDIN_FILENO)) goto fatal;
|
if (!isatty(fileno(stdin))) goto fatal;
|
||||||
if (!atexit_registered) {
|
if (!atexit_registered) {
|
||||||
atexit(linenoiseAtExit);
|
atexit(linenoiseAtExit);
|
||||||
atexit_registered = 1;
|
atexit_registered = 1;
|
||||||
|
@ -320,6 +320,7 @@ fatal:
|
||||||
|
|
||||||
void linenoiseDisableRawMode(int fd) {
|
void linenoiseDisableRawMode(int fd) {
|
||||||
/* Don't even check the return value as it's too late. */
|
/* Don't even check the return value as it's too late. */
|
||||||
|
if (!isatty(fileno(stdin))) return;
|
||||||
if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
|
if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1)
|
||||||
rawmode = 0;
|
rawmode = 0;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +379,7 @@ failed:
|
||||||
|
|
||||||
/* Clear the screen. Used to handle ctrl+l */
|
/* Clear the screen. Used to handle ctrl+l */
|
||||||
void linenoiseClearScreen(void) {
|
void linenoiseClearScreen(void) {
|
||||||
if (write(STDOUT_FILENO,"\e[H\e[2J",7) <= 0) {
|
if (write(fileno(stdout),"\e[H\e[2J",7) <= 0) {
|
||||||
/* nothing to do, just to avoid warning. */
|
/* nothing to do, just to avoid warning. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1054,9 +1055,9 @@ static int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (enableRawMode(STDIN_FILENO) == -1) return -1;
|
if (enableRawMode(fileno(stdin)) == -1) return -1;
|
||||||
count = linenoiseEdit(STDIN_FILENO, STDOUT_FILENO, buf, buflen, prompt);
|
count = linenoiseEdit(fileno(stdin), fileno(stdout), buf, buflen, prompt);
|
||||||
linenoiseDisableRawMode(STDIN_FILENO);
|
linenoiseDisableRawMode(fileno(stdin));
|
||||||
if (count != -1) printf("\n");
|
if (count != -1) printf("\n");
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -1104,7 +1105,7 @@ static char *linenoiseNoTTY(void) {
|
||||||
char *linenoise(const char *prompt) {
|
char *linenoise(const char *prompt) {
|
||||||
int count;
|
int count;
|
||||||
char *buf;
|
char *buf;
|
||||||
if (!isatty(STDIN_FILENO)) {
|
if (!isatty(fileno(stdin))) {
|
||||||
/* Not a tty: read from file / pipe. In this mode we don't want any
|
/* Not a tty: read from file / pipe. In this mode we don't want any
|
||||||
* limit to the line size, so we call a function to handle that. */
|
* limit to the line size, so we call a function to handle that. */
|
||||||
return linenoiseNoTTY();
|
return linenoiseNoTTY();
|
||||||
|
@ -1143,7 +1144,7 @@ void linenoiseHistoryFree(void) {
|
||||||
|
|
||||||
/* At exit we'll try to fix the terminal to the initial conditions. */
|
/* At exit we'll try to fix the terminal to the initial conditions. */
|
||||||
static void linenoiseAtExit(void) {
|
static void linenoiseAtExit(void) {
|
||||||
linenoiseDisableRawMode(STDIN_FILENO);
|
linenoiseDisableRawMode(fileno(stdin));
|
||||||
linenoiseHistoryFree();
|
linenoiseHistoryFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
third_party/lua/test/main.lua
vendored
31
third_party/lua/test/main.lua
vendored
|
@ -285,17 +285,22 @@ a = 2
|
||||||
]]
|
]]
|
||||||
RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out)
|
RUN([[lua "-e_PROMPT='%s'" -i < %s > %s]], prompt, prog, out)
|
||||||
local t = getoutput()
|
local t = getoutput()
|
||||||
assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt))
|
-- <disabled-by-jart>
|
||||||
|
-- [it doesn't make sense to print prompt if !isatty]
|
||||||
|
-- assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt))
|
||||||
|
-- </disabled-by-jart>
|
||||||
|
|
||||||
-- using the prompt default
|
-- -- using the prompt default
|
||||||
prepfile[[ --
|
prepfile[[ --
|
||||||
a = 2
|
a = 2
|
||||||
]]
|
]]
|
||||||
RUN([[lua -i < %s > %s]], prog, out)
|
RUN([[lua -i < %s > %s]], prog, out)
|
||||||
local t = getoutput()
|
local t = getoutput()
|
||||||
prompt = "> " -- the default
|
prompt = "> " -- the default
|
||||||
assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt))
|
-- <disabled-by-jart>
|
||||||
|
-- [it doesn't make sense to print prompt if !isatty]
|
||||||
|
-- assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt))
|
||||||
|
-- </disabled-by-jart>
|
||||||
|
|
||||||
-- non-string prompt
|
-- non-string prompt
|
||||||
prompt =
|
prompt =
|
||||||
|
@ -305,13 +310,17 @@ prompt =
|
||||||
prepfile[[ --
|
prepfile[[ --
|
||||||
a = 2
|
a = 2
|
||||||
]]
|
]]
|
||||||
RUN([[lua -e "%s" -i < %s > %s]], prompt, prog, out)
|
-- <disabled-by-jart>
|
||||||
local t = getoutput()
|
-- [it doesn't make sense to print prompt if !isatty]
|
||||||
assert(string.find(t, [[
|
-- RUN([[lua -e "%s" -i < %s > %s]], prompt, prog, out)
|
||||||
1 --
|
-- local t = getoutput()
|
||||||
2a = 2
|
-- assert(string.find(t, [[
|
||||||
3
|
-- 1 --
|
||||||
]], 1, true) or string.find(t, "123", 1, true))
|
-- 2a = 2
|
||||||
|
-- 3
|
||||||
|
-- ]], 1, true) or string.find(t, "123", 1, true))
|
||||||
|
-- assert(string.find(t, prompt .. ".*" .. prompt .. ".*" .. prompt))
|
||||||
|
-- </disabled-by-jart>
|
||||||
|
|
||||||
|
|
||||||
-- test for error objects
|
-- test for error objects
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue