Skip to content

Commit

Permalink
Extract stty calls into separate module (#30)
Browse files Browse the repository at this point in the history
Closes #29
  • Loading branch information
InDieTasten authored Oct 13, 2024
1 parent 73a2919 commit 56ffc31
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 19 additions & 0 deletions lib/stty.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Stty = {}

function Stty.enableRawMode()
os.execute("/bin/stty raw")
end

function Stty.disableRawMode()
os.execute("/bin/stty sane")
end

function Stty.disableEcho()
os.execute("/bin/stty -echo")
end

function Stty.enableEcho()
os.execute("/bin/stty echo")
end

return Stty
10 changes: 6 additions & 4 deletions lib/term.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local stty = require("lib/stty")

Term = {}
Term.internalInputBuffer = ""
Term.internalOutputBuffer = ""
Expand Down Expand Up @@ -145,8 +147,8 @@ end
--- This will disable echo and line buffering
--- It will also switch to the alternate screen buffer
function Term.enterRawMode()
os.execute("/bin/stty raw")
os.execute("/bin/stty -echo")
stty.enableRawMode()
stty.disableEcho()
io.write("\27[?1049h")
io.flush()
end
Expand All @@ -157,8 +159,8 @@ end
function Term.leaveRawMode()
io.write("\27[?1049l")
io.flush()
os.execute("/bin/stty echo")
os.execute("/bin/stty sane")
stty.enableEcho()
stty.disableRawMode()
end

--- Requests the cursor position from the terminal.
Expand Down

0 comments on commit 56ffc31

Please sign in to comment.