diff options
author | charmlesscoin <charmlesscoin@gmail.com> | 2013-08-03 17:29:18 -0400 |
---|---|---|
committer | charmlesscoin <charmlesscoin@gmail.com> | 2013-08-03 17:29:18 -0400 |
commit | a65715e81134207677354a2e827a38723f3ee6bc (patch) | |
tree | 1f075508220dba710ac7b4dcc8be8ed311618e16 /testing | |
parent | 09a6d2d351840edbe8defd7c209c312c226bedef (diff) |
fix for issue #306
Diffstat (limited to 'testing')
-rw-r--r-- | testing/toxic/chat.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 7cae1c0a..a90bb2aa 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -77,6 +77,18 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 | |||
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | /* check that the string has one non-space character */ | ||
81 | int string_is_empty(char *string) | ||
82 | { | ||
83 | int rc = 0; | ||
84 | char *copy = strdup(string); | ||
85 | |||
86 | rc = ((strtok(copy, " ") == NULL) ? 1:0); | ||
87 | free(copy); | ||
88 | |||
89 | return rc; | ||
90 | } | ||
91 | |||
80 | static void chat_onKey(ToxWindow* self, int key) { | 92 | static void chat_onKey(ToxWindow* self, int key) { |
81 | ChatContext* ctx = (ChatContext*) self->x; | 93 | ChatContext* ctx = (ChatContext*) self->x; |
82 | 94 | ||
@@ -92,23 +104,28 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
92 | ctx->line[ctx->pos] = '\0'; | 104 | ctx->line[ctx->pos] = '\0'; |
93 | } | 105 | } |
94 | } | 106 | } |
107 | |||
95 | else if(key == '\n') { | 108 | else if(key == '\n') { |
96 | wattron(ctx->history, COLOR_PAIR(2)); | 109 | if(!string_is_empty(ctx->line)) { |
97 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | 110 | /* make sure the string has at least non-space character */ |
98 | wattron(ctx->history, COLOR_PAIR(1)); | 111 | wattron(ctx->history, COLOR_PAIR(2)); |
99 | wprintw(ctx->history, "you: ", ctx->line); | 112 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
100 | wattroff(ctx->history, COLOR_PAIR(1)); | 113 | wattron(ctx->history, COLOR_PAIR(1)); |
101 | wprintw(ctx->history, "%s\n", ctx->line); | 114 | wprintw(ctx->history, "you: ", ctx->line); |
102 | 115 | wattroff(ctx->history, COLOR_PAIR(1)); | |
103 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { | 116 | wprintw(ctx->history, "%s\n", ctx->line); |
104 | wattron(ctx->history, COLOR_PAIR(3)); | 117 | |
105 | wprintw(ctx->history, " * Failed to send message.\n"); | 118 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { |
106 | wattroff(ctx->history, COLOR_PAIR(3)); | 119 | wattron(ctx->history, COLOR_PAIR(3)); |
120 | wprintw(ctx->history, " * Failed to send message.\n"); | ||
121 | wattroff(ctx->history, COLOR_PAIR(3)); | ||
122 | } | ||
123 | |||
124 | ctx->line[0] = '\0'; | ||
125 | ctx->pos = 0; | ||
107 | } | 126 | } |
108 | |||
109 | ctx->line[0] = '\0'; | ||
110 | ctx->pos = 0; | ||
111 | } | 127 | } |
128 | |||
112 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { | 129 | else if(key == 0x107 || key == 0x8 || key == 0x7f) { |
113 | if(ctx->pos != 0) { | 130 | if(ctx->pos != 0) { |
114 | ctx->line[--ctx->pos] = '\0'; | 131 | ctx->line[--ctx->pos] = '\0'; |