-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
503 lines (500 loc) · 18.5 KB
/
index.html
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ncurses Cheatsheet</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body id="preview">
<a href="https://github.com/hereisnaman/ncurses-cheatsheet">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
</br>
</br>
<h1><a id="A_Handy_Ncurses_Cheatsheet_0"></a>A Handy Ncurses Cheatsheet</h1>
<p>A handy cheatsheet for programmers working with <a href="https://www.gnu.org/software/ncurses/">ncurses library by GNU</a>. Complete inshort documentation and usage details. This is a reference doc which will help you in the process of building up
great interactive command line projects using the ncurses library by GNU.</p>
<h2><a id="How_to_install_ncurses_4"></a>How to install ncurses</h2>
<p>Well installing ncurses library is an easy task, you just have to follow the steps listed below:</p>
<h3><a id="Installing_ncurses_on_DebianUbuntu_Linux_7"></a>Installing ncurses on Debian/Ubuntu Linux</h3>
<ol>
<li><code>sudo apt-get install libncurses5-dev libncursesw5-dev</code>
</li>
</ol>
<h3><a id="Installing_ncurses_on_Mac_OS_X_10"></a>Installing ncurses on Mac OS X</h3>
<ol>
<li>Install <a href="http://brew.sh/">Homebrew</a> (if not already):
<br>
<code>/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code>
</li>
<li>Install ncurses package: <code>$brew install homebrew/dupes/ncurses</code>
</li>
</ol>
<h2><a id="How_to_link_ncurses_with_project_16"></a>How to link ncurses with project</h2>
<p>Command structure: <code>g++ ${file} -o ${file_path}/${file_base_name} -lncurses</code>
</p>
<p>Example: <code>gcc main.cpp -o main -lncurses</code>
</p>
<h2><a id="Initialization_Functions_23"></a>Initialization Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td>initscr()</td>
<td>Initializes the terminal in cursor mode. It must be called first to do any manupulation with ncurses package.</td>
</tr>
<tr>
<td>refresh()</td>
<td>Tell the curses system to dump the contents on the screen. It checks the window and updates only the portion which has been changed.</td>
</tr>
<tr>
<td>wrefresh()</td>
<td>Tell the curses system to dump the contents on the given window. It checks the given window and updates only the portion which has been changed.</td>
</tr>
<tr>
<td>endwin()</td>
<td>Ends the terminal cursor mode.</td>
</tr>
<tr>
<td>raw()</td>
<td>Disable inline buffering. Control characters are directly passed to the program without generating a signal.</td>
</tr>
<tr>
<td>cbreak()</td>
<td>Disable inline buffering. Control characters are interpreted as any other character by the terminal driver.</td>
</tr>
<tr>
<td>echo()</td>
<td>Switch on echo.</td>
</tr>
<tr>
<td>noecho()</td>
<td>Switch off echo.</td>
</tr>
<tr>
<td>keypad(stdscr,TRUE)</td>
<td>Enable reading of fucntion keys.</td>
</tr>
<tr>
<td>halfdelay()</td>
<td>Enable the half−delay mode, it waits for ‘X’ tenths of a second for input and then returns ERR, if no input is available</td>
</tr>
</tbody>
</table>
<h2><a id="Miscellaneous_Functions_38"></a>Miscellaneous Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td>clear()</td>
<td>Clear the stdscr window.</td>
</tr>
<tr>
<td>wclear()</td>
<td>Clear the given window.</td>
</tr>
<tr>
<td>move(y,x)</td>
<td>Move the cursor to the x,y position on the window.</td>
</tr>
<tr>
<td>wmove(win,y,x)</td>
<td>Move the cursor to the x,y position on the given window.</td>
</tr>
<tr>
<td>getmaxyx(stdscr,y,x)</td>
<td>Get the boundaries of the screeen i.e. number of rows and columns</td>
</tr>
<tr>
<td>getyx(stdscr,y,x)</td>
<td>Get the current cusor position</td>
</tr>
</tbody>
</table>
<h2><a id="Output_Functions_49"></a>Output Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>addch()</strong>
</td>
<td><strong>Print a character with given attributes at the current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvaddch()</td>
<td>Move the cursor to a given position and then print as by addch().</td>
</tr>
<tr>
<td>waddch()</td>
<td>Print a character as by addch() but into the given window.</td>
</tr>
<tr>
<td>mvwaddch()</td>
<td>Move the cursor to a given position and then print as by addch() but into the given window.</td>
</tr>
<tr>
<td><strong>printw()</strong>
</td>
<td><strong>Print similar to printf() but at any position on the window i.e. current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvprintw()</td>
<td>Move the cursor to a given position and then print as by printw().</td>
</tr>
<tr>
<td>wprintw()</td>
<td>Print as by printw() but into the given window.</td>
</tr>
<tr>
<td>mvwprintw()</td>
<td>Move the cursor to a given position and then print as by printw() but into the given window.</td>
</tr>
<tr>
<td><strong>addstr()</strong>
</td>
<td><strong>Print a character string with given attributes at the current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvaddstr()</td>
<td>Move the cursor to a given position and then print as by addstr().</td>
</tr>
<tr>
<td>waddstr()</td>
<td>Print a character string as by addstr() but into the given window.</td>
</tr>
<tr>
<td>mvwaddstr()</td>
<td>Move the cursor to a given position and then print as by addstr() but into the given window.</td>
</tr>
</tbody>
</table>
<h2><a id="Input_Functions_66"></a>Input Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>getch()</strong>
</td>
<td><strong>Input a character with given attributes from the current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvgetch()</td>
<td>Move the cursor to a given position and then input as by getch().</td>
</tr>
<tr>
<td>whetch()</td>
<td>Input a character as by getch() but from the given window.</td>
</tr>
<tr>
<td>mvwgetch()</td>
<td>Move the cursor to a given position and then input as by getch() but into the given window.</td>
</tr>
<tr>
<td><strong>scanw()</strong>
</td>
<td><strong>Takes input similar to scanf() but from any position on the window i.e. current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvscanw()</td>
<td>Move the cursor to a given position and then input as by scanw().</td>
</tr>
<tr>
<td>wscanw()</td>
<td>Takes input as by scanw() but from the given window.</td>
</tr>
<tr>
<td>mvwscanw()</td>
<td>Move the cursor to a given position and then input as by scanw() but from the given window.</td>
</tr>
<tr>
<td><strong>getstr()</strong>
</td>
<td><strong>Input a character string with given attributes from the current cursor position and advance the position of the cursor.</strong>
</td>
</tr>
<tr>
<td>mvgetstr()</td>
<td>Move the cursor to a given position and then input as by getstr().</td>
</tr>
<tr>
<td>wgetstr()</td>
<td>Input a character string as by getstr() but from the given window.</td>
</tr>
<tr>
<td>mvwgetstr()</td>
<td>Move the cursor to a given position and then input as by getstr() but from the given window.</td>
</tr>
</tbody>
</table>
<h2><a id="Attribute_Functions_83"></a>Attribute Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>attron()</strong>
</td>
<td><strong>Switches on attribute(s) given to it.</strong>
</td>
</tr>
<tr>
<td>wattron()</td>
<td>Switches on attribute(s) given to it, in the given window.</td>
</tr>
<tr>
<td><strong>attrset()</strong>
</td>
<td><strong>Fully overrides whatever attributes the window previously had and sets it to the new attribute(s).</strong>
</td>
</tr>
<tr>
<td>wattrset()</td>
<td>Fully overrides whatever attributes the given window previously had and sets it to the new attribute(s).</td>
</tr>
<tr>
<td><strong>attroff()</strong>
</td>
<td><strong>Switches off the attribute(s) given to it.</strong>
</td>
</tr>
<tr>
<td>wattroff()</td>
<td>Switches off the attribute(s) given to it, in the given window.</td>
</tr>
<tr>
<td><strong>standend()</strong>
</td>
<td><strong>Turns off all attributes and brings you to normal mode.</strong>
</td>
</tr>
<tr>
<td><strong>attr_get()</strong>
</td>
<td><strong>Gets the current attributes and color pair of the window.</strong>
</td>
</tr>
<tr>
<td>wattr_get()</td>
<td>Gets the current attributes and color pair of the given window.</td>
</tr>
<tr>
<td><strong>chgat()</strong>
</td>
<td><strong>Change attribute(s) for characters that are already on the screen.</strong>
</td>
</tr>
<tr>
<td>mvchgat()</td>
<td>Move the cursor to the given position and then perform the work as by chgat().</td>
</tr>
<tr>
<td>wchgat()</td>
<td>Perform the work done as by chgat() on the given window.</td>
</tr>
<tr>
<td>mvwchgat()</td>
<td>Move the cursor to the given position and then perform the work as by chgat() on the given window.</td>
</tr>
</tbody>
</table>
<h2><a id="Attributes_List_101"></a>Attributes List</h2>
<p>We can <strong>OR(|)</strong> any number of above attributes to get a combined effect.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td>A_NORMAL</td>
<td>Normal display (no highlight).</td>
</tr>
<tr>
<td>A_STANDOUT</td>
<td>Best highlighting mode of the terminal.</td>
</tr>
<tr>
<td>A_UNDERLINE</td>
<td>Underlining.</td>
</tr>
<tr>
<td>A_REVERSE</td>
<td>Reverse video.</td>
</tr>
<tr>
<td>A_BLINK</td>
<td>Blinking.</td>
</tr>
<tr>
<td>A_DIM</td>
<td>Half bright.</td>
</tr>
<tr>
<td>A_BOLD</td>
<td>Extra bright or bold.</td>
</tr>
<tr>
<td>A_PROTECT</td>
<td>Protected mode.</td>
</tr>
<tr>
<td>A_INVIS</td>
<td>Invisible or blank mode.</td>
</tr>
<tr>
<td>A_ALTCHARSET</td>
<td>Alternate character set.</td>
</tr>
<tr>
<td>A_CHARTEXT</td>
<td>Bit−mask to extract a character.</td>
</tr>
<tr>
<td>COLOR_PAIR(n)</td>
<td>Color−pair number n.</td>
</tr>
</tbody>
</table>
<h2><a id="Color_Functions_120"></a>Color Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td>start_color()</td>
<td>Needed to be called before using colors.</td>
</tr>
<tr>
<td>has_colors()</td>
<td>Check whether terminal has color capabilities.</td>
</tr>
<tr>
<td>init_pair()</td>
<td>Initiate a color pair number n with foreground and background color, which can be used in COLOR_PAIR(n).</td>
</tr>
<tr>
<td>init_color()</td>
<td>Change the rgb values for the colors defined by curses initially.</td>
</tr>
<tr>
<td>can_change_color()</td>
<td>Check whether the terminal has the capability of changing color.</td>
</tr>
</tbody>
</table>
<h2><a id="Colors_130"></a>Colors</h2>
<p>The following colors are defined in curses.h. You can use these as parameters for various color functions.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Colors</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr>
<td>COLOR_BLACK</td>
<td>0</td>
</tr>
<tr>
<td>COLOR_RED</td>
<td>1</td>
</tr>
<tr>
<td>COLOR_GREEN</td>
<td>2</td>
</tr>
<tr>
<td>COLOR_YELLOW</td>
<td>3</td>
</tr>
<tr>
<td>COLOR_BLUE</td>
<td>4</td>
</tr>
<tr>
<td>COLOR_MAGENTA</td>
<td>5</td>
</tr>
<tr>
<td>COLOR_CYAN</td>
<td>6</td>
</tr>
<tr>
<td>COLOR_WHITE</td>
<td>7</td>
</tr>
</tbody>
</table>
<h2><a id="Windows_Functions_145"></a>Windows Functions</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Functions</th>
<th>Discription</th>
</tr>
</thead>
<tbody>
<tr>
<td>box()</td>
<td>Draw border around windows.</td>
</tr>
<tr>
<td>newwin()</td>
<td>Creates a new Window.</td>
</tr>
<tr>
<td>create_newwin()</td>
<td>Creates a new window with newwin() and displays a border around it with box().</td>
</tr>
<tr>
<td>delwin()</td>
<td>Deallocate memory related to the window.</td>
</tr>
<tr>
<td>destroy_win()</td>
<td>Erases the window from the screena dn then delete it by calling delwin()</td>
</tr>
<tr>
<td>wborder()</td>
<td>Draws a border around the window by the characters given to it.</td>
</tr>
</tbody>
</table>
</body>
</html>