1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 10:53:26 +01:00

Merge pull request #407 from JFreegman/master

fixed chat window text wrapping in toxic
This commit is contained in:
irungentoo 2013-08-09 05:35:01 -07:00
commit 9237bbc0d7
2 changed files with 35 additions and 20 deletions

51
chat.c
View File

@ -14,6 +14,8 @@
#include "windows.h" #include "windows.h"
#define CURS_Y_OFFSET 3
typedef struct { typedef struct {
int friendnum; int friendnum;
char line[MAX_STR_SIZE]; char line[MAX_STR_SIZE];
@ -123,16 +125,35 @@ static void chat_onKey(ToxWindow *self, int key)
struct tm * timeinfo; struct tm * timeinfo;
timeinfo = localtime(&now); timeinfo = localtime(&now);
/* Add printable characters to line */ int x, y, y2, x2;
getyx(self->window, y, x);
getmaxyx(self->window, y2, x2);
/* Add printable chars to buffer and print on input space */
if (isprint(key)) { if (isprint(key)) {
if (ctx->pos != sizeof(ctx->line)-1) { if (ctx->pos != sizeof(ctx->line)-1) {
mvwaddch(self->window, y, x, key);
ctx->line[ctx->pos++] = key; ctx->line[ctx->pos++] = key;
ctx->line[ctx->pos] = '\0'; ctx->line[ctx->pos] = '\0';
} }
} }
/* BACKSPACE key: Remove one character from line */
else if (key == 0x107 || key == 0x8 || key == 0x7f) {
if (ctx->pos > 0) {
ctx->line[--ctx->pos] = '\0';
if (x == 0)
mvwdelch(self->window, y-1, x2-1);
else
mvwdelch(self->window, y, x-1);
}
}
/* RETURN key: Execute command or print line */ /* RETURN key: Execute command or print line */
else if (key == '\n') { if (key == '\n') {
wclear(ctx->linewin);
wmove(self->window, y2-CURS_Y_OFFSET, 0);
wclrtobot(self->window);
if (ctx->line[0] == '/') if (ctx->line[0] == '/')
execute(self, ctx, ctx->line, timeinfo); execute(self, ctx, ctx->line, timeinfo);
else { else {
@ -155,13 +176,6 @@ static void chat_onKey(ToxWindow *self, int key)
ctx->line[0] = '\0'; ctx->line[0] = '\0';
ctx->pos = 0; ctx->pos = 0;
} }
/* BACKSPACE key: Remove one character from line */
else if (key == 0x107 || key == 0x8 || key == 0x7f) {
if (ctx->pos != 0) {
ctx->line[--ctx->pos] = '\0';
}
}
} }
void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) void 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)
if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
wclear(self->window); wclear(self->window);
wclear(ctx->history); wclear(ctx->history);
int x, y;
getmaxyx(self->window, y, x);
(void) x;
wmove(self->window, y-CURS_Y_OFFSET, 0);
} }
else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h")) else if (!strcmp(cmd, "/help") || !strcmp(cmd, "/h"))
@ -287,14 +305,10 @@ static void chat_onDraw(ToxWindow *self)
{ {
curs_set(1); curs_set(1);
int x, y; int x, y;
ChatContext *ctx = (ChatContext*) self->x;
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
(void) x; (void) y;
if (y < 3) return; ChatContext *ctx = (ChatContext*) self->x;
mvwhline(ctx->linewin, 0, 0, '_', x);
wclear(ctx->linewin);
mvwhline(ctx->linewin, 0, 0, '_', COLS);
mvwprintw(self->window, y-1, 0, "%s\n", ctx->line);
wrefresh(self->window); wrefresh(self->window);
} }
@ -303,10 +317,11 @@ static void chat_onInit(ToxWindow *self)
int x, y; int x, y;
ChatContext *ctx = (ChatContext*) self->x; ChatContext *ctx = (ChatContext*) self->x;
getmaxyx(self->window, y, x); getmaxyx(self->window, y, x);
ctx->history = subwin(self->window, y - 4, x, 0, 0); ctx->history = subwin(self->window, y-4, x, 0, 0);
scrollok(ctx->history, 1); scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, 2, x, y - 3, 0); ctx->linewin = subwin(self->window, 2, x, y-4, 0);
print_help(ctx); print_help(ctx);
wmove(self->window, y-CURS_Y_OFFSET, 0);
} }
void print_help(ChatContext *self) void print_help(ChatContext *self)

4
main.c
View File

@ -82,7 +82,7 @@ void on_action(int friendnumber, uint8_t *string, uint16_t length)
void on_nickchange(int friendnumber, uint8_t *string, uint16_t length) void on_nickchange(int friendnumber, uint8_t *string, uint16_t length)
{ {
wprintw(prompt->window, "\n(nickchange) %d: %s!\n", friendnumber, string); wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string);
int i; int i;
for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { for (i = 0; i < MAX_WINDOW_SLOTS; ++i) {
if (windows[i].onNickChange != NULL) if (windows[i].onNickChange != NULL)
@ -281,7 +281,7 @@ static void draw_bar()
move(LINES - 1, 0); move(LINES - 1, 0);
attron(COLOR_PAIR(4) | A_BOLD); attron(COLOR_PAIR(4) | A_BOLD);
printw(" TOXIC " TOXICVER " |"); printw(" TOXIC " TOXICVER "|");
attroff(COLOR_PAIR(4) | A_BOLD); attroff(COLOR_PAIR(4) | A_BOLD);
int i; int i;