Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ local function main()
print(to_hex_debug_format(key))

local keyname = keymap[key]
print(yellow("\tit has the internal name: '") .. tostring(keyname) .. yellow("'"))
print(yellow("\tit maps to the names:"))
print(yellow("\tkey name: '") .. tostring(keyname) .. yellow("'"))
print(yellow("\taliases:"))
for k, v in pairs(keys) do
if v == keyname then
print("\t\t" .. k)
Expand Down
34 changes: 34 additions & 0 deletions src/terminal/input/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ M.sys_readansi = sys.readansi
-- @tparam number timeout the timeout in seconds
-- @tparam[opt] function fsleep the sleep function to use (default: the sleep function
-- set by `initialize`)
-- @see terminal.input.keymap
-- @usage
-- local t = require "terminal"
-- local key_names = t.input.keymap.default_key_map
-- local keys = t.input.keymap.default_keys
--
-- -- read a key, and look up its name
-- local rawkey, keytype = t.input.readansi(math.huge)
-- local keyname = key_names[rawkey] -- note: not every key has a name
--
-- -- use the 'keys' table to check for key-names to prevent
-- -- having to use magic strings
-- if keyname == keys.escape then
-- t.output.print("Escape key pressed")
-- elseif keyname == keys.up then
-- t.output.print("Up key pressed")
-- elseif keyname == keys.down then
-- t.output.print("Down key pressed")
-- elseif keyname == keys.left then
-- t.output.print("Left key pressed")
-- elseif keyname == keys.right then
-- t.output.print("Right key pressed")
-- else
-- -- check on key-type; ctrl/ansi/char
-- if keytype == "ctrl" then
-- t.output.print("Control key pressed: " .. tostring(keyname))
-- elseif keytype == "ansi" then
-- t.output.print("ANSI key pressed: " .. tostring(keyname))
-- elseif keytype == "char" then
-- t.output.print("Character key pressed: " .. tostring(rawkey)) -- use rawkey here, not keyname
-- else
-- error("this cannot happen! keytype: " .. tostring(keytype))
-- end
-- end
function M.readansi(timeout, fsleep)
if kbend == 0 then
-- buffer is empty, so read from the terminal
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/input/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
-- local key_map = terminal.input.keymap.default_key_map
-- local keys = terminal.input.keymap.default_keys
--
-- -- lookup the key-name from the raw inpout
-- -- lookup the key-name from the raw input
-- local keyname = key_map[rawkey] --> "ctrl_m"
--
-- -- the following if statements are equivalent:
Expand Down
Loading