Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scrolling windows up in curses

569 views
Skip to first unread message

Dr. Laurence Leff

unread,
Feb 3, 1995, 1:07:13 AM2/3/95
to
We would like to know how to scroll a window up in curses. We are in
Solaris 2.3

We found the scroll down command for a window--winsertln. That works fine.

We thought that curses didn't support scrolling the other way so we
wrote a loop to redraw the material. That worked but it is slow
and causes jerky motion of the screen.

We later found the wscrl(-1) facility but it doesn't seem to work.
Instead of scrolling the contents of the window, it moves the whole window
down on the screen.

Here is a test program. What are we doing wrong?

#include <curses.h>
main (){
WINDOW *z;
/* create new window */
/* initialize the window with initial data */
/* set current_line_on_screen
currrent_line_of_list */
/* do logic in program */
FILE *debug;
int z1;
debug=fopen("debug.out","w");
initscr();
z=newwin(5,80,0,0);
box(z,'|','_');
keypad(z,TRUE);
clear();
savetty();
raw();
nonl();
wmove(z,1,1);
wprintw(z,"abc");
wmove(z,2,2);
wprintw(z,"def");
wmove(z,3,3);
wprintw(z,"ghi");
noecho();
z1=wgetch(z);
scrollok(z,TRUE);
idlok(z,TRUE);
while ((z1 == KEY_UP) || (z1==KEY_DOWN)) {
z1=wgetch(z);
wscrl(z,-1);
}
fprintf(debug,"non arrow hit %x\n",z1);
fclose(debug);
printf("non arrow hit %x\n",z1);

endwin();
}

David Katleman

unread,
Feb 3, 1995, 11:40:32 PM2/3/95
to
Dr. Laurence Leff (mf...@uxa.ecn.bgu.edu) wrote:
: We found the scroll down command for a window--winsertln. That works fine.

: We thought that curses didn't support scrolling the other way so we
: wrote a loop to redraw the material. That worked but it is slow
: and causes jerky motion of the screen.

: We later found the wscrl(-1) facility but it doesn't seem to work.
: Instead of scrolling the contents of the window, it moves the whole window
: down on the screen.

: Here is a test program. What are we doing wrong?

Hum... wscrl() seems to work for both up and down. Where the confusion
might be is that "contents of the window" == "whole window". Just because
box() is used on a window doesn't mean that the box itself is not
part of the window's contents.

Hopefully I've understood you question and the modifications I've
made to your test program will clear things up.

#include <curses.h>
main (){
WINDOW *w,*z,*zz;


/* create new window */
/* initialize the window with initial data */
/* set current_line_on_screen
currrent_line_of_list */
/* do logic in program */
FILE *debug;

int i,z1;


debug=fopen("debug.out","w");
initscr();

zz=newwin(16,80,0,0);
z=subwin(zz,14,78,1,1);
w=newwin(5,80,16,0);
box(zz,'|','_');
box(w,'w','w');
wrefresh(w);
wrefresh(zz);


keypad(z,TRUE);
clear();
savetty();
raw();
nonl();

for (i=0;i< 14 ; i++) {
wmove(z,i,i);
wprintw(z,"abc");


}
noecho();
z1=wgetch(z);
scrollok(z,TRUE);
idlok(z,TRUE);
while ((z1 == KEY_UP) || (z1==KEY_DOWN)) {

if (z1 == KEY_UP) wscrl(z,-1);
if (z1 == KEY_DOWN) wscrl(z,1);
z1=wgetch(z);


}
fprintf(debug,"non arrow hit %x\n",z1);
fclose(debug);
printf("non arrow hit %x\n",z1);

endwin();
}

--
Dave Katleman (No opinions but my own need apply)
katl...@eng.sun.com

Michael Bresnahan

unread,
Feb 7, 1995, 12:53:32 PM2/7/95
to
In article <3gsh6h$m...@ecom2.ecn.bgu.edu>,

What platform are you using? I can't find wscrl() in SunOS 4.1.3 nor
HPUX 9.0 curses.

I use a pad when I want to do scrolling. Pads allow you to specify
what part of a window you want displayed. Scrolling can be done by
moving this "view window" up and down. Take this code for example:

foo() {

WINDOW *pad;
int y = 0;

pad = newpad( 1024, 80);
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
/* scroll up */
y--;
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
/* scroll down */
y++;
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
}

Hope this helps.

MikeB


Message has been deleted

Jenkins a.k.a. ['dzen:kinz]

unread,
Feb 12, 1995, 8:29:25 PM2/12/95
to
J$ the currently defined scrolling area and waddch(win, '\n'). Alternatively,
J$ you can scroll the whole window one line by calling scroll(win); but as
J$ scroll() is also an internal routine, it's somewhat risky. However, current
J$ SVR3.2 and SVR4 curses manpages document scroll(), so it is safer than
J$ wscrl(). (scroll() can do unexpected things with termcap-based curses, as
J$ it's not intended for this purpose; in termcap curses it's somewhat closer to
J$ terminfo curses' wscrl(), so it tends to do "unexpected" things to the
J$ physical screen.)

I use wscrl to scroll up and down too, but on machines that doesn't
support wscrl, I uses use the following macro to simulate wscrl,

#define wscrl(win,direction) \
{ \
if (direction) /* Move up */ \
scroll(win) \
else \
{ \
wmove(win,0,0); \
winsertln(win); \
} \
wrefresh(win); \
}
--
-['dzen:kinz]-
<Detail in URL=http://www.iscs.nus.sg/~chngsunp>

0 new messages