summaryrefslogtreecommitdiff
path: root/docs/modules/system.html
blob: 0423e3763147825dd1fb0c8e71984a2f5e6983bd (plain)
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
<!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>Lua-System docs</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>Lua-System</h1>


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

<h2>Contents</h2>
<ul>
<li><a href="#Fields">Fields</a></li>
<li><a href="#Environment">Environment </a></li>
<li><a href="#Random">Random </a></li>
<li><a href="#Terminal">Terminal </a></li>
<li><a href="#Time">Time </a></li>
</ul>


<h2>Modules</h2>
<ul class="nowrap">
  <li><strong>system</strong></li>
</ul>
<h2>Classes</h2>
<ul class="nowrap">
  <li><a href="../classes/bitflags.html">bitflags</a></li>
</ul>
<h2>Topics</h2>
<ul class="">
  <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li>
  <li><a href="../topics/02-development.md.html">2. Development</a></li>
  <li><a href="../topics/03-terminal.md.html">3. Terminal functionality</a></li>
  <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li>
  <li><a href="../topics/LICENSE.md.html">MIT License</a></li>
</ul>
<h2>Examples</h2>
<ul class="nowrap">
  <li><a href="../examples/compat.lua.html">compat.lua</a></li>
  <li><a href="../examples/flag_debugging.lua.html">flag_debugging.lua</a></li>
  <li><a href="../examples/password_input.lua.html">password_input.lua</a></li>
  <li><a href="../examples/read.lua.html">read.lua</a></li>
  <li><a href="../examples/readline.lua.html">readline.lua</a></li>
  <li><a href="../examples/spinner.lua.html">spinner.lua</a></li>
  <li><a href="../examples/spiral_snake.lua.html">spiral_snake.lua</a></li>
  <li><a href="../examples/terminalsize.lua.html">terminalsize.lua</a></li>
</ul>

</div>

<div id="content">

<h1>Module <code>system</code></h1>
<p>Platform independent system calls for Lua.</p>
<p>

</p>


<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#windows">windows</a></td>
	<td class="summary">Flag to identify Windows.</td>
	</tr>
</table>
<h2><a href="#Environment">Environment </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#getenv">getenv (name)</a></td>
	<td class="summary">Gets the value of an environment variable.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getenvs">getenvs ()</a></td>
	<td class="summary">Returns a table with all environment variables.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setenv">setenv (name[, value])</a></td>
	<td class="summary">Sets an environment variable.</td>
	</tr>
</table>
<h2><a href="#Random">Random </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#random">random ([length=1])</a></td>
	<td class="summary">Generate random bytes.</td>
	</tr>
