Skip to content

Instantly share code, notes, and snippets.

@csmr
Last active November 23, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csmr/c528116a585c4c1c68ee7b8e83d004fd to your computer and use it in GitHub Desktop.
Save csmr/c528116a585c4c1c68ee7b8e83d004fd to your computer and use it in GitHub Desktop.
STDIN.read(1) and STDIN.getc reading in multiple characters
# encoding: utf-8
module G
class UI
def initialize
require 'io/console' # for on-key input
@input_buffer = ""
@_debug_frame = 0
ui_run 1
end
def ui_refresh(ui)
_drawing_bool = true
#ui_render_view
STDOUT.puts " ***** #{__FILE__} - " + @_debug_frame.to_s
_drawing_bool = false
end
def ui_run argh
#require 'pry'; binding.pry
STDOUT.puts Thread.current.to_s + @_debug_frame.to_s
_state_int = argh
while _state_int == 1
ui_refresh(0)
@_debug_frame += 1
#input?
#ui_grab_input
tmp = STDIN.getc
puts tmp + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
sleep(0.1)
end
end # ui_run loop
def ui_grab_input
@input_buffer << $stdin.gets.chomp
# _inp << STDIN.getch
# exit(1) if _input_buffer.include? "\u0003"
# puts "IN PUT !!!!! " + _inp
end
end # class UI
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment