-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm.lua
More file actions
37 lines (30 loc) · 2.11 KB
/
term.lua
File metadata and controls
37 lines (30 loc) · 2.11 KB
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
local expect = require "cc.expect"
local syscall = require "_syscall"
-- TODO: Figure out GFX mode plans (omit? setGraphicsMode?)
local term = {}
local thandle = assert(syscall.openterm())
local native = {}
local current = native
-- local getTextColor, setTextColor, getBackgroundColor, setBackgroundColor, getPaletteColor, setPaletteColor, nativePaletteColor =
-- native.getTextColor, native.setTextColor, native.getBackgroundColor, native.setBackgroundColor, native.getPaletteColor, native.setPaletteColor, native.nativePaletteColor
-- function native.getTextColor() return 2^getTextColor() end
-- function native.setTextColor(color) return setTextColor(select(2, math.frexp(color))-1) end
-- function native.getBackgroundColor() return 2^getBackgroundColor() end
-- function native.setBackgroundColor(color) return setBackgroundColor(select(2, math.frexp(color))-1) end
-- function native.getPaletteColor(color) return getPaletteColor(select(2, math.frexp(color))-1) end
-- function native.setPaletteColor(color, r, g, b) return setPaletteColor(select(2, math.frexp(color))-1, r, g, b) end
-- function native.nativePaletteColor(color) return nativePaletteColor(select(2, math.frexp(color))-1) end
-- native.getTextColour, native.setTextColour, native.getBackgroundColour, native.setBackgroundColour, native.getPaletteColour, native.setPaletteColour, native.nativePaletteColour =
-- native.getTextColor, native.setTextColor, native.getBackgroundColor, native.setBackgroundColor, native.getPaletteColor, native.setPaletteColor, native.nativePaletteColor
for k, v in pairs(thandle) do native[k] = v term[k] = function(...) return current[k](...) end end
function term.redirect(target)
expect(1, target, "table")
if target == term then error("term is not a recommended redirect target, try term.current() instead", 2) end
for k in pairs(native) do if type(target[k]) ~= "function" then target[k] = function() error("Redirect object is missing method " .. k .. ".", 2) end end end
local old = current
current = target
return old
end
function term.current() return current end
function term.native() return native end
return term