#include <stdlib.h>
+#include <curses.h>
#include "zalloc.h"
#include "error.h"
return b;
}
+struct te_char *nth_char(struct te_char *c, int n)
+{
+ if (c == NULL)
+ return;
+
+ struct te_char *r = c;
+ int i = 0;
+
+ for(i = 0; r != NULL && i < n; i++)
+ r = TAILQ_NEXT(c, chars);
+
+ statusprintf("r is %x, r->contents are : %c", r, r->contents);
+
+ return r;
+}
+
void free_char(struct te_buffer *b, struct te_char *c)
{
if (b == NULL || c == NULL)
}
statusprintf("%s", filename);
+
+ b->point = TAILQ_FIRST(&b->chars_head);
+ b->scr_top = b->point;
+ b->scr_bottom = nth_char(b->point, (LINES - 3) * COLS);
+
return b;
}
void scroll_down(struct te_buffer *buf)
{
+ if (buf == NULL || buf->point == NULL)
+ return;
+ struct te_char *c = buf->point;
+
+
}
void move_left(struct te_buffer *buf)
char *name;
int dirty;
int x, y;
+
struct te_char *point;
+ struct te_char *scr_top, *scr_bottom; /* the first and last char of the screen */
+
TAILQ_HEAD(te_chars_head, te_char) chars_head;
TAILQ_ENTRY(te_buffer) buffers;
};
struct te_char *alloc_and_insert_char(struct te_buffer *buf, char contents);
struct te_buffer *alloc_and_insert_buffer(void);
+struct te_char *nth_char(struct te_char *c, int n);
void free_char(struct te_buffer *b, struct te_char *c);
void free_buffer(struct te_buffer *b);
struct te_buffer* load_buffer(char *filename);
switch(c) {
case 'q':
exit(0);
+
+ case 'k':
+ screen_move_down(current_buf);
+ break;
}
}
#define __KEYB_H__
#include <stdlib.h>
+#include "buffer.h"
+#include "screen.h"
void input_loop(void);
+struct te_buffer *current_buf;
+
#endif
#include <stdio.h>
#include <curses.h>
+#include "screen.h"
+extern struct te_buffer *current_buf;
int main(int argc, char **argv)
{
init_buffers();
init_windows();
- struct te_buffer *b = load_buffer("screen.c");
- paint_buffer(b);
- miniprintf("Over the top!");
-
-
-
+ current_buf = load_buffer("screen.c");
+ paint_buffer(current_buf);
+ refresh();
input_loop();
}
initscr();
cbreak();
noecho();
- scrollok(stdscr, TRUE);
keypad(stdscr, TRUE);
buffer_win = subwin(stdscr, LINES - 2, COLS, 0, 0);
+ idlok(stdscr, TRUE);
+ scrollok(buffer_win, FALSE);
status_win = subwin(stdscr, 1, COLS, LINES - 2, 0);
wattron(status_win, A_REVERSE);
if (buf == NULL)
return;
+ wmove(buffer_win, 0, 0);
+
struct te_char *c;
- int y, x;
+ int i = 0;
- TAILQ_FOREACH(c, &buf->chars_head, chars) {
- getyx(stdscr, y, x);
- if (y >= LINES -2)
+ for(c = buf->scr_top; c != buf->scr_bottom; c = TAILQ_NEXT(c, chars)) {
+ if (++i > (LINES - 3) * COLS)
break;
-
- waddch(buffer_win, c->contents);
+ else
+ waddch(buffer_win, c->contents);
}
-
+ miniprintf("%d", i);
+ wmove(buffer_win, 0, 0);
refresh();
}
-void screen_move_left(void)
+void screen_move_left(struct te_buffer *buf)
{
}
-void screen_move_right(void)
+void screen_move_right(struct te_buffer *buf)
{
}
-void screen_move_up(void)
+void screen_move_up(struct te_buffer *buf)
{
+ if (buf == NULL)
+ return;
+ if (buf->scr_top == NULL || buf->scr_bottom == NULL)
+ fail("FATAL: buf->scr_top or buf->scr_bottom is NULL\n");
+
+ scrollok(buffer_win, TRUE);
+ wscrl(buffer_win, -1);
+
+ wmove(buffer_win, LINES - 3, 0);
+ struct te_char *c = buf->scr_bottom;
+
+ for (c = buf->scr_bottom; c != NULL && c->contents != '\n'; c = TAILQ_NEXT(c, chars))
+ addch(c->contents);
+
+ buf->scr_bottom = c;
+
+ /* Update scr_top accordingly */
+ c = buf->scr_top;
+ for (c = buf->scr_top; c != NULL && c->contents != '\n'; c = TAILQ_NEXT(c, chars))
+ continue;
+
+ buf->scr_top = c;
+
+ scrollok(buffer_win, FALSE);
+
+ wrefresh(buffer_win);
}
-void screen_move_down(void)
+void screen_move_down(struct te_buffer *buf)
{
-
+ scroll(buffer_win);
+ wrefresh(buffer_win);
}
void statusprintf(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
+ werase(minibuffer_win);
vwprintw(minibuffer_win, fmt, ap);
va_end(ap);
void cleanup_windows(void);
void paint_buffer(struct te_buffer *buf);
-void screen_move_left(void);
-void screen_move_right(void);
-void screen_move_up(void);
-void screen_move_down(void);
+void screen_move_left(struct te_buffer *buf);
+void screen_move_right(struct te_buffer *buf);
+void screen_move_up(struct te_buffer *buf);
+void screen_move_down(struct te_buffer *buf);
void statusprintf(char *fmt, ...);
void miniprintf(char *fmt, ...);