summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/chat.c51
-rw-r--r--testing/toxic/main.c4
2 files changed, 35 insertions, 20 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 73cb1458..33f51f29 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -14,6 +14,8 @@
14 14
15#include "windows.h" 15#include "windows.h"
16 16
17#define CURS_Y_OFFSET 3
18
17typedef struct { 19typedef struct {
18 int friendnum; 20 int friendnum;
19 char line[MAX_STR_SIZE]; 21 char line[MAX_STR_SIZE];
@@ -123,16 +125,35 @@ static void chat_onKey(ToxWindow *self, int key)
123 struct tm * timeinfo; 125 struct tm * timeinfo;
124 timeinfo = localtime(&now); 126 timeinfo = localtime(&now);
125 127
126 /* Add printable characters to line */ 128 int x, y, y2, x2;
129 getyx(self->window, y, x);
130 getmaxyx(self->window, y2, x2);
131
132 /* Add printable chars to buffer and print on input space */
127 if (isprint(key)) { 133 if (isprint(key)) {
128 if (ctx->pos != sizeof(ctx->line)-1) { 134 if (ctx->pos != sizeof(ctx->line)-1) {
135 mvwaddch(self->window, y, x, key);
129 ctx->line[ctx->pos++] = key; 136 ctx->line[ctx->pos++] = key;
130 ctx->line[ctx->pos] = '\0'; 137 ctx->line[ctx->pos] = '\0';
131 } 138 }
132 } 139 }
133 140
141 /* BACKSPACE key: Remove one character from line */
142 else if (key == 0x107 || key == 0x8 || key == 0x7f) {
143 if (ctx->pos > 0) {
144 ctx->line[--ctx->pos] = '\0';
145 if (x == 0)
146 mvwdelch(self->window, y-1, x2-1);
147 else
148 mvwdelch(self->window, y, x-1);
149 }
150 }
151
134 /* RETURN key: Execute command or print line */ 152 /* RETURN key: Execute command or print line */
135 else if (key == '\n') { 153 if (key == '\n') {
154 wclear(ctx->linewin);
155 wmove(self->window, y2-CURS_Y_OFFSET, 0);
156 wclrtobot(self->window);
136 if (ctx->line[0] == '/') 157 if (ctx->line[0] == '/')
137 execute(self, ctx, ctx->line, timeinfo); 158 execute(self, ctx, ctx->line, timeinfo);
138 else { 159 else {
@@ -155,13 +176,6 @@ static void chat_onKey(ToxWindow *self, int key)
155 ctx->line[0] = '\0'; 176 ctx->line[0] = '\0';
156 ctx->pos = 0; 177 ctx->pos = 0;
157 } 178 }
158
159 /* BACKSPACE key: Remove one character from line */
160 else if (key == 0x107 || key == 0x8 || key == 0x7f) {
161 if (ctx->pos != 0) {
162 ctx->line[--ctx->pos] = '\0';
163 }
164 }
165} 179}
166 180
167void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) 181void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo)
@@ -169,6 +183,10 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo)
169 if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { 183 if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
170 wclear(self->window); 184 wclear(self->window);
171 wclear(ctx->history); 185 wclear(ctx->history);
186 int x, y;
187 getmaxyx(self->window, y, x);
188 (void) x;
189 wmove(self->window, y-CURS_Y_OFFSET, 0);
172 } 190 }
173 191
174 else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h")) 192 else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h"))
@@ -287,14 +305,10 @@ static void chat_onDraw(ToxWindow *self)
287{ 305{
288 curs_set(1); 306 curs_set(1);
289 int x, y; 307 int x, y;
290 ChatContext *ctx = (ChatContext*) self->x;
291 getmaxyx(self->window, y, x); 308 getmaxyx(self->window, y, x);
292 (void) x; 309 (void) y;
293 if (y < 3) return; 310 ChatContext *ctx = (ChatContext*) self->x;
294 311 mvwhline(ctx->linewin, 0, 0, '_', x);
295 wclear(ctx->linewin);
296 mvwhline(ctx->linewin, 0, 0, '_', COLS);
297 mvwprintw(self->window, y-1, 0, "%s\n", ctx->line);
298 wrefresh(self->window); 312 wrefresh(self->window);
299} 313}
300 314
@@ -303,10 +317,11 @@ static void chat_onInit(ToxWindow *self)
303 int x, y; 317 int x, y;
304 ChatContext *ctx = (ChatContext*) self->x; 318 ChatContext *ctx = (ChatContext*) self->x;
305 getmaxyx(self->window, y, x); 319 getmaxyx(self->window, y, x);
306 ctx->history = subwin(self->window, y - 4, x, 0, 0); 320 ctx->history = subwin(self->window, y-4, x, 0, 0);
307 scrollok(ctx->history, 1); 321 scrollok(ctx->history, 1);
308 ctx->linewin = subwin(self->window, 2, x, y - 3, 0); 322 ctx->linewin = subwin(self->window, 2, x, y-4, 0);
309 print_help(ctx); 323 print_help(ctx);
324 wmove(self->window, y-CURS_Y_OFFSET, 0);
310} 325}
311 326
312void print_help(ChatContext *self) 327void print_help(ChatContext *self)
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 3c5c4be7..bb5faf83 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -82,7 +82,7 @@ void on_action(int friendnumber, uint8_t *string, uint16_t length)
82 82
83void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) 83void on_nickchange(int friendnumber, uint8_t *string, uint16_t length)
84{ 84{
85 wprintw(prompt->window, "\n(nickchange) %d: %s!\n", friendnumber, string); 85 wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string);
86 int i; 86 int i;
87 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { 87 for (i = 0; i < MAX_WINDOW_SLOTS; ++i) {
88 if (windows[i].onNickChange != NULL) 88 if (windows[i].onNickChange != NULL)
@@ -281,7 +281,7 @@ static void draw_bar()
281 move(LINES - 1, 0); 281 move(LINES - 1, 0);
282 282
283 attron(COLOR_PAIR(4) | A_BOLD); 283 attron(COLOR_PAIR(4) | A_BOLD);
284 printw(" TOXIC " TOXICVER " |"); 284 printw(" TOXIC " TOXICVER "|");
285 attroff(COLOR_PAIR(4) | A_BOLD); 285 attroff(COLOR_PAIR(4) | A_BOLD);
286 286
287 int i; 287 int i;