</table>
<h2><a href="#Terminal">Terminal </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#CODEPAGE_UTF8">CODEPAGE_UTF8</a></td>
	<td class="summary">UTF8 codepage.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#_readkey">_readkey ()</a></td>
	<td class="summary">Reads a key from the console non-blocking.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#autotermrestore">autotermrestore ()</a></td>
	<td class="summary">Backs up terminal settings and restores them on application exit.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getconsolecp">getconsolecp ()</a></td>
	<td class="summary">Gets the current console code page (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getconsoleflags">getconsoleflags (file)</a></td>
	<td class="summary">Gets console flags (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getconsoleoutputcp">getconsoleoutputcp ()</a></td>
	<td class="summary">Gets the current console output code page (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getnonblock">getnonblock (fd)</a></td>
	<td class="summary">Gets non-blocking mode status for a file (Posix).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#isatty">isatty (file)</a></td>
	<td class="summary">Checks if a file-handle is a TTY.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#listconsoleflags">listconsoleflags (fh)</a></td>
	<td class="summary">Debug function for console flags (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#listtermflags">listtermflags (fh)</a></td>
	<td class="summary">Debug function for terminal flags (Posix).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#readansi">readansi (timeout)</a></td>
	<td class="summary">Reads a single key, if it is the start of ansi escape sequence then it reads
 the full sequence.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#readkey">readkey (timeout)</a></td>
	<td class="summary">Reads a single byte from the console, with a timeout.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setconsolecp">setconsolecp (cp)</a></td>
	<td class="summary">Sets the current console code page (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setconsoleflags">setconsoleflags (file, bitflags)</a></td>
	<td class="summary">Sets the console flags (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setconsoleoutputcp">setconsoleoutputcp (cp)</a></td>
	<td class="summary">Sets the current console output code page (Windows).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setnonblock">setnonblock (fd, make_non_block)</a></td>
	<td class="summary">Enables or disables non-blocking mode for a file (Posix).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#tcgetattr">tcgetattr (fd)</a></td>
	<td class="summary">Get termios state (Posix).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#tcsetattr">tcsetattr (fd, actions, termios)</a></td>
	<td class="summary">Set termios state (Posix).</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#termbackup">termbackup ()</a></td>
	<td class="summary">Returns a backup of terminal settings for stdin/out/err.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#termrestore">termrestore (backup)</a></td>
	<td class="summary">Restores terminal settings from a backup</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#termsize">termsize ()</a></td>
	<td class="summary">Get the size of the terminal in rows and columns.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#termwrap">termwrap (f)</a></td>
	<td class="summary">Wraps a function to automatically restore terminal settings upon returning.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#utf8cwidth">utf8cwidth (utf8_char)</a></td>
	<td class="summary">Get the width of a utf8 character for terminal display.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#utf8swidth">utf8swidth (utf8_string)</a></td>
	<td class="summary">Get the width of a utf8 string for terminal display.</td>
	</tr>
</table>
<h2><a href="#Time">Time </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#gettime">gettime ()</a></td>
	<td class="summary">Get system time.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#monotime">monotime ()</a></td>
	<td class="summary">Get monotonic time.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#sleep">sleep (seconds[, precision=16])</a></td>
	<td class="summary">Sleep without a busy loop.</td>
	</tr>
</table>

<br/>
<br/>


    <h2 class="section-header "><a name="Fields"></a>Fields</h2>

    <dl class="function">
    <dt>
    <a name = "windows"></a>
    <strong>windows</strong>
    </dt>
    <dd>
    Flag to identify Windows.


    <ul>
        <li><span class="parameter">windows</span>
         <code>true</code> if on Windows, <code>false</code> otherwise.
        </li>
    </ul>





</dd>
</dl>
    <h2 class="section-header "><a name="Environment"></a>Environment </h2>

    <dl class="function">
    <dt>
    <a name = "getenv"></a>
    <strong>getenv (name)</strong>
    </dt>
    <dd>
    Gets the value of an environment variable. </p>

<p><strong>NOTE</strong>: Windows has multiple copies of environment variables. For this reason,
the <a href="../modules/system.html#setenv">setenv</a> function will not work with Lua's <a href="https://www.lua.org/manual/5.4/manual.html#pdf-os.getenv">os.getenv</a> on Windows. If you want
to use <a href="../modules/system.html#setenv">setenv</a> then consider patching <a href="https://www.lua.org/manual/5.4/manual.html#pdf-os.getenv">os.getenv</a> with this implementation of <a href="../modules/system.html#getenv">getenv</a>.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">name</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
         name of the environment variable
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a> or <span class="type">nil</span></span>
        value of the environment variable, or nil if the variable is not set
    </ol>




</dd>
    <dt>
    <a name = "getenvs"></a>
    <strong>getenvs ()</strong>
    </dt>
    <dd>
    Returns a table with all environment variables.



    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.6">table</a></span>
        table with all environment variables and their values
    </ol>




</dd>
    <dt>
    <a name = "setenv"></a>
    <strong>setenv (name[, value])</strong>
    </dt>
    <dd>
    Sets an environment variable. </p>

<p><strong>NOTE</strong>: Windows has multiple copies of environment variables. For this reason, the
<a href="../modules/system.html#setenv">setenv</a> function will not work with Lua's <a href="https://www.lua.org/manual/5.4/manual.html#pdf-os.getenv">os.getenv</a> on Windows. If you want to use
it then consider patching <a href="https://www.lua.org/manual/5.4/manual.html#pdf-os.getenv">os.getenv</a> with the implementation of <a href="../modules/system.html#getenv">system.getenv</a>.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">name</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
         name of the environment variable
        </li>
        <li><span class="parameter">value</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
         value of the environment variable, if <code>nil</code> the variable will be deleted (on
Windows, setting an empty string, will also delete the variable)
         (<em>optional</em>)
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">boolean</span></span>
        success
    </ol>




</dd>
</dl>
    <h2 class="section-header "><a name="Random"></a>Random </h2>

    <dl class="function">
    <dt>
    <a name = "random"></a>
    <strong>random ([length=1])</strong>
    </dt>
    <dd>
    Generate random bytes.
This uses <code>CryptGenRandom()</code> on Windows, and <code>/dev/urandom</code> on other platforms. It will return the
requested number of bytes, or an error, never a partial result.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">length</span>
            <span class="types"><span class="type">int</span></span>
         number of bytes to get
         (<em>default</em> 1)
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        string of random bytes
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>




</dd>
</dl>
    <h2 class="section-header has-description"><a name="Terminal"></a>Terminal </h2>

          <div class="section-description">
           Unix: see https://blog.nelhage.com/2009/12/a-brief-introduction-to-termios-termios3-and-stty/</p>

<p> Windows: see https://learn.microsoft.com/en-us/windows/console/console-reference
          </div>
    <dl class="function">
    <dt>
    <a name = "CODEPAGE_UTF8"></a>
    <strong>CODEPAGE_UTF8</strong>
    </dt>
    <dd>
    UTF8 codepage.
 To be used with <a href="../modules/system.html#setconsoleoutputcp">system.setconsoleoutputcp</a> and <a href="../modules/system.html#setconsolecp">system.setconsolecp</a>.


    <ul>
        <li><span class="parameter">CODEPAGE_UTF8</span>
         The Windows CodePage for UTF8.
        </li>
    </ul>





</dd>
    <dt>
    <a name = "_readkey"></a>
    <strong>_readkey ()</strong>
    </dt>
    <dd>
    Reads a key from the console non-blocking.  This function should not be called
directly, but through the <a href="../modules/system.html#readkey">system.readkey</a> or <a href="../modules/system.html#readansi">system.readansi</a> functions. It
will return the next byte from the input stream, or <code>nil</code> if no key was pressed.</p>

<p>On Posix, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a> must be set to non-blocking mode using <a href="../modules/system.html#setnonblock">setnonblock</a>
and canonical mode must be turned off using <a href="../modules/system.html#tcsetattr">tcsetattr</a>,
before calling this function. Otherwise it will block. No conversions are
done on Posix, so the byte read is returned as-is.</p>

<p>On Windows this reads a wide character and converts it to UTF-8. Multi-byte
sequences will be buffered internally and returned one byte at a time.



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">integer</span></span>
        the byte read from the input stream
    </ol>
     <h3>Or</h3>
    <ol>

           <span class="types"><span class="type">nil</span></span>
        if no key was pressed
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>
        on error</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        errnum (on posix)</li>
    </ol>




</dd>
    <dt>
    <a name = "autotermrestore"></a>
    <strong>autotermrestore ()</strong>
    </dt>
    <dd>
    Backs up terminal settings and restores them on application exit.
 Calls <a href="../modules/system.html#termbackup">termbackup</a> to back up terminal settings and sets up a GC method to
 automatically restore them on application exit (also works on Lua 5.1).



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">boolean</span></span>
        true
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>
        if the backup was already created</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>




</dd>
    <dt>
    <a name = "getconsolecp"></a>
    <strong>getconsolecp ()</strong>
    </dt>
    <dd>
    Gets the current console code page (Windows).



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">int</span></span>
        the current code page (always 65001 on Posix systems)
    </ol>




</dd>
    <dt>
    <a name = "getconsoleflags"></a>
    <strong>getconsoleflags (file)</strong>
    </dt>
    <dd>
    Gets console flags (Windows).
The <code>CIF_</code> and <code>COF_</code> constants are available on the module table. Where <code>CIF</code> are the
input flags (for use with <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>) and <code>COF</code> are the output flags (for use with
<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>/<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>).</p>

<p><em>Note</em>: See <a href="https://learn.microsoft.com/en-us/windows/console/setconsolemode">setconsolemode documentation</a>
for more information on the flags.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">file</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="../classes/bitflags.html#">bitflags</a></span>
        the current console flags.
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>



    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> system = <span class="global">require</span>(<span class="string">'system'</span>)

<span class="keyword">local</span> flags = system.<span class="function-name">getconsoleflags</span>(<span class="global">io</span>.stdout)
<span class="global">print</span>(<span class="string">"Current stdout flags:"</span>, <span class="global">tostring</span>(flags))

<span class="keyword">if</span> flags:<span class="function-name">has_all_of</span>(system.COF_VIRTUAL_TERMINAL_PROCESSING + system.COF_PROCESSED_OUTPUT) <span class="keyword">then</span>
    <span class="global">print</span>(<span class="string">"Both flags are set"</span>)
<span class="keyword">else</span>
    <span class="global">print</span>(<span class="string">"At least one flag is not set"</span>)
<span class="keyword">end</span></pre>
    </ul>

</dd>
    <dt>
    <a name = "getconsoleoutputcp"></a>
    <strong>getconsoleoutputcp ()</strong>
    </dt>
    <dd>
    Gets the current console output code page (Windows).



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">int</span></span>
        the current code page (always 65001 on Posix systems)
    </ol>




</dd>
    <dt>
    <a name = "getnonblock"></a>
    <strong>getnonblock (fd)</strong>
    </dt>
    <dd>
    Gets non-blocking mode status for a file (Posix).


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fd</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        <code>true</code> if set to non-blocking, <code>false</code> if not. Always returns <code>false</code> on Windows.
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        errnum</li>
    </ol>




</dd>
    <dt>
    <a name = "isatty"></a>
    <strong>isatty (file)</strong>
    </dt>
    <dd>
    Checks if a file-handle is a TTY.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">file</span>
            <span class="types"><span class="type">file</span></span>
         the file-handle to check, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">boolean</span></span>
        true if the file is a tty
    </ol>



    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> system = <span class="global">require</span>(<span class="string">'system'</span>)
<span class="keyword">if</span> system.<span class="function-name">isatty</span>(<span class="global">io</span>.stdin) <span class="keyword">then</span>
    <span class="comment">-- enable ANSI coloring etc on Windows, does nothing in Posix.
</span>    <span class="keyword">local</span> flags = system.<span class="function-name">getconsoleflags</span>(<span class="global">io</span>.stdout)
    system.<span class="function-name">setconsoleflags</span>(<span class="global">io</span>.stdout, flags + sys.COF_VIRTUAL_TERMINAL_PROCESSING)
<span class="keyword">end</span></pre>
    </ul>

</dd>
    <dt>
    <a name = "listconsoleflags"></a>
    <strong>listconsoleflags (fh)</strong>
    </dt>
    <dd>
    Debug function for console flags (Windows).
 Pretty prints the current flags set for the handle.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fh</span>
         file handle (<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>)
        </li>
    </ul>




    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="comment">-- Print the flags for stdin/out/err
</span>system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdin)
system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdout)
system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stderr)</pre>
    </ul>

</dd>
    <dt>
    <a name = "listtermflags"></a>
    <strong>listtermflags (fh)</strong>
    </dt>
    <dd>
    Debug function for terminal flags (Posix).
 Pretty prints the current flags set for the handle.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fh</span>
         file handle (<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>)
        </li>
    </ul>




    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="comment">-- Print the flags for stdin/out/err
</span>system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdin)
system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdout)
system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stderr)</pre>
    </ul>

