Skip to content

Instantly share code, notes, and snippets.

@greenmoss
Created October 28, 2010 17:51
Show Gist options
  • Save greenmoss/651912 to your computer and use it in GitHub Desktop.
Save greenmoss/651912 to your computer and use it in GitHub Desktop.
$ cat dwatch_stub.rb
#!/usr/bin/env ruby
require 'logger'
require 'rubygems'
require 'ncurses'
class Ncurses::WINDOW
def initialize( height, width, starty, startx )
raise 'Boo!'
w = super( height, width, starty, startx )
w.clear
w.move(0,0)
w.addstr('first psot')
@log = Logger.new('/tmp/initialize.log')
@log.level = Logger::INFO
@log.info 'initialized'
w
end
def move( y, x )
@log = Logger.new('/tmp/move.log')
@log.level = Logger::INFO
@log.info "moving to: #{y}, #{x}"
super
end
end
w2 = Ncurses::WINDOW.new(20, 20, 10, 10)
begin
# initialize ncurses
Ncurses.initscr
Ncurses.cbreak # provide unbuffered input
Ncurses.noecho # turn off input echoing
Ncurses.nonl # turn off newline translation
Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
Ncurses.stdscr.keypad(true) # turn on keypad mode
Ncurses.stdscr.nodelay(true) # don't block on getch
Ncurses.curs_set(0) # don't show cursor
Ncurses.start_color
top_height = 2
w = Ncurses::WINDOW.new(20, 20, 10, 10)
3.times{ |i|
w.move(1 + i,1 + i)
w.addstr("#{i}Foo")
w.refresh
sleep 1
}
ensure
Ncurses.echo
Ncurses.nocbreak
Ncurses.nl
Ncurses.endwin
Ncurses.curs_set(1)
end
$ ./dwatch_stub.rb
/usr/lib/ruby/1.8/ncurses.rb:89:in `new': undefined method `newwin' for Ncurses:Module (NoMethodError)
from ./dwatch_stub.rb:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment