Skip to content

Commit

Permalink
fix raw mode CRLF bug in a cleaner and hopefully more robust way
Browse files Browse the repository at this point in the history
  • Loading branch information
alexch committed Dec 4, 2011
1 parent 457320f commit 8aea224
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions lib/rerun/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion rerun.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
32 changes: 22 additions & 10 deletions stty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def tty
stty.split(':')
end


def tty_setting name
tty.grep(/^#{name}/).first.split('=').last
end
Expand All @@ -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.