module Lecture::Terminal
Private Instance Methods
clear()
click to toggle source
# File lib/lecture/terminal.rb, line 7 def clear print "\e[2J\e[H" end
clear_and_exit(exit_status = 0)
click to toggle source
# File lib/lecture/terminal.rb, line 11 def clear_and_exit(exit_status = 0) clear exit exit_status end
cols()
click to toggle source
# File lib/lecture/terminal.rb, line 16 def cols IO.console.winsize[1] end
getch()
click to toggle source
# File lib/lecture/terminal.rb, line 20 def getch prep_for_keyboard_entry do if (input = STDIN.getc.chr) == "\e" input << STDIN.read_nonblock(3) rescue nil input << STDIN.read_nonblock(2) rescue nil end input end end
lines()
click to toggle source
# File lib/lecture/terminal.rb, line 31 def lines IO.console.winsize[0] end
move_to(x, y)
click to toggle source
# File lib/lecture/terminal.rb, line 35 def move_to(x, y) print "\033[#{y};#{x}H" end
prep_for_keyboard_entry() { || ... }
click to toggle source
# File lib/lecture/terminal.rb, line 39 def prep_for_keyboard_entry begin STDIN.echo = false STDIN.raw! input = yield ensure STDIN.echo = true STDIN.cooked! end input end
print_line(line, x, y)
click to toggle source
# File lib/lecture/terminal.rb, line 53 def print_line(line, x, y) move_to(x, y) line.each_char do |c| print c sleep [ Lecture.transition_time / line.length, Lecture.character_print_delay ].min end end