diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | system/init.lua | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index aa242d9..3cd8447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -27,6 +27,10 @@ The scope of what is covered by the version number excludes: | |||
27 | 27 | ||
28 | ## Version history | 28 | ## Version history |
29 | 29 | ||
30 | ### version 0.6.2, unreleased | ||
31 | |||
32 | - Fix: autotermrestore didn't work because its metatable was overwritten. | ||
33 | |||
30 | ### version 0.6.1, released 13-Apr-2025 | 34 | ### version 0.6.1, released 13-Apr-2025 |
31 | 35 | ||
32 | - Docs: document readansi internal buffer for incomplete sequences. | 36 | - Docs: document readansi internal buffer for incomplete sequences. |
diff --git a/system/init.lua b/system/init.lua index e0e5f21..a9f57e9 100644 --- a/system/init.lua +++ b/system/init.lua | |||
@@ -13,14 +13,16 @@ local system = require 'system.core' | |||
13 | system.CODEPAGE_UTF8 = 65001 | 13 | system.CODEPAGE_UTF8 = 65001 |
14 | 14 | ||
15 | do | 15 | do |
16 | local backup_mt = {} | 16 | local backup_indicator = {} |
17 | 17 | ||
18 | --- Returns a backup of terminal settings for stdin/out/err. | 18 | --- Returns a backup of terminal settings for stdin/out/err. |
19 | -- Handles terminal/console flags, Windows codepage, and non-block flags on the streams. | 19 | -- 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. | 20 | -- Backs up terminal/console flags only if a stream is a tty. |
21 | -- @return table with backup of terminal settings | 21 | -- @return table with backup of terminal settings |
22 | function system.termbackup() | 22 | function system.termbackup() |
23 | local backup = setmetatable({}, backup_mt) | 23 | local backup = { |
24 | __type = backup_indicator, -- cannot set a metatable, since autotermrestore uses it for GC | ||
25 | } | ||
24 | 26 | ||
25 | if system.isatty(io.stdin) then | 27 | if system.isatty(io.stdin) then |
26 | backup.console_in = system.getconsoleflags(io.stdin) | 28 | backup.console_in = system.getconsoleflags(io.stdin) |
@@ -51,7 +53,7 @@ do | |||
51 | -- @tparam table backup the backup of terminal settings, see `termbackup`. | 53 | -- @tparam table backup the backup of terminal settings, see `termbackup`. |
52 | -- @treturn boolean true | 54 | -- @treturn boolean true |
53 | function system.termrestore(backup) | 55 | function system.termrestore(backup) |
54 | if getmetatable(backup) ~= backup_mt then | 56 | if type(backup) ~= "table" or backup.__type ~= backup_indicator then |
55 | error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2) | 57 | error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2) |
56 | end | 58 | end |
57 | 59 | ||