diff options
Diffstat (limited to 'docs/examples/password_input.lua.html')
-rw-r--r-- | docs/examples/password_input.lua.html | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/docs/examples/password_input.lua.html b/docs/examples/password_input.lua.html new file mode 100644 index 0000000..4234fbb --- /dev/null +++ b/docs/examples/password_input.lua.html | |||
@@ -0,0 +1,139 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | <ul> | ||
31 | <li><a href="../index.html">Index</a></li> | ||
32 | </ul> | ||
33 | |||
34 | |||
35 | |||
36 | <h2>Examples</h2> | ||
37 | <ul class="nowrap"> | ||
38 | <li><a href="../examples/compat.lua.html">compat.lua</a></li> | ||
39 | <li><a href="../examples/flag_debugging.lua.html">flag_debugging.lua</a></li> | ||
40 | <li><strong>password_input.lua</strong></li> | ||
41 | <li><a href="../examples/read.lua.html">read.lua</a></li> | ||
42 | <li><a href="../examples/readline.lua.html">readline.lua</a></li> | ||
43 | <li><a href="../examples/spinner.lua.html">spinner.lua</a></li> | ||
44 | <li><a href="../examples/spiral_snake.lua.html">spiral_snake.lua</a></li> | ||
45 | <li><a href="../examples/terminalsize.lua.html">terminalsize.lua</a></li> | ||
46 | </ul> | ||
47 | <h2>Modules</h2> | ||
48 | <ul class="nowrap"> | ||
49 | <li><a href="../modules/system.html">system</a></li> | ||
50 | </ul> | ||
51 | <h2>Classes</h2> | ||
52 | <ul class="nowrap"> | ||
53 | <li><a href="../classes/bitflags.html">bitflags</a></li> | ||
54 | </ul> | ||
55 | <h2>Topics</h2> | ||
56 | <ul class=""> | ||
57 | <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li> | ||
58 | <li><a href="../topics/02-development.md.html">2. Development</a></li> | ||
59 | <li><a href="../topics/03-terminal.md.html">3. Terminal functionality</a></li> | ||
60 | <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
61 | <li><a href="../topics/LICENSE.md.html">MIT License</a></li> | ||
62 | </ul> | ||
63 | |||
64 | </div> | ||
65 | |||
66 | <div id="content"> | ||
67 | |||
68 | <h2>password_input.lua</h2> | ||
69 | <pre> | ||
70 | <span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">"system"</span> | ||
71 | |||
72 | <span class="global">print</span> <span class="string">[[ | ||
73 | |||
74 | This example shows how to disable the "echo" of characters read to the console, | ||
75 | useful for reading secrets from the user. | ||
76 | |||
77 | ]]</span> | ||
78 | |||
79 | <span class="comment">--- Function to read from stdin without echoing the input (for secrets etc). | ||
80 | </span><span class="comment">-- It will (in a platform agnostic way) disable echo on the terminal, read the | ||
81 | </span><span class="comment">-- input, and then re-enable echo. | ||
82 | </span><span class="comment">-- @param ... Arguments to pass to <code>io.stdin:read()</code> | ||
83 | </span><span class="comment">-- @return the results of <code>io.stdin:read(...)</code> | ||
84 | </span><span class="keyword">local</span> <span class="keyword">function</span> <span class="function-name">read_secret</span>(...) | ||
85 | <span class="keyword">local</span> w_oldflags, p_oldflags | ||
86 | |||
87 | <span class="keyword">if</span> sys.<span class="function-name">isatty</span>(<span class="global">io</span>.stdin) <span class="keyword">then</span> | ||
88 | <span class="comment">-- backup settings, configure echo flags | ||
89 | </span> w_oldflags = sys.<span class="function-name">getconsoleflags</span>(<span class="global">io</span>.stdin) | ||
90 | p_oldflags = sys.<span class="function-name">tcgetattr</span>(<span class="global">io</span>.stdin) | ||
91 | <span class="comment">-- set echo off to not show password on screen | ||
92 | </span> <span class="global">assert</span>(sys.<span class="function-name">setconsoleflags</span>(<span class="global">io</span>.stdin, w_oldflags - sys.CIF_ECHO_INPUT)) | ||
93 | <span class="global">assert</span>(sys.<span class="function-name">tcsetattr</span>(<span class="global">io</span>.stdin, sys.TCSANOW, { lflag = p_oldflags.lflag - sys.L_ECHO })) | ||
94 | <span class="keyword">end</span> | ||
95 | |||
96 | <span class="keyword">local</span> secret, err = <span class="global">io</span>.stdin:<span class="function-name">read</span>(...) | ||
97 | |||
98 | <span class="comment">-- restore settings | ||
99 | </span> <span class="keyword">if</span> sys.<span class="function-name">isatty</span>(<span class="global">io</span>.stdin) <span class="keyword">then</span> | ||
100 | <span class="global">io</span>.stdout:<span class="function-name">write</span>(<span class="string">"\n"</span>) <span class="comment">-- Add newline after reading the password | ||
101 | </span> sys.<span class="function-name">setconsoleflags</span>(<span class="global">io</span>.stdin, w_oldflags) | ||
102 | sys.<span class="function-name">tcsetattr</span>(<span class="global">io</span>.stdin, sys.TCSANOW, p_oldflags) | ||
103 | <span class="keyword">end</span> | ||
104 | |||
105 | <span class="keyword">return</span> secret, err | ||
106 | <span class="keyword">end</span> | ||
107 | |||
108 | |||
109 | |||
110 | <span class="comment">-- Get username | ||
111 | </span><span class="global">io</span>.<span class="function-name">write</span>(<span class="string">"Username: "</span>) | ||
112 | <span class="keyword">local</span> username = <span class="global">io</span>.stdin:<span class="function-name">read</span>(<span class="string">"*l"</span>) | ||
113 | |||
114 | <span class="comment">-- Get the secret | ||
115 | </span><span class="global">io</span>.<span class="function-name">write</span>(<span class="string">"Password: "</span>) | ||
116 | <span class="keyword">local</span> password = <span class="function-name">read_secret</span>(<span class="string">"*l"</span>) | ||
117 | |||
118 | <span class="comment">-- Get domainname | ||
119 | </span><span class="global">io</span>.<span class="function-name">write</span>(<span class="string">"Domain : "</span>) | ||
120 | <span class="keyword">local</span> domain = <span class="global">io</span>.stdin:<span class="function-name">read</span>(<span class="string">"*l"</span>) | ||
121 | |||
122 | |||
123 | <span class="comment">-- Print the results | ||
124 | </span><span class="global">print</span>(<span class="string">""</span>) | ||
125 | <span class="global">print</span>(<span class="string">"Here's what we got:"</span>) | ||
126 | <span class="global">print</span>(<span class="string">" username: "</span> .. username) | ||
127 | <span class="global">print</span>(<span class="string">" password: "</span> .. password) | ||
128 | <span class="global">print</span>(<span class="string">" domain : "</span> .. domain)</pre> | ||
129 | |||
130 | |||
131 | </div> <!-- id="content" --> | ||
132 | </div> <!-- id="main" --> | ||
133 | <div id="about"> | ||
134 | <i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> | ||
135 | <i style="float:right;">Last updated 2024-06-20 23:11:37 </i> | ||
136 | </div> <!-- id="about" --> | ||
137 | </div> <!-- id="container" --> | ||
138 | </body> | ||
139 | </html> | ||