Comparison

util/human/io.lua @ 12783:d513e4bd4928

util.human.io: Fix handling of os.execute() return values in Lua 5.2+ Wrong part of Lua 5.1 compat removed in 0f4feaf9ca64
author Kim Alvefur <zash@zash.se>
date Thu, 20 Oct 2022 17:35:01 +0200
parent 12573:0f4feaf9ca64
child 12975:d10957394a3c
comparison
equal deleted inserted replaced
12782:8815d3090928 12783:d513e4bd4928
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
29 end 29 end
30 end 30 end
31 31
32 local function getpass() 32 local function getpass()
33 local stty_ret = os.execute("stty -echo 2>/dev/null"); 33 local stty_ret = os.execute("stty -echo 2>/dev/null");
34 if stty_ret ~= 0 then 34 if not stty_ret then
35 io.write("\027[08m"); -- ANSI 'hidden' text attribute 35 io.write("\027[08m"); -- ANSI 'hidden' text attribute
36 end 36 end
37 local ok, pass = pcall(io.read, "*l"); 37 local ok, pass = pcall(io.read, "*l");
38 if stty_ret == 0 then 38 if stty_ret then
39 os.execute("stty sane"); 39 os.execute("stty sane");
40 else 40 else
41 io.write("\027[00m"); 41 io.write("\027[00m");
42 end 42 end
43 io.write("\n"); 43 io.write("\n");