</dd>
    <dt>
    <a name = "readansi"></a>
    <strong>readansi (timeout)</strong>
    </dt>
    <dd>
    Reads a single key, if it is the start of ansi escape sequence then it reads
 the full sequence.  The key can be a multi-byte string in case of multibyte UTF-8 character.
 This function uses <a href="../modules/system.html#readkey">system.readkey</a>, and hence <a href="../modules/system.html#sleep">system.sleep</a> to wait until either a key is
 available or the timeout is reached.
 It returns immediately if a key is available or if <code>timeout</code> is less than or equal to <code>0</code>.
 In case of an ANSI sequence, it will return the full sequence as a string.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">timeout</span>
            <span class="types"><span class="type">number</span></span>
         the timeout in seconds.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        the character that was received (can be multi-byte), or a complete ANSI sequence</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        the type of input: <code>&quot;char&quot;</code> for a single key, <code>&quot;ansi&quot;</code> for an ANSI sequence</li>
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>
        in case of an error</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message; <code>&quot;timeout&quot;</code> if the timeout was reached.</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        partial result in case of an error while reading a sequence, the sequence so far.</li>
    </ol>




</dd>
    <dt>
    <a name = "readkey"></a>
    <strong>readkey (timeout)</strong>
    </dt>
    <dd>
    Reads a single byte from the console, with a timeout.
 This function uses <a href="../modules/system.html#sleep">system.sleep</a> to wait until either a byte is available or the timeout is reached.
 The sleep period is exponentially backing off, starting at 0.0125 seconds, with a maximum of 0.2 seconds.
 It returns immediately if a byte is available or if <code>timeout</code> is less than or equal to <code>0</code>.</p>

