Skip to content

Commit 8aea224

Browse files
committed
fix raw mode CRLF bug in a cleaner and hopefully more robust way
1 parent 457320f commit 8aea224

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

lib/rerun/runner.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,14 @@ def say msg
229229
def key_pressed
230230
begin
231231
# this "raw input" nonsense is because unix likes waiting for linefeeds before sending stdin
232-
system("stty raw") # turn raw input on
232+
233+
# 'raw' means turn raw input on
233234

234235
# restore proper output newline handling -- see stty.rb and "man stty" and /usr/include/sys/termios.h
235236
# looks like "raw" flips off the OPOST bit 0x00000001 /* enable following output processing */
236237
# which disables #define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
237-
system("stty gfmt1:oflag=3")
238+
# so this sets it back on again since all we care about is raw input, not raw output
239+
system("stty raw opost")
238240

239241
c = nil
240242
if $stdin.ready?

rerun.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $spec = Gem::Specification.new do |s|
33
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
44

55
s.name = 'rerun'
6-
s.version = '0.6.4'
6+
s.version = '0.6.5'
77

88
s.description = "Restarts your app when a file changes"
99
s.summary = "Launches an app, and restarts it whenever the filesystem changes."

stty.rb

+22-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def tty
88
stty.split(':')
99
end
1010

11-
1211
def tty_setting name
1312
tty.grep(/^#{name}/).first.split('=').last
1413
end
@@ -18,29 +17,42 @@ def oflag
1817
end
1918

2019
normal = tty
20+
2121
`stty raw`
2222
raw = tty
23+
2324
`stty -raw`
24-
post_raw = tty
25-
assert { post_raw == normal }
25+
minus_raw = tty
26+
assert { minus_raw == normal }
27+
28+
`stty raw opost`
29+
raw_opost = tty
2630

2731
d { raw - normal }
2832
d { normal - raw }
33+
d { normal - raw_opost }
2934

3035
puts "== normal"
3136
# d { tty }
3237
d{oflag}
3338

3439
def check setting
35-
`stty gfmt1:#{setting}`
40+
`stty #{setting}`
3641
puts "testing #{setting}:\nline\nline"
42+
print "\r\n"
3743
end
3844

39-
puts "== raw"
40-
`stty raw`
41-
puts "testing\nraw\nmode"
45+
check "raw"
46+
47+
check "-raw"
48+
49+
check "raw opost"
50+
51+
check "-raw"
52+
53+
check "raw gfmt1:oflag=3"
4254

43-
check "oflag=3"
44-
check "lflag=200005cb"
45-
check "iflag=2b02"
55+
# check "oflag=3"
56+
# check "lflag=200005cb"
57+
# check "iflag=2b02"
4658
`stty -raw`

0 commit comments

Comments
 (0)