diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-09-09 16:29:23 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-09-09 16:29:23 +0200 |
commit | b89c6a3ffb7d6a8505403c0291a71a9f2ea1e6aa (patch) | |
tree | 50b75b990e2595894c5b80ba7edad7d468c5f745 | |
parent | 2a72f770ecf2f6243fada17c6c31d4dd085eb911 (diff) | |
download | messenger-cli-b89c6a3ffb7d6a8505403c0291a71a9f2ea1e6aa.tar.gz messenger-cli-b89c6a3ffb7d6a8505403c0291a71a9f2ea1e6aa.zip |
Added prefix syntax to send files
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/ui/messages.c | 35 | ||||
-rw-r--r-- | src/ui/messages.h | 3 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/ui/messages.c b/src/ui/messages.c index 7b2d724..8bfd934 100644 --- a/src/ui/messages.c +++ b/src/ui/messages.c | |||
@@ -116,7 +116,32 @@ messages_event(UI_MESSAGES_Handle *messages, | |||
116 | _messages_handle_message(messages); | 116 | _messages_handle_message(messages); |
117 | else if (messages->text_len > 0) | 117 | else if (messages->text_len > 0) |
118 | { | 118 | { |
119 | GNUNET_CHAT_context_send_text(app->chat.context, messages->text); | 119 | if (0 != strncmp(messages->text, |
120 | UI_MESSAGES_FILE_PREFIX, | ||
121 | UI_MESSAGES_FILE_PREFIX_LEN)) | ||
122 | goto write_text; | ||
123 | |||
124 | const char* filename = messages->text + 5; | ||
125 | |||
126 | if (0 != access(filename, R_OK | F_OK)) | ||
127 | break; | ||
128 | |||
129 | GNUNET_CHAT_context_send_file( | ||
130 | app->chat.context, | ||
131 | filename, | ||
132 | NULL, | ||
133 | NULL | ||
134 | ); | ||
135 | |||
136 | goto drop_text; | ||
137 | |||
138 | write_text: | ||
139 | GNUNET_CHAT_context_send_text( | ||
140 | app->chat.context, | ||
141 | messages->text | ||
142 | ); | ||
143 | |||
144 | drop_text: | ||
120 | messages->text_len = 0; | 145 | messages->text_len = 0; |
121 | } | 146 | } |
122 | break; | 147 | break; |
@@ -269,7 +294,13 @@ messages_print(UI_MESSAGES_Handle *messages) | |||
269 | wmove(messages->window, line_height, 0); | 294 | wmove(messages->window, line_height, 0); |
270 | whline(messages->window, '-', width); | 295 | whline(messages->window, '-', width); |
271 | 296 | ||
272 | const int attrs_select = A_BOLD; | 297 | const bool is_file_text = (0 == strncmp( |
298 | messages->text, | ||
299 | UI_MESSAGES_FILE_PREFIX, | ||
300 | UI_MESSAGES_FILE_PREFIX_LEN | ||
301 | )); | ||
302 | |||
303 | const int attrs_select = A_BOLD | (is_file_text? A_ITALIC : A_NORMAL); | ||
273 | 304 | ||
274 | if (selected) wattron(messages->window, attrs_select); | 305 | if (selected) wattron(messages->window, attrs_select); |
275 | 306 | ||
diff --git a/src/ui/messages.h b/src/ui/messages.h index 685cb82..edc3192 100644 --- a/src/ui/messages.h +++ b/src/ui/messages.h | |||
@@ -70,6 +70,9 @@ typedef struct UI_MESSAGES_Handle | |||
70 | 70 | ||
71 | #define UI_MESSAGES_COLS_MIN 50 | 71 | #define UI_MESSAGES_COLS_MIN 50 |
72 | 72 | ||
73 | #define UI_MESSAGES_FILE_PREFIX "file:" | ||
74 | #define UI_MESSAGES_FILE_PREFIX_LEN 5 | ||
75 | |||
73 | void | 76 | void |
74 | messages_event(UI_MESSAGES_Handle *messages, | 77 | messages_event(UI_MESSAGES_Handle *messages, |
75 | struct MESSENGER_Application *app, | 78 | struct MESSENGER_Application *app, |