<p> Using <a href="../modules/system.html#readansi">system.readansi</a> is preferred over this function. Since this function can leave stray/invalid
 byte-sequences in the input buffer, while <a href="../modules/system.html#readansi">system.readansi</a> reads full ANSI and UTF8 sequences.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">timeout</span>
            <span class="types"><span class="type">number</span></span>
         the timeout in seconds.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">byte</span></span>
        the byte value that was read.
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>
        if no key was read</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message; <code>&quot;timeout&quot;</code> if the timeout was reached.</li>
    </ol>




</dd>
    <dt>
    <a name = "setconsolecp"></a>
    <strong>setconsolecp (cp)</strong>
    </dt>
    <dd>
    Sets the current console code page (Windows).


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">cp</span>
            <span class="types"><span class="type">int</span></span>
         the code page to set, use <a href="../modules/system.html#CODEPAGE_UTF8">system.CODEPAGE_UTF8</a> (65001) for UTF-8
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        <code>true</code> on success (always <code>true</code> on Posix systems)
    </ol>




</dd>
    <dt>
    <a name = "setconsoleflags"></a>
    <strong>setconsoleflags (file, bitflags)</strong>
    </dt>
    <dd>
    Sets the console flags (Windows).
The <code>CIF_</code> and <code>COF_</code> constants are available on the module table. Where <code>CIF</code> are the
input flags (for use with <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>) and <code>COF</code> are the output flags (for use with
<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>/<a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>).</p>

