Ruby: Remove evil curses
Ruby
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
spec
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE
Rakefile
Readme.md
dispel.gemspec
gem-public_cert.pem

Readme.md

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

Timeouts

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
Build Status