Permalink
Browse files

fix raw mode CRLF bug in a cleaner and hopefully more robust way

  • Loading branch information...
1 parent 457320f commit 8aea22437583f0e5e263f326bb8eeaa940b41c95 @alexch committed Dec 4, 2011
Showing with 27 additions and 13 deletions.
  1. +4 −2 lib/rerun/runner.rb
  2. +1 −1 rerun.gemspec
  3. +22 −10 stty.rb
View
@@ -229,12 +229,14 @@ def say msg
def key_pressed
begin
# this "raw input" nonsense is because unix likes waiting for linefeeds before sending stdin
- system("stty raw") # turn raw input on
+
+ # 'raw' means turn raw input on
# restore proper output newline handling -- see stty.rb and "man stty" and /usr/include/sys/termios.h
# looks like "raw" flips off the OPOST bit 0x00000001 /* enable following output processing */
# which disables #define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
- system("stty gfmt1:oflag=3")
+ # so this sets it back on again since all we care about is raw input, not raw output
+ system("stty raw opost")
c = nil
if $stdin.ready?
View
@@ -3,7 +3,7 @@ $spec = Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.name = 'rerun'
- s.version = '0.6.4'
+ s.version = '0.6.5'
s.description = "Restarts your app when a file changes"
s.summary = "Launches an app, and restarts it whenever the filesystem changes."
View
32 stty.rb
@@ -8,7 +8,6 @@ def tty
stty.split(':')
end
-
def tty_setting name
tty.grep(/^#{name}/).first.split('=').last
end
@@ -18,29 +17,42 @@ def oflag
end
normal = tty
+
`stty raw`
raw = tty
+
`stty -raw`
-post_raw = tty
-assert { post_raw == normal }
+minus_raw = tty
+assert { minus_raw == normal }
+
+`stty raw opost`
+raw_opost = tty
d { raw - normal }
d { normal - raw }
+d { normal - raw_opost }
puts "== normal"
# d { tty }
d{oflag}
def check setting
- `stty gfmt1:#{setting}`
+ `stty #{setting}`
puts "testing #{setting}:\nline\nline"
+ print "\r\n"
end
-puts "== raw"
-`stty raw`
-puts "testing\nraw\nmode"
+check "raw"
+
+check "-raw"
+
+check "raw opost"
+
+check "-raw"
+
+check "raw gfmt1:oflag=3"
-check "oflag=3"
-check "lflag=200005cb"
-check "iflag=2b02"
+# check "oflag=3"
+# check "lflag=200005cb"
+# check "iflag=2b02"
`stty -raw`

0 comments on commit 8aea224

Please sign in to comment.