views:

17

answers:

0

I have following code to try and alter the default Ruby Ncurses behavior:

#!/usr/bin/env ruby
require 'logger'
require 'rubygems'
require 'ncurses'

class Ncurses::WINDOW
   def initialize( height, width, starty, startx )
      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

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

However when I run this, my overridden "initialize" does not seem to be used, though my overridden "move" does (nonexistent /tmp/initialize.log and missing "first psot" text, whereas /tmp/move.log does exist). Is it possible to override the Ncurses::WINDOW initialize, and if so what am I doing wrong here?