Software / code / prosody
Comparison
prosodyctl @ 2410:ce912b648741
prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 03 Jan 2010 03:36:40 +0000 |
| parent | 2329:e497718194a3 |
| child | 2439:511ba389147a |
comparison
equal
deleted
inserted
replaced
| 2409:36b8de1bfa27 | 2410:ce912b648741 |
|---|---|
| 135 print(" "..desc); | 135 print(" "..desc); |
| 136 end | 136 end |
| 137 end | 137 end |
| 138 | 138 |
| 139 local function getchar(n) | 139 local function getchar(n) |
| 140 os.execute("stty raw -echo"); | 140 local stty_ret = os.execute("stty raw -echo 2>/dev/null"); |
| 141 local ok, char = pcall(io.read, n or 1); | 141 local ok, char; |
| 142 os.execute("stty sane"); | 142 if stty_ret == 0 then |
| 143 ok, char = pcall(io.read, n or 1); | |
| 144 os.execute("stty sane"); | |
| 145 else | |
| 146 ok, char = pcall(io.read, "*l"); | |
| 147 if ok then | |
| 148 char = char:sub(1, n or 1); | |
| 149 end | |
| 150 end | |
| 143 if ok then | 151 if ok then |
| 144 return char; | 152 return char; |
| 145 end | 153 end |
| 146 end | 154 end |
| 147 | 155 |
| 148 local function getpass() | 156 local function getpass() |
| 149 os.execute("stty -echo"); | 157 local stty_ret = os.execute("stty -echo 2>/dev/null"); |
| 158 if stty_ret ~= 0 then | |
| 159 io.write("\027[08m"); -- ANSI 'hidden' text attribute | |
| 160 end | |
| 150 local ok, pass = pcall(io.read, "*l"); | 161 local ok, pass = pcall(io.read, "*l"); |
| 151 os.execute("stty sane"); | 162 if stty_ret == 0 then |
| 163 os.execute("stty sane"); | |
| 164 else | |
| 165 io.write("\027[00m"); | |
| 166 end | |
| 152 io.write("\n"); | 167 io.write("\n"); |
| 153 if ok then | 168 if ok then |
| 154 return pass; | 169 return pass; |
| 155 end | 170 end |
| 156 end | 171 end |