Skip to content

Commit 56ffc31

Browse files
authored
Extract stty calls into separate module (#30)
Closes #29
1 parent 73a2919 commit 56ffc31

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/stty.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Stty = {}
2+
3+
function Stty.enableRawMode()
4+
os.execute("/bin/stty raw")
5+
end
6+
7+
function Stty.disableRawMode()
8+
os.execute("/bin/stty sane")
9+
end
10+
11+
function Stty.disableEcho()
12+
os.execute("/bin/stty -echo")
13+
end
14+
15+
function Stty.enableEcho()
16+
os.execute("/bin/stty echo")
17+
end
18+
19+
return Stty

lib/term.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local stty = require("lib/stty")
2+
13
Term = {}
24
Term.internalInputBuffer = ""
35
Term.internalOutputBuffer = ""
@@ -145,8 +147,8 @@ end
145147
--- This will disable echo and line buffering
146148
--- It will also switch to the alternate screen buffer
147149
function Term.enterRawMode()
148-
os.execute("/bin/stty raw")
149-
os.execute("/bin/stty -echo")
150+
stty.enableRawMode()
151+
stty.disableEcho()
150152
io.write("\27[?1049h")
151153
io.flush()
152154
end
@@ -157,8 +159,8 @@ end
157159
function Term.leaveRawMode()
158160
io.write("\27[?1049l")
159161
io.flush()
160-
os.execute("/bin/stty echo")
161-
os.execute("/bin/stty sane")
162+
stty.enableEcho()
163+
stty.disableRawMode()
162164
end
163165

164166
--- Requests the cursor position from the terminal.

0 commit comments

Comments
 (0)