Comparison

util/human/io.lua @ 12802:4a8740e01813

Merge 0.12->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 12 Dec 2022 07:10:54 +0100
parent 12783:d513e4bd4928
child 12975:d10957394a3c
comparison
equal deleted inserted replaced
12801:ebd6b4d8bf04 12802:4a8740e01813
6 end; 6 end;
7 7
8 local function getchar(n) 8 local function getchar(n)
9 local stty_ret = os.execute("stty raw -echo 2>/dev/null"); 9 local stty_ret = os.execute("stty raw -echo 2>/dev/null");
10 local ok, char; 10 local ok, char;
11 if stty_ret == true or stty_ret == 0 then 11 if stty_ret then
12 ok, char = pcall(io.read, n or 1); 12 ok, char = pcall(io.read, n or 1);
13 os.execute("stty sane"); 13 os.execute("stty sane");
14 else 14 else
15 ok, char = pcall(io.read, "*l"); 15 ok, char = pcall(io.read, "*l");
16 if ok then 16 if ok then
28 return line; 28 return line;
29 end 29 end
30 end 30 end
31 31
32 local function getpass() 32 local function getpass()
33 local stty_ret, _, status_code = os.execute("stty -echo 2>/dev/null"); 33 local stty_ret = os.execute("stty -echo 2>/dev/null");
34 if status_code then -- COMPAT w/ Lua 5.1 34 if not stty_ret then
35 stty_ret = status_code;
36 end
37 if stty_ret ~= 0 then
38 io.write("\027[08m"); -- ANSI 'hidden' text attribute 35 io.write("\027[08m"); -- ANSI 'hidden' text attribute
39 end 36 end
40 local ok, pass = pcall(io.read, "*l"); 37 local ok, pass = pcall(io.read, "*l");
41 if stty_ret == 0 then 38 if stty_ret then
42 os.execute("stty sane"); 39 os.execute("stty sane");
43 else 40 else
44 io.write("\027[00m"); 41 io.write("\027[00m");
45 end 42 end
46 io.write("\n"); 43 io.write("\n");