mirror of
git://git.code.sf.net/p/zsh/code
synced 2026-01-06 09:41:07 +01:00
24018: add zcurses scroll
This commit is contained in:
parent
7489d51823
commit
9fc8fe1785
3 changed files with 64 additions and 1 deletions
|
|
@ -1,5 +1,8 @@
|
|||
2007-10-24 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* 24018: Doc/Zsh/mod_curses.yo, Src/Modules/curses.c:
|
||||
add "zcurses scroll".
|
||||
|
||||
* 24017: Doc/Zsh/mod_curses.yo, Src/Modules/curses.c:
|
||||
fold color support into attr subcommand and improve error
|
||||
handling; add various readonly parameters; replace strtok();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ xitem(tt(zcurses) tt(move) var(targetwin) var(new_y) var(new_x) )
|
|||
xitem(tt(zcurses) tt(char) var(targetwin) var(character) )
|
||||
xitem(tt(zcurses) tt(string) var(targetwin) var(string) )
|
||||
xitem(tt(zcurses) tt(border) var(targetwin) var(border) )(
|
||||
item(tt(zcurses) tt(attr) var(targetwin) [ var({+/-}attribute) | var(fg_col)tt(/)var(bg_col) ] [...])(
|
||||
xitem(tt(zcurses) tt(attr) var(targetwin) [ var({+/-}attribute) | var(fg_col)tt(/)var(bg_col) ] [...])
|
||||
item(tt(zcurses) tt(scroll) [ tt(on) | tt(off) | {+/-}var(lines) ])(
|
||||
Manipulate curses windows. All uses of this command should be
|
||||
bracketed by `tt(zcurses init)' to initialise use of curses, and
|
||||
`tt(zcurses end)' to end it; omitting `tt(zcurses end)' can cause
|
||||
|
|
@ -53,6 +54,15 @@ supported are tt(blink), tt(bold), tt(dim), tt(reverse), tt(standout),
|
|||
and tt(underline). Each var(fg_col)tt(/)var(bg_col) (to be read as
|
||||
`var(fg_col) on var(bg_col)') sets the foreground and background color
|
||||
for character output.
|
||||
|
||||
tt(scroll) can be used with tt(on) or tt(off) to enabled or disable
|
||||
scrolling of a window when the cursor would otherwise move below the
|
||||
window due to typing or output. It can also be used with a positive
|
||||
or negative integer to scroll the window up or down the given number
|
||||
of lines without changing the current cursor position (which therefore
|
||||
appears to move in the opposite direction relative to the window).
|
||||
In the second case, if scrolling is tt(off) it is temporarily turned tt(on)
|
||||
to allow the window to be scrolled,
|
||||
)
|
||||
enditem()
|
||||
|
||||
|
|
|
|||
|
|
@ -51,9 +51,15 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
enum zc_win_flags {
|
||||
/* Scrolling enabled */
|
||||
ZCWF_SCROLL = 0x0001
|
||||
};
|
||||
|
||||
typedef struct zc_win {
|
||||
WINDOW *win;
|
||||
char *name;
|
||||
int flags;
|
||||
} *ZCWin;
|
||||
|
||||
struct zcurses_namenumberpair {
|
||||
|
|
@ -620,6 +626,49 @@ zccmd_attr(const char *nam, char **args)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
zccmd_scroll(const char *nam, char **args)
|
||||
{
|
||||
LinkNode node;
|
||||
ZCWin w;
|
||||
int ret = 0;
|
||||
|
||||
node = zcurses_validate_window(args[0], ZCURSES_USED);
|
||||
if (node == NULL) {
|
||||
zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
w = (ZCWin)getdata(node);
|
||||
|
||||
if (!strcmp(args[1], "on")) {
|
||||
if (scrollok(w->win, TRUE) == ERR)
|
||||
return 1;
|
||||
w->flags |= ZCWF_SCROLL;
|
||||
} else if (!strcmp(args[1], "off")) {
|
||||
if (scrollok(w->win, FALSE) == ERR)
|
||||
return 1;
|
||||
w->flags &= ~ZCWF_SCROLL;
|
||||
} else {
|
||||
char *endptr;
|
||||
zlong sl = zstrtol(args[1], &endptr, 10);
|
||||
if (*endptr) {
|
||||
zwarnnam(nam, "scroll requires `on', `off' or integer: %s",
|
||||
args[1]);
|
||||
return 1;
|
||||
}
|
||||
if (!(w->flags & ZCWF_SCROLL))
|
||||
scrollok(w->win, TRUE);
|
||||
if (wscrl(w->win, (int)sl) == ERR)
|
||||
ret = 1;
|
||||
if (!(w->flags & ZCWF_SCROLL))
|
||||
scrollok(w->win, FALSE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*********************
|
||||
Main builtin handler
|
||||
*********************/
|
||||
|
|
@ -643,6 +692,7 @@ bin_zcurses(char *nam, char **args, Options ops, UNUSED(int func))
|
|||
{"border", zccmd_border, 1, 1},
|
||||
{"end", zccmd_endwin, 0, 0},
|
||||
{"attr", zccmd_attr, 2, -1},
|
||||
{"scroll", zccmd_scroll, 2, 2},
|
||||
{NULL, (zccmd_t)0, 0, 0}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue