util/human/io.lua
changeset 12787 d513e4bd4928
parent 12577 0f4feaf9ca64
child 12979 d10957394a3c
equal deleted inserted replaced
12786:8815d3090928 12787: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");