<p>To see flag status and constant names check <a href="../modules/system.html#listconsoleflags">listconsoleflags</a>.</p>

<p>Note: not all combinations of flags are allowed, as some are mutually exclusive or mutually required.
See <a href="https://learn.microsoft.com/en-us/windows/console/setconsolemode">setconsolemode documentation</a>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">file</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
        <li><span class="parameter">bitflags</span>
            <span class="types"><a class="type" href="../classes/bitflags.html#">bitflags</a></span>
         the flags to set/unset
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">boolean</span></span>
        <code>true</code> on success
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>



    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> system = <span class="global">require</span>(<span class="string">'system'</span>)
system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdout) <span class="comment">-- List all the available flags and their current status
</span>
<span class="keyword">local</span> flags = system.<span class="function-name">getconsoleflags</span>(<span class="global">io</span>.stdout)
<span class="global">assert</span>(system.<span class="function-name">setconsoleflags</span>(<span class="global">io</span>.stdout,
        flags + system.COF_VIRTUAL_TERMINAL_PROCESSING)

system.<span class="function-name">listconsoleflags</span>(<span class="global">io</span>.stdout) <span class="comment">-- List again to check the differences</span></pre>
    </ul>

</dd>
    <dt>
    <a name = "setconsoleoutputcp"></a>
    <strong>setconsoleoutputcp (cp)</strong>
    </dt>
    <dd>
    Sets the current console output code page (Windows).


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">cp</span>
            <span class="types"><span class="type">int</span></span>
         the code page to set, use <a href="../modules/system.html#CODEPAGE_UTF8">system.CODEPAGE_UTF8</a> (65001) for UTF-8
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        <code>true</code> on success (always <code>true</code> on Posix systems)
    </ol>




</dd>
    <dt>
    <a name = "setnonblock"></a>
    <strong>setnonblock (fd, make_non_block)</strong>
    </dt>
    <dd>
    Enables or disables non-blocking mode for a file (Posix).


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fd</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
        <li><span class="parameter">make_non_block</span>
            <span class="types"><span class="type">boolean</span></span>
         a truthy value will enable non-blocking mode, a falsy value will disable it.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        <code>true</code>, if successful
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        errnum</li>
    </ol>


    <h3>See also:</h3>
    <ul>
         <a href="../modules/system.html#getnonblock">getnonblock</a>
    </ul>

    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span>(<span class="string">'system'</span>)

<span class="comment">-- set io.stdin to non-blocking mode
</span><span class="keyword">local</span> old_setting = sys.<span class="function-name">getnonblock</span>(<span class="global">io</span>.stdin)
sys.<span class="function-name">setnonblock</span>(<span class="global">io</span>.stdin, <span class="keyword">true</span>)

<span class="comment">-- do stuff
</span>
<span class="comment">-- restore old setting
</span>sys.<span class="function-name">setnonblock</span>(<span class="global">io</span>.stdin, old_setting)</pre>
    </ul>

</dd>
    <dt>
    <a name = "tcgetattr"></a>
    <strong>tcgetattr (fd)</strong>
    </dt>
    <dd>

<p>Get termios state (Posix).
The terminal attributes is a table with the following fields:</p>

<ul>
    <li><code>iflag</code> input flags</li>
    <li><code>oflag</code> output flags</li>
    <li><code>lflag</code> local flags</li>
    <li><code>cflag</code> control flags</li>
    <li><code>ispeed</code> input speed</li>
    <li><code>ospeed</code> output speed</li>
    <li><code>cc</code> control characters</li>
</ul>




    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fd</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

        error message if failed
    </ol>
     <h3>Or</h3>
    <ol>

           <span class="types"><span class="type">termios</span></span>
        terminal attributes, if successful. On Windows the bitflags are all 0, and the <code>cc</code> table is empty.
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        errnum</li>
    </ol>



    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> system = <span class="global">require</span>(<span class="string">'system'</span>)

<span class="keyword">local</span> status = <span class="global">assert</span>(<span class="function-name">tcgetattr</span>(<span class="global">io</span>.stdin))
<span class="keyword">if</span> status.iflag:<span class="function-name">has_all_of</span>(system.I_IGNBRK) <span class="keyword">then</span>
    <span class="global">print</span>(<span class="string">"Ignoring break condition"</span>)
<span class="keyword">end</span></pre>
    </ul>

</dd>
    <dt>
    <a name = "tcsetattr"></a>
    <strong>tcsetattr (fd, actions, termios)</strong>
    </dt>
    <dd>
    Set termios state (Posix).
This function will set the flags as given.</p>

<p>The <code>I_</code>, <code>O_</code>, and <code>L_</code> constants are available on the module table. They are the respective
flags for the <code>iflags</code>, <code>oflags</code>, and <code>lflags</code> bitmasks.</p>

<p>To see flag status and constant names check <a href="../modules/system.html#listtermflags">listtermflags</a>. For their meaning check
<a href="https://www.man7.org/linux/man-pages/man3/termios.3.html">the manpage</a>.</p>

<p><em>Note</em>: only <code>iflag</code>, <code>oflag</code>, and <code>lflag</code> are supported at the moment. The other fields are ignored.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">fd</span>
            <span class="types"><span class="type">file</span></span>
         file handle to operate on, one of <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdin">io.stdin</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stdout">io.stdout</a>, <a href="https://www.lua.org/manual/5.4/manual.html#pdf-io.stderr">io.stderr</a>
        </li>
        <li><span class="parameter">actions</span>
            <span class="types"><span class="type">integer</span></span>
         one of <code>TCSANOW</code>, <code>TCSADRAIN</code>, <code>TCSAFLUSH</code>
        </li>
        <li><span class="parameter">termios</span> a table with bitflag fields:
        <ul>
        <li><span class="parameter">iflag</span>
            <span class="types"><a class="type" href="../classes/bitflags.html#">bitflags</a></span>
         if given will set the input flags
         (<em>optional</em>)
        </li>
        <li><span class="parameter">oflag</span>
            <span class="types"><a class="type" href="../classes/bitflags.html#">bitflags</a></span>
         if given will set the output flags
         (<em>optional</em>)
        </li>
        <li><span class="parameter">lflag</span>
            <span class="types"><a class="type" href="../classes/bitflags.html#">bitflags</a></span>
         if given will set the local flags
         (<em>optional</em>)
        </li>
        </li></ul>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        <code>true</code>, if successful. Always returns <code>true</code> on Windows.
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
        nil</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        errnum</li>
    </ol>



    <h3>Usage:</h3>
    <ul>
        <pre class="example"><span class="keyword">local</span> system = <span class="global">require</span>(<span class="string">'system'</span>)

<span class="keyword">local</span> status = <span class="global">assert</span>(<span class="function-name">tcgetattr</span>(<span class="global">io</span>.stdin))
<span class="keyword">if</span> <span class="keyword">not</span> status.lflag:<span class="function-name">has_all_of</span>(system.L_ECHO) <span class="keyword">then</span>
    <span class="comment">-- if echo is off, turn echoing newlines on
</span>    <span class="function-name">tcsetattr</span>(<span class="global">io</span>.stdin, system.TCSANOW, { lflag = status.lflag + system.L_ECHONL }))
<span class="keyword">end</span></pre>
    </ul>

