Skip to content

Instantly share code, notes, and snippets.

@giann
Created February 13, 2019 09:03
Show Gist options
  • Save giann/4e226baf318a4e3592c7058ee0defee3 to your computer and use it in GitHub Desktop.
Save giann/4e226baf318a4e3592c7058ee0defee3 to your computer and use it in GitHub Desktop.
Echo keyboard input (useful to print out escape codes)
os.execute("/usr/bin/env stty raw -echo 2> /dev/null")
local term = require "term"
local function loop()
local char
repeat
term.cursor.save()
char = io.stdin:read(1)
print("- " .. char:byte(1) .. ": " .. char)
term.cursor.restore()
term.cleareol()
until char == "\r"
end
pcall(loop)
os.execute("/usr/bin/env stty sane")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment