File: curses.lua.html

package info (click to toggle)
lua-curses 1%3A9.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,328 kB
  • sloc: sh: 11,898; ansic: 2,704; makefile: 52
file content (115 lines) | stat: -rw-r--r-- 4,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>lcurses 9.0.0 Reference</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>lcurses 9.0.0</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><strong>curses.lua</strong></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><a href="../modules/curses.html">curses</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
  <li><a href="../classes/curses.chstr.html">curses.chstr</a></li>
  <li><a href="../classes/curses.window.html">curses.window</a></li>
</ul>

</div>

<div id="content">

    <h2>curses.lua</h2>
<pre>
<span class="keyword">local</span> curses = <span class="global">require</span> <span class="string">"curses"</span>


<span class="keyword">local</span> <span class="keyword">function</span> printf (fmt, ...)
  <span class="keyword">return</span> <span class="global">print</span> (<span class="global">string</span>.format (fmt, ...))
<span class="keyword">end</span>


<span class="keyword">local</span> <span class="keyword">function</span> main ()
  <span class="keyword">local</span> stdscr = curses.initscr ()

  curses.cbreak ()
  curses.echo (<span class="keyword">false</span>)	<span class="comment">-- not noecho !
</span>  curses.nl (<span class="keyword">false</span>)	<span class="comment">-- not nonl !
</span>
  stdscr:clear ()

  <span class="keyword">local</span> a = {}
  <span class="keyword">for</span> k, v <span class="keyword">in</span> <span class="global">pairs</span> (curses) <span class="keyword">do</span>
    <span class="keyword">if</span> <span class="global">type</span> (v) == <span class="string">"number"</span> <span class="keyword">then</span> a[#a+<span class="number">1</span>] = k <span class="keyword">end</span>
  <span class="keyword">end</span>

  stdscr:mvaddstr (<span class="number">15</span>, <span class="number">20</span>, <span class="string">"print out curses constants (y/n) ? "</span>)
  stdscr:refresh ()

  <span class="keyword">local</span> c = stdscr:getch ()
  <span class="keyword">if</span> c &lt; <span class="number">256</span> <span class="keyword">then</span> c = <span class="global">string</span>.char (c) <span class="keyword">end</span>

  curses.endwin ()

  <span class="keyword">if</span> c == <span class="string">"y"</span> <span class="keyword">then</span>
    <span class="global">table</span>.sort (a, cmp)
    <span class="keyword">for</span> i, k <span class="keyword">in</span> <span class="global">ipairs</span> (a) <span class="keyword">do</span>
      printf (<span class="string">" %03d. %20s = 0x%08x (%d)"</span>,
        i, <span class="string">"curses."</span> .. k, curses[k], curses[k])
    <span class="keyword">end</span>
  <span class="keyword">end</span>
<span class="keyword">end</span>


<span class="comment">-- To display Lua errors, we must close curses to return to
</span><span class="comment">-- normal terminal mode, and then write the error to stdout.
</span><span class="keyword">local</span> <span class="keyword">function</span> err (err)
  curses.endwin ()
  <span class="global">print</span> <span class="string">"Caught an error:"</span>
  <span class="global">print</span> (<span class="global">debug</span>.traceback (err, <span class="number">2</span>))
  <span class="global">os</span>.exit (<span class="number">2</span>)
<span class="keyword">end</span>

<span class="global">xpcall</span> (main, err)</pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-01-10 18:31:15 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>