From 8aea22437583f0e5e263f326bb8eeaa940b41c95 Mon Sep 17 00:00:00 2001 From: Alex Chaffee Date: Sun, 4 Dec 2011 13:06:42 -0800 Subject: [PATCH] fix raw mode CRLF bug in a cleaner and hopefully more robust way --- lib/rerun/runner.rb | 6 ++++-- rerun.gemspec | 2 +- stty.rb | 32 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/rerun/runner.rb b/lib/rerun/runner.rb index 0096844..8300f9d 100644 --- a/lib/rerun/runner.rb +++ b/lib/rerun/runner.rb @@ -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? diff --git a/rerun.gemspec b/rerun.gemspec index 9378c6f..84e0a04 100644 --- a/rerun.gemspec +++ b/rerun.gemspec @@ -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." diff --git a/stty.rb b/stty.rb index ad39e25..01a7621 100644 --- a/stty.rb +++ b/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`