</dd>
    <dt>
    <a name = "termbackup"></a>
    <strong>termbackup ()</strong>
    </dt>
    <dd>
    Returns a backup of terminal settings for stdin/out/err.
 Handles terminal/console flags, Windows codepage, and non-block flags on the streams.
 Backs up terminal/console flags only if a stream is a tty.



    <h3>Returns:</h3>
    <ol>

        table with backup of terminal settings
    </ol>




</dd>
    <dt>
    <a name = "termrestore"></a>
    <strong>termrestore (backup)</strong>
    </dt>
    <dd>
    Restores terminal settings from a backup


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">backup</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.6">table</a></span>
         the backup of terminal settings, see <a href="../modules/system.html#termbackup">termbackup</a>.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">boolean</span></span>
        true
    </ol>




</dd>
    <dt>
    <a name = "termsize"></a>
    <strong>termsize ()</strong>
    </dt>
    <dd>
    Get the size of the terminal in rows and columns.



    <h3>Returns:</h3>
    <ol>
        <li>
           <span class="types"><span class="type">int</span></span>
        the number of rows</li>
        <li>
           <span class="types"><span class="type">int</span></span>
        the number of columns</li>
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>




</dd>
    <dt>
    <a name = "termwrap"></a>
    <strong>termwrap (f)</strong>
    </dt>
    <dd>
    Wraps a function to automatically restore terminal settings upon returning.
 Calls <a href="../modules/system.html#termbackup">termbackup</a> before calling the function and <a href="../modules/system.html#termrestore">termrestore</a> after.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">f</span>
            <span class="types"><span class="type">function</span></span>
         function to wrap
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">function</span></span>
        wrapped function
    </ol>




