Improve window refresh
It's not perfect, sometimes the input buffer isn't printed properly
This commit is contained in:
parent
b1bcd6f75d
commit
bcec4fed68
3 changed files with 99 additions and 92 deletions
|
|
@ -258,6 +258,8 @@ bytenuts_set_status(int user, const char *fmt, ...)
|
||||||
int
|
int
|
||||||
bytenuts_update_screen_size()
|
bytenuts_update_screen_size()
|
||||||
{
|
{
|
||||||
|
char *old_status = strdup(bytenuts.bytenuts_status);
|
||||||
|
|
||||||
pthread_mutex_lock(&bytenuts.term_lock);
|
pthread_mutex_lock(&bytenuts.term_lock);
|
||||||
|
|
||||||
wresize(bytenuts.status_win, 1, COLS);
|
wresize(bytenuts.status_win, 1, COLS);
|
||||||
|
|
@ -274,7 +276,10 @@ bytenuts_update_screen_size()
|
||||||
|
|
||||||
pthread_mutex_unlock(&bytenuts.term_lock);
|
pthread_mutex_unlock(&bytenuts.term_lock);
|
||||||
|
|
||||||
|
ingest_refresh();
|
||||||
|
bytenuts_set_status(STATUS_BYTENUTS, old_status);
|
||||||
cheerios_insert("", 0);
|
cheerios_insert("", 0);
|
||||||
|
free(old_status);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
183
src/ingest.c
183
src/ingest.c
|
|
@ -20,7 +20,6 @@ static ingest_t ingest;
|
||||||
static int mode_normal(int ch);
|
static int mode_normal(int ch);
|
||||||
static int mode_xmodem(int block_sz);
|
static int mode_xmodem(int block_sz);
|
||||||
static int handle_functions(int ch);
|
static int handle_functions(int ch);
|
||||||
static int inbuf_load();
|
|
||||||
static int print_stats();
|
static int print_stats();
|
||||||
static int auto_complete();
|
static int auto_complete();
|
||||||
static int read_cmd_page(int idx);
|
static int read_cmd_page(int idx);
|
||||||
|
|
@ -80,6 +79,80 @@ ingest_stop()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ingest_refresh()
|
||||||
|
{
|
||||||
|
static int start = 0;
|
||||||
|
int startx = 0, starty = 0;
|
||||||
|
int cx = -1, cy = -1;
|
||||||
|
int win_len = getmaxx(ingest.input) + 1;
|
||||||
|
|
||||||
|
pthread_mutex_lock(ingest.term_lock);
|
||||||
|
|
||||||
|
werase(ingest.input);
|
||||||
|
wmove(ingest.input, 0, 0);
|
||||||
|
if (ingest.prepend) {
|
||||||
|
wprintw(ingest.input, "%s", ingest.prepend);
|
||||||
|
getyx(ingest.input, starty, startx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start > ingest.inpos) {
|
||||||
|
start = ingest.inpos;
|
||||||
|
}
|
||||||
|
/* this is not perfect as some characters are wider than one space, but it
|
||||||
|
* makes the algorithm for printing less redundant */
|
||||||
|
else if (ingest.inpos > (start + win_len)) {
|
||||||
|
start = ingest.inpos - win_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
int hit_cursor = 0;
|
||||||
|
while (1) {
|
||||||
|
int p = i + start;
|
||||||
|
int iy, ix;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
getyx(ingest.input, iy, ix);
|
||||||
|
|
||||||
|
/* print the cursor at this position */
|
||||||
|
if (p == ingest.inpos) {
|
||||||
|
cy = iy;
|
||||||
|
cx = ix;
|
||||||
|
hit_cursor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* nothing left to write... */
|
||||||
|
if (p >= ingest.inlen)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* we want to leave a blank character for printing the cursor at the end of the line */
|
||||||
|
if (ix >= (win_len-2)) {
|
||||||
|
/* we printed the cursor, so we can break */
|
||||||
|
if (hit_cursor)
|
||||||
|
break;
|
||||||
|
/* otherwise, we didn't print the cursor, so start over */
|
||||||
|
i = 0;
|
||||||
|
start++;
|
||||||
|
wmove(ingest.input, starty, startx);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
waddch(ingest.input, ingest.inbuf[p]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cx < 0) {
|
||||||
|
cx = ingest.inlen < win_len ? ingest.inlen : win_len - 1;
|
||||||
|
cy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wmove(ingest.input, cy, cx);
|
||||||
|
wrefresh(ingest.input);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(ingest.term_lock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ingest_set_history(char **history, int history_len)
|
ingest_set_history(char **history, int history_len)
|
||||||
{
|
{
|
||||||
|
|
@ -191,7 +264,7 @@ ingest_thread(void *arg)
|
||||||
memcpy(ingest.inbuf, toload, toload_len);
|
memcpy(ingest.inbuf, toload, toload_len);
|
||||||
ingest.inpos = toload_len;
|
ingest.inpos = toload_len;
|
||||||
ingest.inlen = toload_len;
|
ingest.inlen = toload_len;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'c':
|
case 'c':
|
||||||
|
|
@ -363,7 +436,7 @@ mode_normal(int ch)
|
||||||
memset(ingest.inbuf, 0, sizeof(ingest.inbuf));
|
memset(ingest.inbuf, 0, sizeof(ingest.inbuf));
|
||||||
ingest.inpos = 0;
|
ingest.inpos = 0;
|
||||||
ingest.inlen = 0;
|
ingest.inlen = 0;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case KEY_UP: /* load in history */
|
case KEY_UP: /* load in history */
|
||||||
|
|
@ -378,7 +451,7 @@ mode_normal(int ch)
|
||||||
strcpy(ingest.inbuf, ingest.history[ingest.history_pos]);
|
strcpy(ingest.inbuf, ingest.history[ingest.history_pos]);
|
||||||
ingest.inlen = strlen(ingest.inbuf);
|
ingest.inlen = strlen(ingest.inbuf);
|
||||||
ingest.inpos = ingest.inlen;
|
ingest.inpos = ingest.inlen;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN: /* load in history */
|
case KEY_DOWN: /* load in history */
|
||||||
|
|
@ -398,7 +471,7 @@ mode_normal(int ch)
|
||||||
ingest.inpos = ingest.inlen;
|
ingest.inpos = ingest.inlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -421,7 +494,7 @@ mode_normal(int ch)
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
}
|
}
|
||||||
|
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -442,7 +515,7 @@ mode_xmodem(int block_sz)
|
||||||
if (ingest.prepend)
|
if (ingest.prepend)
|
||||||
free(ingest.prepend);
|
free(ingest.prepend);
|
||||||
ingest.prepend = strdup("Give me a path (ctrl-c to stop): ");
|
ingest.prepend = strdup("Give me a path (ctrl-c to stop): ");
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
while (ingest.running) {
|
while (ingest.running) {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
@ -474,7 +547,7 @@ mode_xmodem(int block_sz)
|
||||||
break;
|
break;
|
||||||
case '\t': /* tab complete */
|
case '\t': /* tab complete */
|
||||||
auto_complete();
|
auto_complete();
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
@ -496,7 +569,7 @@ mode_xmodem(int block_sz)
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
}
|
}
|
||||||
|
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +585,7 @@ mode_xmodem(int block_sz)
|
||||||
ingest.prepend = NULL;
|
ingest.prepend = NULL;
|
||||||
|
|
||||||
bytenuts_set_status(STATUS_INGEST, "normal");
|
bytenuts_set_status(STATUS_INGEST, "normal");
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -557,7 +630,7 @@ handle_functions(int ch)
|
||||||
ingest.inpos--;
|
ingest.inpos--;
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
ingest.inbuf[ingest.inlen] = '\0';
|
ingest.inbuf[ingest.inlen] = '\0';
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -569,7 +642,7 @@ handle_functions(int ch)
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
memcpy(&ingest.inbuf[ingest.inpos], tmp, tmp_len);
|
memcpy(&ingest.inbuf[ingest.inpos], tmp, tmp_len);
|
||||||
ingest.inbuf[ingest.inlen] = '\0';
|
ingest.inbuf[ingest.inlen] = '\0';
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -583,7 +656,7 @@ handle_functions(int ch)
|
||||||
} else if (ingest.inpos == ingest.inlen - 1) {
|
} else if (ingest.inpos == ingest.inlen - 1) {
|
||||||
ingest.inbuf[ingest.inpos] = '\0';
|
ingest.inbuf[ingest.inpos] = '\0';
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -592,7 +665,7 @@ handle_functions(int ch)
|
||||||
ingest.inlen--;
|
ingest.inlen--;
|
||||||
memcpy(&ingest.inbuf[ingest.inpos], tmp, tmp_len);
|
memcpy(&ingest.inbuf[ingest.inpos], tmp, tmp_len);
|
||||||
ingest.inbuf[ingest.inlen] = '\0';
|
ingest.inbuf[ingest.inlen] = '\0';
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -600,21 +673,21 @@ handle_functions(int ch)
|
||||||
if (ingest.inpos == 0)
|
if (ingest.inpos == 0)
|
||||||
return 1;
|
return 1;
|
||||||
ingest.inpos--;
|
ingest.inpos--;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if (ingest.inpos == ingest.inlen)
|
if (ingest.inpos == ingest.inlen)
|
||||||
return 1;
|
return 1;
|
||||||
ingest.inpos++;
|
ingest.inpos++;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
case KEY_END:
|
case KEY_END:
|
||||||
ingest.inpos = ingest.inlen;
|
ingest.inpos = ingest.inlen;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
ingest.inpos = 0;
|
ingest.inpos = 0;
|
||||||
inbuf_load();
|
ingest_refresh();
|
||||||
return 1;
|
return 1;
|
||||||
#if 0
|
#if 0
|
||||||
case KEY_MOUSE:
|
case KEY_MOUSE:
|
||||||
|
|
@ -637,80 +710,6 @@ handle_functions(int ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
inbuf_load()
|
|
||||||
{
|
|
||||||
static int start = 0;
|
|
||||||
int startx = 0, starty = 0;
|
|
||||||
int cx = -1, cy = -1;
|
|
||||||
int win_len = getmaxx(ingest.input) + 1;
|
|
||||||
|
|
||||||
pthread_mutex_lock(ingest.term_lock);
|
|
||||||
|
|
||||||
werase(ingest.input);
|
|
||||||
wmove(ingest.input, 0, 0);
|
|
||||||
if (ingest.prepend) {
|
|
||||||
wprintw(ingest.input, "%s", ingest.prepend);
|
|
||||||
getyx(ingest.input, starty, startx);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start > ingest.inpos) {
|
|
||||||
start = ingest.inpos;
|
|
||||||
}
|
|
||||||
/* this is not perfect as some characters are wider than one space, but it
|
|
||||||
* makes the algorithm for printing less redundant */
|
|
||||||
else if (ingest.inpos > (start + win_len)) {
|
|
||||||
start = ingest.inpos - win_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int hit_cursor = 0;
|
|
||||||
while (1) {
|
|
||||||
int p = i + start;
|
|
||||||
int iy, ix;
|
|
||||||
i++;
|
|
||||||
|
|
||||||
getyx(ingest.input, iy, ix);
|
|
||||||
|
|
||||||
/* print the cursor at this position */
|
|
||||||
if (p == ingest.inpos) {
|
|
||||||
cy = iy;
|
|
||||||
cx = ix;
|
|
||||||
hit_cursor = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* nothing left to write... */
|
|
||||||
if (p >= ingest.inlen)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* we want to leave a blank character for printing the cursor at the end of the line */
|
|
||||||
if (ix >= (win_len-2)) {
|
|
||||||
/* we printed the cursor, so we can break */
|
|
||||||
if (hit_cursor)
|
|
||||||
break;
|
|
||||||
/* otherwise, we didn't print the cursor, so start over */
|
|
||||||
i = 0;
|
|
||||||
start++;
|
|
||||||
wmove(ingest.input, starty, startx);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
waddch(ingest.input, ingest.inbuf[p]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cx < 0) {
|
|
||||||
cx = ingest.inlen < win_len ? ingest.inlen : win_len - 1;
|
|
||||||
cy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
wmove(ingest.input, cy, cx);
|
|
||||||
wrefresh(ingest.input);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(ingest.term_lock);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
print_stats()
|
print_stats()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,9 @@ int ingest_start(bytenuts_t *bytenuts);
|
||||||
/* stop the input window thread */
|
/* stop the input window thread */
|
||||||
int ingest_stop();
|
int ingest_stop();
|
||||||
|
|
||||||
|
/* refresh the inbuf window */
|
||||||
|
int ingest_refresh();
|
||||||
|
|
||||||
/* Set the the command history directly. Values are copied */
|
/* Set the the command history directly. Values are copied */
|
||||||
int ingest_set_history(char **history, int history_len);
|
int ingest_set_history(char **history, int history_len);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue