Permalink
Browse files

Add buffer scroll & resize management

  • Loading branch information...
xorg62 committed Feb 28, 2012
1 parent b298987 commit 7c572083384333f137e814a3beeae54465b28fdf
Showing with 81 additions and 6 deletions.
  1. +18 −0 src/hftirc.c
  2. +2 −2 src/hftirc.h
  3. +59 −4 src/ui.c
  4. +2 −0 src/ui.h
View
@@ -15,9 +15,27 @@
void
signal_handler(int signal)
{
+ int oc, ol, d;
+ (void)d;
+
switch(signal)
{
+ /* Terminal resize */
case SIGWINCH:
+ oc = COLS;
+ ol = LINES;
+
+ endwin();
+ refresh();
+ getmaxyx(stdscr, d, d);
+
+ ui_init();
+ ui_get_input();
+ ui_print_buf(STATUS_BUFFER,
+ "[HFTIrc] *** Terminal resized (%dx%d -> %dx%d)",
+ ol, oc, LINES, COLS);
+ ui_buffer_set(H.bufsel);
+
break;
}
}
View
@@ -7,7 +7,6 @@
#define HFTIRC_H
#define _XOPEN_SOURCE_EXTENDED 1
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -77,11 +76,12 @@ struct buffer_line
struct buffer
{
struct session *session;
+ struct buffer_line *scrollb;
int id;
#define ACT_NO 0
#define ACT_NORMAL 1
#define ACT_HL 2
- int act, nline;
+ int act, nline, nscroll;
char *name;
char *topic;
TAILQ_HEAD(blsub, buffer_line) lines;
View
@@ -20,9 +20,11 @@ ui_buffer_new(struct session *session, char *name)
b->session = session;
b->name = xstrdup(name);
b->topic = NULL;
+ b->scrollb = NULL;
b->act = ACT_NO;
b->id = (p ? p->id + 1 : 0);
b->nline = 0;
+ b->nscroll = 0;
TAILQ_INIT(&b->lines);
SLIST_INIT(&b->nicks);
@@ -163,7 +165,7 @@ ui_update(void)
static void
ui_print_line(struct buffer_line *bl)
{
- waddstr(H.ui.mainwin, bl->line);
+ mvwaddstr(H.ui.mainwin, MAINWIN_LINES - 1, 0, bl->line);
}
static void
@@ -173,8 +175,18 @@ ui_update_buf(void)
werase(H.ui.mainwin);
- TAILQ_FOREACH(b, &H.bufsel->lines, next)
- ui_print_line(b);
+ if(H.bufsel->nscroll)
+ {
+ TAILQ_FOREACH(b, &H.bufsel->lines, next)
+ {
+ if(b == H.bufsel->scrollb)
+ break;
+ ui_print_line(b);
+ }
+ }
+ else
+ TAILQ_FOREACH(b, &H.bufsel->lines, next)
+ ui_print_line(b);
wrefresh(H.ui.mainwin);
}
@@ -218,7 +230,7 @@ ui_print_buf(struct buffer *b, char *fmt, ...)
bl = ui_buffer_line_new(b, fstr);
- if(b == H.bufsel)
+ if(b == H.bufsel && !b->nscroll)
{
ui_print_line(bl);
wrefresh(H.ui.mainwin);
@@ -240,6 +252,38 @@ ui_buffer_set(struct buffer *b)
ui_update_buf();
}
+void
+ui_buffer_scroll(struct buffer *b, int n)
+{
+ struct buffer_line *bl;
+ int i = 0;
+
+ b->nscroll += n;
+
+ if(b->nscroll <= 0)
+ {
+ b->nscroll = 0;
+ b->scrollb = NULL;
+ }
+
+ /* Save pointer of the buffer line limit in list */
+ TAILQ_FOREACH_REVERSE(bl, &b->lines, blsub, next)
+ {
+ if(i == b->nscroll)
+ {
+ b->scrollb = bl;
+ break;
+ }
+ ++i;
+ }
+
+ if(!bl)
+ b->nscroll -= n;
+
+ if(b == H.bufsel)
+ ui_update_buf();
+}
+
void
ui_get_input(void)
{
@@ -271,6 +315,14 @@ ui_get_input(void)
ui_buffer_set(bf);
break;
+ case KEY_PPAGE:
+ ui_buffer_scroll(H.bufsel, (MAINWIN_LINES >> 1));
+ break;
+
+ case KEY_NPAGE:
+ ui_buffer_scroll(H.bufsel, -(MAINWIN_LINES >> 1));
+ break;
+
case KEY_HOME:
wmove(H.ui.inputwin, 0, 0);
ib->pos = ib->cpos = 0;
@@ -472,6 +524,9 @@ ui_get_input(void)
}
break;
+ case KEY_RESIZE:
+ break;
+
default:
if(ib->buffer[ib->pos] != '\0')
for(i = (int)wcslen(ib->buffer);
View
@@ -19,6 +19,7 @@
#define NICKLIST_SIZE 20
#define MAINWIN_LINES (LINES - 2)
+#define STATUS_BUFFER TAILQ_FIRST(&H.h.buffer)
/* Test control-bind */
#define IS_CTRLK(c) (c > 0 && c < 32)
@@ -36,6 +37,7 @@ void ui_get_input(void);
void ui_update(void);
void ui_print_buf(struct buffer *b, char *fmt, ...);
void ui_buffer_set(struct buffer *b);
+void ui_buffer_scroll(struct buffer *b, int n);
static inline struct buffer*
ui_buffer_gb_id(int n)

0 comments on commit 7c57208

Please sign in to comment.