better but not ready
This commit is contained in:
parent
f61e1776ab
commit
76a3f2c503
@ -13,6 +13,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -33,12 +34,16 @@
|
|||||||
#define C_A 1 /* BOL */
|
#define C_A 1 /* BOL */
|
||||||
#define C_B 2 /* BOL */
|
#define C_B 2 /* BOL */
|
||||||
#define C_E 5 /* EOL */
|
#define C_E 5 /* EOL */
|
||||||
#define C_U 21 /* CLR TO BOL */
|
|
||||||
#define C_H 8 /* BACKSPACE */
|
#define C_H 8 /* BACKSPACE */
|
||||||
|
#define C_L 12 /* REFRESH */
|
||||||
|
#define C_U 21 /* CLR TO BOL */
|
||||||
#define C_W 23 /* DELETE PREVWORD */
|
#define C_W 23 /* DELETE PREVWORD */
|
||||||
#define C_L 12 /* Signal SIGWINCH */
|
#define C_L 12 /* Signal SIGWINCH */
|
||||||
#define C_R 18 /* hah not going to implement that */
|
#define C_R 18 /* hah not going to implement that */
|
||||||
|
|
||||||
|
#define C_T 20 /* scroll up */
|
||||||
|
#define C_N 14 /* scroll down */
|
||||||
|
|
||||||
#define UP 258
|
#define UP 258
|
||||||
#define DOWN 259
|
#define DOWN 259
|
||||||
#define LEFT 260
|
#define LEFT 260
|
||||||
@ -64,8 +69,8 @@ void fillline(int y, int xstart, char c) {
|
|||||||
|
|
||||||
#define TITLE(str) do { mvprintw(0,0,str); fillline(0,strlen(str),'-'); } while (0)
|
#define TITLE(str) do { mvprintw(0,0,str); fillline(0,strlen(str),'-'); } while (0)
|
||||||
|
|
||||||
void hardrefresh(void) {
|
void decoration(void) {
|
||||||
mvprintw(g_y - 2, 0, "max screen %d; max ours %d", (g_y - 3) * SENDMAX, RECVMAX);
|
/* mvprintw(g_y - 2, 0, "max screen %d; max ours %d", (g_y - 3) * SENDMAX, RECVMAX); */
|
||||||
TITLE("-- MOONTALK ");
|
TITLE("-- MOONTALK ");
|
||||||
fillline(g_y - 3, 0, '-');
|
fillline(g_y - 3, 0, '-');
|
||||||
}
|
}
|
||||||
@ -90,7 +95,7 @@ void init_screen(int x) {
|
|||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
ESCDELAY = 0;
|
ESCDELAY = 0;
|
||||||
clear();
|
clear();
|
||||||
hardrefresh();
|
decoration();
|
||||||
g_hardrefresh = 1;
|
g_hardrefresh = 1;
|
||||||
|
|
||||||
signal(SIGWINCH, init_screen);
|
signal(SIGWINCH, init_screen);
|
||||||
@ -99,7 +104,7 @@ void init_screen(int x) {
|
|||||||
void stop(void) {
|
void stop(void) {
|
||||||
int sockfd = g_sockfd;
|
int sockfd = g_sockfd;
|
||||||
endwin();
|
endwin();
|
||||||
printf("stopping now. maybe you forgot torify?\n");
|
printf("stopping now.\n");
|
||||||
if (sockfd > -1) { close(sockfd); }
|
if (sockfd > -1) { close(sockfd); }
|
||||||
g_sockfd = -1;
|
g_sockfd = -1;
|
||||||
}
|
}
|
||||||
@ -167,15 +172,14 @@ size_t lastline(char * buf, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clearline(int y) {
|
void clearline(int y) {
|
||||||
int x = g_x;
|
|
||||||
int oldy, oldx;
|
int oldy, oldx;
|
||||||
getyx(stdscr, oldy, oldx);
|
getyx(stdscr, oldy, oldx);
|
||||||
move(y, x);
|
move(y, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
move(oldy, oldx);
|
move(oldy, oldx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UPDATE_TIME() do { \
|
#define UPDATE_TIME() do { \
|
||||||
t = time(NULL); \
|
t = time(NULL); \
|
||||||
tm = gmtime(&t); \
|
tm = gmtime(&t); \
|
||||||
strftime(sendbuf, TIMESTRMAX, TIMESTR, tm); \
|
strftime(sendbuf, TIMESTRMAX, TIMESTR, tm); \
|
||||||
@ -222,21 +226,21 @@ int main (int argc, char ** argv) {
|
|||||||
sockfd = init_connection(serv, port);
|
sockfd = init_connection(serv, port);
|
||||||
|
|
||||||
char raw[SENDMAX + RECVMAX];
|
char raw[SENDMAX + RECVMAX];
|
||||||
char * sendbuf = raw, * recvbuf = raw + SENDMAX;
|
char * sendbuf = raw, * recvbuf = raw + SENDMAX, * off = recvbuf;
|
||||||
size_t sendminlen;
|
size_t sendminlen;
|
||||||
size_t sendlen = sendminlen, recvlen = 1;
|
size_t sendlen = sendminlen, recvlen = 1, offlen = (g_y - 4) * 255;
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm * tm;
|
struct tm * tm;
|
||||||
useconds_t frame = 25;
|
useconds_t frame = 30;
|
||||||
useconds_t interval = 1000000 / frame;
|
useconds_t interval = 1000000 / frame;
|
||||||
int32_t ct = 0;
|
int32_t ct = 0;
|
||||||
int lc, off;
|
/* int lc, off; */
|
||||||
|
int hardrefresh = 0, inputrefresh = 1;
|
||||||
int ch;
|
int ch;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
sendminlen = TIMESTRMAX;
|
sendminlen = TIMESTRMAX;
|
||||||
UPDATE_TIME();
|
|
||||||
|
|
||||||
memcpy(sendbuf + sendminlen, name, strlen(name));
|
memcpy(sendbuf + sendminlen, name, strlen(name));
|
||||||
sendminlen += strlen(name);
|
sendminlen += strlen(name);
|
||||||
@ -244,56 +248,102 @@ int main (int argc, char ** argv) {
|
|||||||
sendminlen += 2;
|
sendminlen += 2;
|
||||||
sendlen = sendminlen;
|
sendlen = sendminlen;
|
||||||
|
|
||||||
hardrefresh();
|
decoration();
|
||||||
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
nextloop:
|
||||||
|
hardrefresh |= g_hardrefresh;
|
||||||
/* update */
|
/* update */
|
||||||
if (ct % (frame) == 0) {
|
if (ct % (frame) == 0 || inputrefresh) {
|
||||||
UPDATE_TIME();
|
UPDATE_TIME();
|
||||||
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
||||||
}
|
}
|
||||||
|
/* recv */
|
||||||
if (ct % (frame * 2) == 0) {
|
if (ct % (frame * 2) == 0) {
|
||||||
ret = recv(sockfd, recvbuf + recvlen, RECVMAX - recvlen, MSG_DONTWAIT);
|
ret = recv(sockfd, recvbuf + recvlen - 1, RECVMAX - recvlen + 1, MSG_DONTWAIT);
|
||||||
if (ret > 0 || g_hardrefresh) {
|
mvprintw(g_y - 2, 150, "ct:%d:%d:called", ct, ret);
|
||||||
|
if (ret > -1) {
|
||||||
recvlen += ret;
|
recvlen += ret;
|
||||||
lc = countlines(recvbuf, recvlen);
|
|
||||||
off = lc - g_y - 4;
|
mvprintw(g_y - 2, 50, "rendstat ct:%d:%d:%ld", ct, ret, recvlen);
|
||||||
off = getoff(recvbuf, recvlen, (off > 0) * off, '\n');
|
if (ret > 0 && recvbuf[recvlen-1] == '\n') {
|
||||||
mvaddnstr(1, 0, recvbuf + off, recvlen - off);
|
mvprintw(g_y - 2, 0, "newline at %ld", recvlen-1);
|
||||||
g_hardrefresh = 0;
|
}
|
||||||
|
mvprintw(g_y - 2, 130, "ct:%d:rendered", ct);
|
||||||
|
hardrefresh = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hardrefresh) {
|
||||||
|
mvprintw(g_y - 2, 100, "ct:%d:REFRESH INVOKED", ct);
|
||||||
|
mvaddnstr(1, 0, off, offlen);
|
||||||
|
hardrefresh = 0;
|
||||||
|
g_hardrefresh = 0;
|
||||||
|
}
|
||||||
/* send */
|
/* send */
|
||||||
while ((ch = getch()) != -1) {
|
while ((ch = getch()) != -1) {
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
if (sendlen == sendminlen) { continue; }
|
if (sendlen == sendminlen) {
|
||||||
UPDATE_TIME();
|
continue;
|
||||||
sendbuf[sendlen++] = '\n'; /* terminator */
|
}
|
||||||
send(sockfd, sendbuf, sendlen, 0);
|
if (sendlen + 1 < SENDMAX)
|
||||||
memcpy(recvbuf + recvlen, sendbuf, (sendlen + recvlen < RECVMAX) * sendlen);
|
{ sendbuf[sendlen++] = '\n'; }
|
||||||
recvlen += sendlen;
|
if (send(sockfd, sendbuf, sendlen, 0) > 0) {
|
||||||
mvaddnstr(1, 0, recvbuf, recvlen);
|
memcpy(recvbuf + recvlen - 1, sendbuf, (sendlen + recvlen - 1 < RECVMAX) * sendlen);
|
||||||
|
recvlen += sendlen;
|
||||||
|
hardrefresh = 1;
|
||||||
|
} else {
|
||||||
|
mvprintw(g_y - 2, 0, "message failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
mvaddch(g_y - 1, sendminlen, ' ');
|
mvaddch(g_y - 1, sendminlen, ' ');
|
||||||
|
inputrefresh = 1;
|
||||||
clearline(g_y - 1);
|
clearline(g_y - 1);
|
||||||
sendlen = sendminlen;
|
sendlen = sendminlen;
|
||||||
}
|
}
|
||||||
else if (ch == C_D) {
|
else if ((ch > 31 && ch < 127)) {
|
||||||
exit(0);
|
if (sendlen + 1 < SENDMAX)
|
||||||
|
{ sendbuf[sendlen++] = ch; }
|
||||||
|
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
||||||
}
|
}
|
||||||
else if (ch == BACKSPACE) {
|
else if (ch == BACKSPACE || ch == C_H) {
|
||||||
|
inputrefresh = 1;
|
||||||
clearline(g_y - 1);
|
clearline(g_y - 1);
|
||||||
if (sendlen - 1 >= sendminlen)
|
if (sendlen - 1 >= sendminlen)
|
||||||
{ mvaddch(g_y - 1, --sendlen, ' '); }
|
{ mvaddch(g_y - 1, --sendlen, ' '); }
|
||||||
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
||||||
move(g_y - 1, sendlen);
|
move(g_y - 1, sendlen);
|
||||||
|
goto nextloop;
|
||||||
}
|
}
|
||||||
else if (ch > 31 && ch < 127) {
|
else if (ch == C_T) {
|
||||||
if (sendlen + 1 < SENDMAX)
|
while (*off != '\n') { --off; }
|
||||||
{ sendbuf[sendlen++] = ch; }
|
if (*off == '\n') { ++off; }
|
||||||
mvaddnstr(g_y - 1, 0, sendbuf, sendlen);
|
hardrefresh = 1;
|
||||||
|
}
|
||||||
|
else if (ch == C_N) {
|
||||||
|
while (*off != '\n') { ++off; }
|
||||||
|
if (*off == '\n') { ++off; }
|
||||||
|
hardrefresh = 1;
|
||||||
|
}
|
||||||
|
else if (ch == C_W) {
|
||||||
|
while (sendlen > sendminlen && ispunct(sendbuf[sendlen - 1])) { --sendlen; }
|
||||||
|
while (sendlen > sendminlen && isspace(sendbuf[sendlen - 1])) { --sendlen; }
|
||||||
|
while (sendlen > sendminlen && isalnum(sendbuf[sendlen - 1])) { --sendlen; }
|
||||||
|
inputrefresh = 1;
|
||||||
|
clearline(g_y - 1);
|
||||||
|
goto nextloop;
|
||||||
|
}
|
||||||
|
else if (ch == C_L) {
|
||||||
|
clear();
|
||||||
|
decoration();
|
||||||
|
hardrefresh = 1;
|
||||||
|
ct = 0;
|
||||||
|
goto nextloop;
|
||||||
|
}
|
||||||
|
else if (ch == C_D) {
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* frame update */
|
||||||
move(g_y - 1, sendlen);
|
move(g_y - 1, sendlen);
|
||||||
++ct;
|
++ct;
|
||||||
refresh();
|
refresh();
|
||||||
|
Loading…
Reference in New Issue
Block a user