Remove evil curses
Install
gem install dispel
Usage
Black and white
require 'dispel'
# draw app and redraw after each keystroke
Dispel::Screen.open do |screen|
screen.draw "Initial state, press any key!\n\n Oh boy!"
Dispel::Keyboard.output do |key|
break if key == :"Ctrl+c"
screen.draw "Looks like you pressed #{key} (Ctrl+c to quit)"
end
end
Colors
require 'dispel'
# draw app and redraw after each keystroke
Dispel::Screen.open(colors: true) do |screen|
map = Dispel::StyleMap.new(3) # number of lines
map.add(:reverse, 0, 1..5) # :normal / :reverse / color, line, characters
map.add(["#aa0000", "#00aa00"], 0, 5..8) # foreground red, background green
screen.draw "Shiny Rainbows!\nDefault\nand more!", map, [0,3] # text, styles, cursor position
Dispel::Keyboard.output { break }
end
Periodical refresh
require 'dispel'
# draw app and redraw after each keystroke
Dispel::Screen.open do |screen|
Dispel::Keyboard.output timeout: 0.5 do |key|
if key == :timeout
screen.draw "The time is #{Time.now}"
elsif key == :"Ctrl+c"
break
else
screen.draw "You pressed #{key}"
end
end
end
Example applications
TODO
- resize event should triggered instantly after resizing, not after first key press
Author
Michael Grosser
michael@grosser.it
License: MIT