# Ncurses: problem with Colors & removing existent windows

**URL:** <https://www.ruby-forum.com/t/ncurses-problem-with-colors-removing-existent-windows/146099>\
**Category:** Ruby\
**Created:** [August 17, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/ncurses-problem-with-colors-removing-existent-windows/146099 "2008-08-17T21:25:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabian\_Holler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ce7236/32.png) [@Fabian\_Holler](https://www.ruby-forum.com/u/Fabian_Holler)\
**Post date:** [August 17, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/ncurses-problem-with-colors-removing-existent-windows/146099/1 "2008-08-17T21:25:33Z")

</div>

Hello,

I’m trying to write a little Linux Console application with Ncurses. To  
have an easier Window interface for my purposes I created an Window  
class.

1. How i can delete an existing windows + its content from the screen?  
AFAIK it should work with clear(), but doesn’t work, the window+content  
is still on the screen

2. I don’t get it work to have colored windows/text 😕  
Whats wrong in my class?

#I initialize ncurses with:  
@scr = Ncurses.initscr() #init ncurses mode  
Ncurses.raw()  
Ncurses.noecho  
Ncurses.cbreak  
Ncurses.stdscr.keypad(true) ’  
Ncurses.start\_color()  
Ncurses.refresh

* * *

class Window

include Ncurses  
attr\_reader :height, :width  
def initialize(title, height, width, x, y)  
@title=title  
@height=height  
@width=width  
@x=x  
@y=y  
@win = Ncurses::WINDOW.new(height,width,x,y)  
refresh  
#Ncurses.init\_pair(0, Ncurses::COLOR\_RED, Ncurses::COLOR\_GREEN);  
end  
def refresh  
@win.box(0,0)  
@win.mvaddstr(0, 1, " #{@title} ")  
@win.refresh  
end  
def clear  
@win.clear  
end  
def addtxt(txt)  
return if txt[0].nil?  
y=0  
#COLORS Test  
Ncurses.start\_color()  
Ncurses.init\_pair(0, Ncurses::COLOR\_RED, Ncurses::COLOR\_GREEN);  
@win.color\_set(Ncurses::COLOR\_PAIR(0),nil)  
@win.attron(Ncurses::COLOR\_PAIR(0))  
Ncurses::attron(Ncurses::COLOR\_PAIR(0))  
#/COLORS Test

```
   txt.each do |i|
     if i[1] == :Bold
       @win.attrset Ncurses::A_BOLD
     else
       @win.attrset Ncurses::A_NORMAL
     end
       Ncurses::mvwprintw @win, y+=1, 1, i[0].to_s.chomp()
      end
 refresh

```

## end def delete @win.delete end end

many thanks and best regards

Fabian
