zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: scrolling
@ 2007-10-24 22:19 Peter Stephenson
  2007-10-24 22:50 ` Clint Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2007-10-24 22:19 UTC (permalink / raw)
  To: Zsh hackers list

This adds scrolling of windows to zcurses.

However, I wouldn't like anybody think I'm a complete geek who spends
all his time fiddling with software.

Index: Doc/Zsh/mod_curses.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_curses.yo,v
retrieving revision 1.9
diff -u -r1.9 mod_curses.yo
--- Doc/Zsh/mod_curses.yo	24 Oct 2007 21:53:48 -0000	1.9
+++ Doc/Zsh/mod_curses.yo	24 Oct 2007 22:19:29 -0000
@@ -18,7 +18,8 @@
 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 @@
 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()
 
Index: Src/Modules/curses.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v
retrieving revision 1.21
diff -u -r1.21 curses.c
--- Src/Modules/curses.c	24 Oct 2007 21:53:49 -0000	1.21
+++ Src/Modules/curses.c	24 Oct 2007 22:19:29 -0000
@@ -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 @@
 }
 
 
+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 @@
 	{"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}
     };
 

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: scrolling
  2007-10-24 22:19 PATCH: scrolling Peter Stephenson
@ 2007-10-24 22:50 ` Clint Adams
  2007-10-25  9:02   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Clint Adams @ 2007-10-24 22:50 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, Oct 24, 2007 at 11:19:31PM +0100, Peter Stephenson wrote:
> This adds scrolling of windows to zcurses.

Hmm, this test script doesn't do quite what I expected in the second half.

zmodload curses
{
zcurses init
zcurses addwin tw $(( LINES - 15 )) $(( COLUMNS - 20 )) 5 10
zcurses border tw
zcurses move tw 1 1
zcurses char tw B
zcurses char tw l
zcurses char tw a
zcurses char tw h
zcurses move tw 2 2
zcurses string tw String
zcurses move tw 3 3
zcurses attr tw bold underline
zcurses string tw BoLD
zcurses move tw 4 4
zcurses attr tw -bold -underline green/black
zcurses string tw Green
zcurses refresh tw
zcurses addwin bw 5 $(( COLUMNS - 20 )) $(( LINES - 10 )) 10
zcurses border bw
zcurses refresh bw
sleep 1
zcurses scroll tw -1
zcurses refresh tw
sleep 1
zcurses scroll tw -1
zcurses refresh tw
sleep 1
zcurses scroll tw 1
zcurses refresh tw
sleep 1
zcurses scroll tw 1
zcurses refresh tw
sleep 1
zcurses refresh
sleep 1
zcurses refresh tw
zcurses refresh bw
sleep 5
zcurses delwin tw
zcurses delwin bw
} always {
zcurses end
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: scrolling
  2007-10-24 22:50 ` Clint Adams
@ 2007-10-25  9:02   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2007-10-25  9:02 UTC (permalink / raw)
  To: Zsh hackers list

On Wed, 24 Oct 2007 18:50:08 -0400
Clint Adams <clint@zsh.org> wrote:
> On Wed, Oct 24, 2007 at 11:19:31PM +0100, Peter Stephenson wrote:
> > This adds scrolling of windows to zcurses.
> 
> Hmm, this test script doesn't do quite what I expected in the second half.

Do you mean the border disappears and doesn't come back?
Yes, scrolling seems to have slightly odd effects like that.  I think you
just have to redraw the border.

pws



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-25  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-24 22:19 PATCH: scrolling Peter Stephenson
2007-10-24 22:50 ` Clint Adams
2007-10-25  9:02   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).