summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/chat.c45
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 */
81int 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
80static void chat_onKey(ToxWindow* self, int key) { 92static 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';