Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created September 17, 2014 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/f09a82d828dfcc52d3c8 to your computer and use it in GitHub Desktop.
Save JoshCheek/f09a82d828dfcc52d3c8 to your computer and use it in GitHub Desktop.
Script I wrote while failing to debug https://github.com/pry/pry/issues/1290#issuecomment-55916557
# Values found with `stty -g`
# Turns out you can do `stty -a` to get human readable values
# Context is at https://github.com/pry/pry/issues/1290#issuecomment-55916557
configs = [
[:broken_pry, "gfmt1:cflag=4b00:iflag=2b02:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], # => [:broken_pry, "gfmt1:cflag=4b00:iflag=2b02:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"]
[:good_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], # => [:good_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"]
[:bad_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005c7:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], # => [:bad_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005c7:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"]
].each_with_object({}) do |(key, value), configs| # => [[:broken_pry, "gfmt1:cflag=4b00:iflag=2b02:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], [:good_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:qu...
configs[key] = {} # => {}, {}, {}
value.split(":").each { |keyval| # => ["gfmt1", "cflag=4b00", "iflag=2b02", "lflag=200005cf", "oflag=3", "discard=f", "dsusp=19", "eof=4", "eol=ff", "eol2=ff", "erase=7f", "intr=3", "kill=15", "lnext=16", "min=1", "quit=1c", "reprint=12", "start=11", "status=14", "stop=13", "susp=1a", "time=0", "werase=17", "ispeed=38400", "ospeed=38400"], ["gfmt1", "cflag=4b00", "iflag=6902", "lflag=200005cf", "oflag=3", "discard=f", "dsusp=1...
if keyval.include?('=') # => false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true,...
config_key, config_value = keyval.split('=', 2) # => ["cflag", "4b00"], ["iflag", "2b02"], ["lflag", "200005cf"], ["oflag", "3"], ["discard", "f"], ["dsusp", "19"], ["eof", "4"], ["eol", "ff"], ["eol2", "ff"], ["erase", "7f"], ["intr", "3"], ["kill", "15"], ["lnext", "16"], ["min", "1"], ["quit", "1c"], ["reprint", "12"], ["start", "11"], ["status", "14"], ["stop", "13"], ["susp", "1a"], ["time", "0"], ["werase", "17"], ["ispeed", "38400"], ...
configs[key][config_key] = config_value # => "4b00", "2b02", "200005cf", "3", "f", "19", "4", "ff", "ff", "7f", "3", "15", "16", "1", "1c", "12", "11", "14", "13", "1a", "0", "17", "38400", "38400", "4b00", "6902", "200005cf", "3", "f", "19", "4", "ff", "ff", "7f", "3", "15", "16", "1", "1c", "12", "11", "14", "13", "1a", "0", "17", "38400", "38400", "4b00", "6902", "200005c7", "3", "f", "19", "4", "ff", "ff", "7f", "3", "15", "16", ...
else
configs[key][keyval] = true # => true, true, true
end # => true, "4b00", "2b02", "200005cf", "3", "f", "19", "4", "ff", "ff", "7f", "3", "15", "16", "1", "1c", "12", "11", "14", "13", "1a", "0", "17", "38400", "38400", true, "4b00", "6902", "200005cf", "3", "f", "19", "4", "ff", "ff", "7f", "3", "15", "16", "1", "1c", "12", "11", "14", "13", "1a", "0", "17", "38400", "38400", true, "4b00", "6902", "200005c7", "3", "f", "19", "4", "ff", "ff", "7f",...
} # => ["gfmt1", "cflag=4b00", "iflag=2b02", "lflag=200005cf", "oflag=3", "discard=f", "dsusp=19", "eof=4", "eol=ff", "eol2=ff", "erase=7f", "intr=3", "kill=15", "lnext=16", "min=1", "quit=1c", "reprint=12", "start=11", "status=14", "stop=13", "susp=1a", "time=0", "werase=17", "ispeed=38400", "ospeed=38400"], ["gfmt1", "cflag=4b00", "iflag=6902", "lflag=200005cf", "oflag=3", "discard=f", "dsusp=1...
end # => {:broken_pry=>{"gfmt1"=>true, "cflag"=>"4b00", "iflag"=>"2b02", "lflag"=>"200005cf", "oflag"=>"3", "discard"=>"f", "dsusp"=>"19", "eof"=>"4", "eol"=>"ff", "eol2"=>"ff", "erase"=>"7f", "intr"=>"3", "kill"=>"15", "lnext"=>"16", "min"=>"1", "quit"=>"1c", "reprint"=>"12", "start"=>"11", "status"=>"14", "stop"=>"13", "susp"=>"1a", "time"=>"0", "werase"=>"17", "ispeed"=>"38400", "ospeed"=>"38400...
all_keys = configs.map { |k, v| v.keys }.inject(:|) # => ["gfmt1", "cflag", "iflag", "lflag", "oflag", "discard", "dsusp", "eof", "eol", "eol2", "erase", "intr", "kill", "lnext", "min", "quit", "reprint", "start", "status", "stop", "susp", "time", "werase", "ispeed", "ospeed"]
raise "Keys don't overlap" unless (all_keys - configs[:broken_pry].keys).empty? # => nil
raise "Keys don't overlap" unless (all_keys - configs[:good_term].keys).empty? # => nil
raise "Keys don't overlap" unless (all_keys - configs[:bad_term].keys).empty? # => nil
configs.each do |name, config| # => {:broken_pry=>{"gfmt1"=>true, "cflag"=>"4b00", "iflag"=>"2b02", "lflag"=>"200005cf", "oflag"=>"3", "discard"=>"f", "dsusp"=>"19", "eof"=>"4", "eol"=>"ff", "eol2"=>"ff", "erase"=>"7f", "intr"=>"3", "kill"=>"15", "lnext"=>"16", "min"=>"1", "quit"=>"1c", "reprint"=>"12", "start"=>"11", "status"=>"14", "stop"=>"13", "susp"=>"1a", "time"=>"0", "werase"=>"17", "ispeed"=>"38400", "ospeed"=>"38400...
next if name == :good_term # => false, true, false
puts name # => nil, nil
config.each do |key, value| # => {"gfmt1"=>true, "cflag"=>"4b00", "iflag"=>"2b02", "lflag"=>"200005cf", "oflag"=>"3", "discard"=>"f", "dsusp"=>"19", "eof"=>"4", "eol"=>"ff", "eol2"=>"ff", "erase"=>"7f", "intr"=>"3", "kill"=>"15", "lnext"=>"16", "min"=>"1", "quit"=>"1c", "reprint"=>"12", "start"=>"11", "status"=>"14", "stop"=>"13", "susp"=>"1a", "time"=>"0", "werase"=>"17", "ispeed"=>"38400", "ospeed"=>"38400"}, {"gfmt1"=>...
puts " #{key} good=#{configs[:good_term][key]} bad=#{value}" if configs[:good_term][key] != value # => nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
end # => {"gfmt1"=>true, "cflag"=>"4b00", "iflag"=>"2b02", "lflag"=>"200005cf", "oflag"=>"3", "discard"=>"f", "dsusp"=>"19", "eof"=>"4", "eol"=>"ff", "eol2"=>"ff", "erase"=>"7f", "intr"=>"3", "kill"=>"15", "lnext"=>"16", "min"=>"1", "quit"=>"1c", "reprint"=>"12", "start"=>"11", "status"=>"14", "stop"=>"13", "susp"=>"1a", "time"=>"0", "werase"=>"17", "ispeed"=>"38400", "ospeed"=>"38400"}, {"gfmt1"=>...
end # => {:broken_pry=>{"gfmt1"=>true, "cflag"=>"4b00", "iflag"=>"2b02", "lflag"=>"200005cf", "oflag"=>"3", "discard"=>"f", "dsusp"=>"19", "eof"=>"4", "eol"=>"ff", "eol2"=>"ff", "erase"=>"7f", "intr"=>"3", "kill"=>"15", "lnext"=>"16", "min"=>"1", "quit"=>"1c", "reprint"=>"12", "start"=>"11", "status"=>"14", "stop"=>"13", "susp"=>"1a", "time"=>"0", "werase"=>"17", "ispeed"=>"38400", "ospeed"=>"38400...
# >> broken_pry
# >> iflag good=6902 bad=2b02
# >> bad_term
# >> lflag good=200005cf bad=200005c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment