scrollable window ncurses ruby -
i created class trying make simulate richtextbox, sort of, on windows forms. means when add new data form/richtextbox added bottom of box/window , rest scrolled 1 line.
ive tried enable scrollok()
, not seem want scroll. not sure if it's bugged or way of implementing wrong.
class textpad attr_accessor :data, :name, :window def initialize(name, height, width, startx, starty) @data = [] @name = name @height = height @width = width @startx = startx @starty = starty ncurses.refresh @window = ncurses.newwin(height, width, starty, startx) @window.scrollok true @window.wrefresh end def add(packetid, username, message) @data.push [time.new.strftime('[%t]'), packetid, username, message] @data.shift if @data.length > 500 end def draw ncurses.init_pair(1, ncurses::color_yellow, ncurses::color_black) ncurses.init_pair(2, ncurses::color_cyan, ncurses::color_black) ncurses.init_pair(3, ncurses::color_red, ncurses::color_black) ncurses.init_pair(4, ncurses::color_white, ncurses::color_black) @window.wclear position = 0 @data.each |timestamp, packetid, username, message| case packetid when '1005' @window.mvwprintw(1*position, 1, "#{timestamp} «#{username}» #{message}") @window.mvchgat(1*position, timestamp.length+2, 1, ncurses::a_normal, 3, nil) @window.mvchgat(1*position, timestamp.length+3+username.length, 1, ncurses::a_normal, 3, nil) #colorize symboles around username end position += 1 end @window.wrefresh end end
the problem inside draw method of textpad class. can fill data array textpad class hundreds of entries top of array gets written (until reaches bottom of window) no scrolling. manually have scroll screen or something? documentation says should automatically scroll when cursor reaches bottom , line added.
to quote man page:
the scrollok option controls happens when cursor of window moved off edge of window or scrolling region, either result of newline action on bottom line, or typing last character of last line. if disabled, (bf false), cursor left on bottom line. if enabled, (bf true), window scrolled 1 line...
what happening in code attempting print outside window error, error curses handles not printing anything.
you can either print new line when bottom of window or once reach bottom of window can call @window.scroll.
either way need keep printing on last line if explicitly setting position.
Comments
Post a Comment