Commits

Robert Lowry committed 3259283

got up/down/home/end scrolling

Comments (0)

Files changed (1)

 Watch *watch = NULL;
 Watch *curwatch = NULL;
 Watch *lastwatch = NULL;
+Line *curline = NULL;
 int rows,cols;
 int updatescreen = 1;
 int updateinput = 1;
 
 	while(read_line(w->infd,buf,sizeof(buf)) != -1) {
 		l = add_line(w->lastline,buf);
+		if(!w->lines) w->lines = l;
 		w->lastline = l;
+		if(curwatch == w)
+			curline = w->lastline;
 	}
 	if (w == curwatch)
 		updatescreen = 1;
 	int size;
 
 	offset = rows - 2;
-	for(cur = curwatch->lastline; cur; cur = cur->prev) {
+	for(cur = curline; cur; cur = cur->prev) {
 		len = strlen(cur->text);
 		size = (len / cols) + (len % cols ? 1 : 0);
 		offset -= size;
-		mvprintw(offset,0,"%s",cur->text);
+		if(offset >= 0) {
+			mvprintw(offset,0,"%s",cur->text);
+		} else {
+			break;
+		}
 	}
 }
 
 			break;
 		case KEY_CONTROL_N:
 			curwatch = next_active(curwatch);
+			curline = curwatch->lastline;
 			updatescreen = 1;
 			break;
 		case KEY_CONTROL_P:
 			curwatch = prev_active(curwatch);
+			curline = curwatch->lastline;
 			updatescreen = 1;
 			break;
 		case KEY_CONTROL_K:
 			curwatch = (curwatch->next? curwatch->next : watch);
 			updatescreen = 1;
 			break;
+		case KEY_UP:
+			if(curline->prev) curline = curline->prev;
+			updatescreen = 1;
+			break;
+		case KEY_DOWN:
+			if(curline->next) curline = curline->next;
+			updatescreen = 1;
+			break;
+		case KEY_HOME:
+			curline = curwatch->lines;
+			updatescreen = 1;
+			break;
+		case KEY_END:
+			curline = curwatch->lastline;
+			updatescreen = 1;
+			break;
 		case '\n':
 			write_input();
 			break;
 	init_ncurses();
 	ftw(dir, ADD_DIR, MAX_OPENFD);
 	curwatch = next_active(watch);
+	curline = curwatch->lastline;
 	for (;;) {
 		CHECK_WATCHES(dir, WATCH_TIMEOUT);
 		draw_screen();