</dd>
    <dt>
    <a name = "utf8cwidth"></a>
    <strong>utf8cwidth (utf8_char)</strong>
    </dt>
    <dd>
    Get the width of a utf8 character for terminal display.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">utf8_char</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
         the utf8 character to check, only the width of the first character will be returned
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">int</span></span>
        the display width in columns of the first character in the string (0 for an empty string)
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>




</dd>
    <dt>
    <a name = "utf8swidth"></a>
    <strong>utf8swidth (utf8_string)</strong>
    </dt>
    <dd>
    Get the width of a utf8 string for terminal display.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">utf8_string</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
         the utf8 string to check
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">int</span></span>
        the display width of the string in columns (0 for an empty string)
    </ol>
     <h3>Or</h3>
    <ol>
        <li>
           <span class="types"><span class="type">nil</span></span>


</li>
        <li>
           <span class="types"><a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4">string</a></span>
        error message</li>
    </ol>




</dd>
</dl>
    <h2 class="section-header "><a name="Time"></a>Time </h2>

    <dl class="function">
    <dt>
    <a name = "gettime"></a>
    <strong>gettime ()</strong>
    </dt>
    <dd>
    Get system time.
The time is returned as the seconds since the epoch (1 January 1970 00:00:00).



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">number</span></span>
        seconds (fractional)
    </ol>




</dd>
    <dt>
    <a name = "monotime"></a>
    <strong>monotime ()</strong>
    </dt>
    <dd>
    Get monotonic time.
The time is returned as the seconds since system start.



    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">number</span></span>
        seconds (fractional)
    </ol>




</dd>
    <dt>
    <a name = "sleep"></a>
    <strong>sleep (seconds[, precision=16])</strong>
    </dt>
    <dd>
    Sleep without a busy loop.
This function will sleep, without doing a busy-loop and wasting CPU cycles.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">seconds</span>
            <span class="types"><span class="type">number</span></span>
         seconds to sleep (fractional).
        </li>
        <li><span class="parameter">precision</span>
            <span class="types"><span class="type">integer</span></span>
         minimum stepsize in milliseconds (Windows only, ignored elsewhere)
         (<em>default</em> 16)
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

        <code>true</code> on success, or <code>nil+err</code> on failure
    </ol>




</dd>
</dl>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
<i style="float:right;">Last updated 2024-06-20 23:11:37 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>