New window screwing up my Ncurses script!


#1

require ‘rubygems’
require ‘ncurses’

Ncurses.initscr
height = Ncurses.LINES() - 3
width = Ncurses.COLS()

outputwin = Ncurses.WINDOW.new(height, width, 0, 0)

failure = “-” * Ncurses.COLS()

Ncurses.mvprintw(22, 0, failure)
Ncurses.refresh

test = “”
Ncurses.mvwgetstr(Ncurses.stdscr, Ncurses.LINES() - 1, 0, test)

outputwin.addstr(test)
outputwin.refresh

sleep 1
Ncurses.endwin

Thats the code. If I comment out the first initialization of
‘outputwin’, the code runs fine up to the point where it gives me a name
error over outputwin.addstr, which is expected. But if I uncomment it, I
don’t get any errors, but some weird actions. When I run the ruby
script, it clears the screen, displays my terminal prompt again, and
text typed doesn’t show up (like the Ncurses mode didn’t end correctly).
Does anyone know whats wrong with my outputwin?


#2

Tim M. wrote:

Ncurses.initscr
height = Ncurses.LINES() - 3
width = Ncurses.COLS()

outputwin = Ncurses.WINDOW.new(height, width, 0, 0)

If you would follow the examples provided, you would be able to complete
your programs with minimal hassles.

It is Ncurses::WINDOW.new

Also, avoid writing to windows and to stdscr at the same time (i.e.
mixing). If you create a window, then write only to windows. That way
when you remove the window, whatever was on it will also get cleared
off.


#3

(RK) Sentinel wrote:

Tim M. wrote:

Ncurses.initscr
height = Ncurses.LINES() - 3
width = Ncurses.COLS()

outputwin = Ncurses.WINDOW.new(height, width, 0, 0)

If you would follow the examples provided, you would be able to complete
your programs with minimal hassles.

It is Ncurses::WINDOW.new

Also, avoid writing to windows and to stdscr at the same time (i.e.
mixing). If you create a window, then write only to windows. That way
when you remove the window, whatever was on it will also get cleared
off.

I thought using :: and . were interchangeable? Guess not. I had been
using .WINDOW.new before, and it worked fine. But it works now thanks!