# New window screwing up my Ncurses script!

**URL:** <https://www.ruby-forum.com/t/new-window-screwing-up-my-ncurses-script/158945>\
**Category:** Ruby\
**Created:** [January 29, 2009, 5:29pm UTC](https://www.ruby-forum.com/t/new-window-screwing-up-my-ncurses-script/158945 "2009-01-29T17:29:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 29, 2009, 5:29pm UTC](https://www.ruby-forum.com/t/new-window-screwing-up-my-ncurses-script/158945/1 "2009-01-29T17:29:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 30, 2009, 6:12am UTC](https://www.ruby-forum.com/t/new-window-screwing-up-my-ncurses-script/158945/2 "2009-01-30T06:12:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 30, 2009, 7:02am UTC](https://www.ruby-forum.com/t/new-window-screwing-up-my-ncurses-script/158945/3 "2009-01-30T07:02:46Z")

</div>

(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!
