aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/init.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/system/init.lua b/system/init.lua
index a9f57e9..9c86c4a 100644
--- a/system/init.lua
+++ b/system/init.lua
@@ -10,6 +10,7 @@ local system = require 'system.core'
10--- UTF8 codepage. 10--- UTF8 codepage.
11-- To be used with `system.setconsoleoutputcp` and `system.setconsolecp`. 11-- To be used with `system.setconsoleoutputcp` and `system.setconsolecp`.
12-- @field CODEPAGE_UTF8 The Windows CodePage for UTF8. 12-- @field CODEPAGE_UTF8 The Windows CodePage for UTF8.
13-- @within Terminal_UTF-8
13system.CODEPAGE_UTF8 = 65001 14system.CODEPAGE_UTF8 = 65001
14 15
15do 16do
@@ -19,6 +20,7 @@ do
19 -- Handles terminal/console flags, Windows codepage, and non-block flags on the streams. 20 -- Handles terminal/console flags, Windows codepage, and non-block flags on the streams.
20 -- Backs up terminal/console flags only if a stream is a tty. 21 -- Backs up terminal/console flags only if a stream is a tty.
21 -- @return table with backup of terminal settings 22 -- @return table with backup of terminal settings
23 -- @within Terminal_Backup
22 function system.termbackup() 24 function system.termbackup()
23 local backup = { 25 local backup = {
24 __type = backup_indicator, -- cannot set a metatable, since autotermrestore uses it for GC 26 __type = backup_indicator, -- cannot set a metatable, since autotermrestore uses it for GC
@@ -52,6 +54,7 @@ do
52 --- Restores terminal settings from a backup 54 --- Restores terminal settings from a backup
53 -- @tparam table backup the backup of terminal settings, see `termbackup`. 55 -- @tparam table backup the backup of terminal settings, see `termbackup`.
54 -- @treturn boolean true 56 -- @treturn boolean true
57 -- @within Terminal_Backup
55 function system.termrestore(backup) 58 function system.termrestore(backup)
56 if type(backup) ~= "table" or backup.__type ~= backup_indicator then 59 if type(backup) ~= "table" or backup.__type ~= backup_indicator then
57 error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2) 60 error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2)
@@ -108,6 +111,7 @@ do -- autotermrestore
108 -- @treturn[1] boolean true 111 -- @treturn[1] boolean true
109 -- @treturn[2] nil if the backup was already created 112 -- @treturn[2] nil if the backup was already created
110 -- @treturn[2] string error message 113 -- @treturn[2] string error message
114 -- @within Terminal_Backup
111 function system.autotermrestore() 115 function system.autotermrestore()
112 if global_backup then 116 if global_backup then
113 return nil, "global terminal backup was already set up" 117 return nil, "global terminal backup was already set up"
@@ -136,6 +140,7 @@ do
136 -- Calls `termbackup` before calling the function and `termrestore` after. 140 -- Calls `termbackup` before calling the function and `termrestore` after.
137 -- @tparam function f function to wrap 141 -- @tparam function f function to wrap
138 -- @treturn function wrapped function 142 -- @treturn function wrapped function
143 -- @within Terminal_Backup
139 function system.termwrap(f) 144 function system.termwrap(f)
140 if type(f) ~= "function" then 145 if type(f) ~= "function" then
141 error("arg #1 to wrap, expected function, got " .. type(f), 2) 146 error("arg #1 to wrap, expected function, got " .. type(f), 2)
@@ -155,6 +160,7 @@ end
155--- Debug function for console flags (Windows). 160--- Debug function for console flags (Windows).
156-- Pretty prints the current flags set for the handle. 161-- Pretty prints the current flags set for the handle.
157-- @param fh file handle (`io.stdin`, `io.stdout`, `io.stderr`) 162-- @param fh file handle (`io.stdin`, `io.stdout`, `io.stderr`)
163-- @within Terminal_Windows
158-- @usage -- Print the flags for stdin/out/err 164-- @usage -- Print the flags for stdin/out/err
159-- system.listconsoleflags(io.stdin) 165-- system.listconsoleflags(io.stdin)
160-- system.listconsoleflags(io.stdout) 166-- system.listconsoleflags(io.stdout)
@@ -194,6 +200,7 @@ end
194--- Debug function for terminal flags (Posix). 200--- Debug function for terminal flags (Posix).
195-- Pretty prints the current flags set for the handle. 201-- Pretty prints the current flags set for the handle.
196-- @param fh file handle (`io.stdin`, `io.stdout`, `io.stderr`) 202-- @param fh file handle (`io.stdin`, `io.stdout`, `io.stderr`)
203-- @within Terminal_Posix
197-- @usage -- Print the flags for stdin/out/err 204-- @usage -- Print the flags for stdin/out/err
198-- system.listconsoleflags(io.stdin) 205-- system.listconsoleflags(io.stdin)
199-- system.listconsoleflags(io.stdout) 206-- system.listconsoleflags(io.stdout)
@@ -242,6 +249,7 @@ do
242 -- @treturn[1] byte the byte value that was read. 249 -- @treturn[1] byte the byte value that was read.
243 -- @treturn[2] nil if no key was read 250 -- @treturn[2] nil if no key was read
244 -- @treturn[2] string error message when the timeout was reached (`"timeout"`), or if `sleep` failed. 251 -- @treturn[2] string error message when the timeout was reached (`"timeout"`), or if `sleep` failed.
252 -- @within Terminal_Input
245 function system.readkey(timeout, fsleep) 253 function system.readkey(timeout, fsleep)
246 if type(timeout) ~= "number" then 254 if type(timeout) ~= "number" then
247 error("arg #1 to readkey, expected timeout in seconds, got " .. type(timeout), 2) 255 error("arg #1 to readkey, expected timeout in seconds, got " .. type(timeout), 2)
@@ -288,6 +296,7 @@ do
288 -- @treturn[2] string partial result in case of an error while reading a sequence, the sequence so far. 296 -- @treturn[2] string partial result in case of an error while reading a sequence, the sequence so far.
289 -- The function retains its own internal buffer, so on the next call the incomplete buffer is used to 297 -- The function retains its own internal buffer, so on the next call the incomplete buffer is used to
290 -- complete the sequence. 298 -- complete the sequence.
299 -- @within Terminal_Input
291 function system.readansi(timeout, fsleep) 300 function system.readansi(timeout, fsleep)
292 if type(timeout) ~= "number" then 301 if type(timeout) ~= "number" then
293 error("arg #1 to readansi, expected timeout in seconds, got " .. type(timeout), 2) 302 error("arg #1 to readansi, expected timeout in seconds, got " .. type(timeout), 2)