2014-02-25 08:28:24 +01:00
|
|
|
/* prompt.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2013-09-02 19:19:25 +02:00
|
|
|
*/
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2014-07-14 20:32:38 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE /* needed for wcswidth() */
|
|
|
|
#endif
|
|
|
|
|
2013-07-30 01:32:39 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-06-22 03:41:38 +02:00
|
|
|
#include <wchar.h>
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "autocomplete.h"
|
2013-11-10 03:43:56 +01:00
|
|
|
#include "execute.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "friendlist.h"
|
2014-07-04 09:24:29 +02:00
|
|
|
#include "help.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "input.h"
|
|
|
|
#include "line_info.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "misc_tools.h"
|
2014-07-21 01:12:13 +02:00
|
|
|
#include "notify.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "prompt.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "toxic.h"
|
|
|
|
#include "toxic_strings.h"
|
|
|
|
#include "windows.h"
|
2013-08-17 11:59:28 +02:00
|
|
|
|
2013-12-06 11:07:35 +01:00
|
|
|
extern ToxWindow *prompt;
|
2014-09-23 03:24:45 +02:00
|
|
|
extern struct user_settings *user_settings;
|
|
|
|
extern struct Winthread Winthread;
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2015-04-01 00:39:42 +02:00
|
|
|
extern FriendsList Friends;
|
2014-09-28 23:49:48 +02:00
|
|
|
FriendRequests FrndRequests;
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2013-12-09 23:56:20 +01:00
|
|
|
/* Array of global command names used for tab completion. */
|
2020-10-30 01:28:09 +01:00
|
|
|
static const char *glob_cmd_list[] = {
|
|
|
|
"/accept",
|
|
|
|
"/add",
|
|
|
|
"/avatar",
|
|
|
|
"/clear",
|
|
|
|
"/connect",
|
|
|
|
"/decline",
|
|
|
|
"/exit",
|
2020-11-08 16:08:24 +01:00
|
|
|
"/conference",
|
2021-04-22 23:05:04 +02:00
|
|
|
#ifdef GAMES
|
2020-12-11 07:46:01 +01:00
|
|
|
"/game",
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif
|
2020-10-30 01:28:09 +01:00
|
|
|
"/help",
|
|
|
|
"/log",
|
|
|
|
"/myid",
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef QRCODE
|
2020-10-30 01:28:09 +01:00
|
|
|
"/myqr",
|
2018-06-16 05:07:16 +02:00
|
|
|
#endif /* QRCODE */
|
2020-10-30 01:28:09 +01:00
|
|
|
"/nick",
|
|
|
|
"/note",
|
|
|
|
"/nospam",
|
|
|
|
"/quit",
|
|
|
|
"/requests",
|
|
|
|
"/status",
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
"/lsdev",
|
|
|
|
"/sdev",
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
#ifdef VIDEO
|
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
"/lsvdev",
|
|
|
|
"/svdev",
|
2015-11-04 05:04:05 +01:00
|
|
|
|
2015-07-30 08:49:27 +02:00
|
|
|
#endif /* VIDEO */
|
2015-11-04 05:04:05 +01:00
|
|
|
|
2017-05-23 02:47:56 +02:00
|
|
|
#ifdef PYTHON
|
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
"/run",
|
2017-05-23 02:47:56 +02:00
|
|
|
|
|
|
|
#endif /* PYTHON */
|
|
|
|
|
2013-12-09 23:56:20 +01:00
|
|
|
};
|
2013-12-06 11:07:35 +01:00
|
|
|
|
2015-03-17 20:25:15 +01:00
|
|
|
void kill_prompt_window(ToxWindow *self)
|
2014-07-10 04:11:31 +02:00
|
|
|
{
|
2014-07-09 01:24:44 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
|
|
|
log_disable(ctx->log);
|
|
|
|
line_info_cleanup(ctx->hst);
|
|
|
|
|
|
|
|
delwin(ctx->linewin);
|
|
|
|
delwin(ctx->history);
|
|
|
|
delwin(statusbar->topline);
|
|
|
|
|
|
|
|
free(ctx->log);
|
|
|
|
free(ctx);
|
|
|
|
free(self->help);
|
|
|
|
free(statusbar);
|
|
|
|
|
|
|
|
del_window(self);
|
|
|
|
}
|
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
/* callback: Updates own connection status in prompt statusbar */
|
2018-10-10 05:06:57 +02:00
|
|
|
void on_self_connection_status(Tox *m, Tox_Connection connection_status, void *userdata)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(userdata);
|
2015-03-28 07:56:54 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
|
|
|
statusbar->connection = connection_status;
|
2021-11-19 23:54:35 +01:00
|
|
|
|
|
|
|
flag_interface_refresh();
|
2015-03-28 07:56:54 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 01:59:45 +02:00
|
|
|
/* Updates own nick in prompt statusbar */
|
2014-07-29 20:54:34 +02:00
|
|
|
void prompt_update_nick(ToxWindow *prompt, const char *nick)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
2014-06-01 19:36:23 +02:00
|
|
|
statusbar->nick_len = strlen(statusbar->nick);
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
2014-08-12 09:01:18 +02:00
|
|
|
/* Updates own statusmessage */
|
|
|
|
void prompt_update_statusmessage(ToxWindow *prompt, Tox *m, const char *statusmsg)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t len = strlen(statusbar->statusmsg);
|
2014-08-12 09:01:18 +02:00
|
|
|
statusbar->statusmsg_len = len;
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Set_Info err;
|
2018-09-14 01:47:47 +02:00
|
|
|
tox_self_set_status_message(m, (const uint8_t *) statusmsg, len, &err);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (err != TOX_ERR_SET_INFO_OK) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set note (error %d)\n", err);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates own status in prompt statusbar */
|
2018-10-10 05:06:57 +02:00
|
|
|
void prompt_update_status(ToxWindow *prompt, Tox_User_Status status)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
statusbar->status = status;
|
|
|
|
}
|
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
/* Returns our own connection status */
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Connection prompt_selfConnectionStatus(void)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
|
|
|
StatusBar *statusbar = prompt->stb;
|
|
|
|
return statusbar->connection;
|
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
/* Adds friend request to pending friend requests.
|
2014-08-07 19:05:42 +02:00
|
|
|
Returns request number on success, -1 if queue is full. */
|
2014-08-20 02:49:29 +02:00
|
|
|
static int add_friend_request(const char *public_key, const char *data)
|
2013-09-06 08:51:10 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (FrndRequests.max_idx >= MAX_FRIEND_REQUESTS) {
|
2013-12-01 23:08:57 +01:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-01 22:57:05 +01:00
|
|
|
|
|
|
|
int i;
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
for (i = 0; i <= FrndRequests.max_idx; ++i) {
|
|
|
|
if (!FrndRequests.request[i].active) {
|
|
|
|
FrndRequests.request[i].active = true;
|
2015-02-01 21:09:48 +01:00
|
|
|
memcpy(FrndRequests.request[i].key, public_key, TOX_PUBLIC_KEY_SIZE);
|
2014-09-28 23:49:48 +02:00
|
|
|
snprintf(FrndRequests.request[i].msg, sizeof(FrndRequests.request[i].msg), "%s", data);
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (i == FrndRequests.max_idx) {
|
2014-09-28 23:49:48 +02:00
|
|
|
++FrndRequests.max_idx;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-20 02:49:29 +02:00
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
++FrndRequests.num_requests;
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2013-12-01 22:57:05 +01:00
|
|
|
return i;
|
2013-10-16 23:59:56 +02:00
|
|
|
}
|
2013-09-16 06:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2013-09-06 08:51:10 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
/*
|
|
|
|
* Return true if input is recognized by handler
|
|
|
|
*/
|
|
|
|
static bool prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-12-04 09:57:03 +01:00
|
|
|
|
2013-10-23 09:24:08 +02:00
|
|
|
int x, y, y2, x2;
|
2014-06-29 00:40:22 +02:00
|
|
|
getyx(self->window, y, x);
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2020-03-30 18:56:42 +02:00
|
|
|
UNUSED_VAR(y);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (x2 <= 0 || y2 <= 0) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return false;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->pastemode && key == '\r') {
|
2016-01-17 15:10:46 +01:00
|
|
|
key = '\n';
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-01-17 15:10:46 +01:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
/* ignore non-menu related input if active */
|
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-07-04 09:24:29 +02:00
|
|
|
}
|
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
if (ltr || key == '\n') { /* char is printable */
|
2020-03-15 19:57:00 +01:00
|
|
|
input_new_char(self, key, x, x2);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-06-29 00:40:22 +02:00
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (line_info_onKey(self, key)) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
if (input_handle(self, key, x, x2)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int input_ret = false;
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (key == '\t') { /* TAB key: auto-completes command */
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (ctx->len > 1 && ctx->line[0] == '/') {
|
2014-09-26 09:10:44 +02:00
|
|
|
int diff = -1;
|
|
|
|
|
2018-10-08 06:47:51 +02:00
|
|
|
if (wcsncmp(ctx->line, L"/avatar ", wcslen(L"/avatar ")) == 0) {
|
2014-09-26 09:10:44 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/avatar");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2017-05-23 02:47:56 +02:00
|
|
|
|
|
|
|
#ifdef PYTHON
|
2018-10-08 06:47:51 +02:00
|
|
|
else if (wcsncmp(ctx->line, L"/run ", wcslen(L"/run ")) == 0) {
|
2017-05-23 02:47:56 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/run");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2017-06-01 22:46:12 +02:00
|
|
|
|
2017-05-23 02:47:56 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) {
|
2020-10-30 01:28:09 +01:00
|
|
|
const char *status_cmd_list[] = {
|
|
|
|
"online",
|
|
|
|
"away",
|
|
|
|
"busy",
|
2015-03-17 20:25:15 +01:00
|
|
|
};
|
2020-10-30 01:28:09 +01:00
|
|
|
diff = complete_line(self, status_cmd_list, sizeof(status_cmd_list) / sizeof(char *));
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-10-30 01:28:09 +01:00
|
|
|
diff = complete_line(self, glob_cmd_list, sizeof(glob_cmd_list) / sizeof(char *));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-29 22:54:27 +02:00
|
|
|
|
|
|
|
if (diff != -1) {
|
|
|
|
if (x + diff > x2 - 1) {
|
2015-08-27 09:38:08 +02:00
|
|
|
int wlen = MAX(0, wcswidth(ctx->line, sizeof(ctx->line) / sizeof(wchar_t)));
|
2014-07-18 18:42:53 +02:00
|
|
|
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
2014-06-29 22:54:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(self, notif_error, 0, NULL);
|
2014-06-29 22:54:27 +02:00
|
|
|
}
|
2014-06-29 00:40:22 +02:00
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(self, notif_error, 0, NULL);
|
2013-12-16 02:52:10 +01:00
|
|
|
}
|
2015-12-04 20:15:31 +01:00
|
|
|
} else if (key == '\r') {
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
rm_trailing_spaces_buf(ctx);
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
if (!wstring_is_empty(ctx->line)) {
|
2015-12-04 20:15:31 +01:00
|
|
|
add_line_to_hist(ctx);
|
|
|
|
wstrsubst(ctx->line, L'¶', L'\n');
|
2014-06-04 02:35:00 +02:00
|
|
|
|
2020-11-24 22:41:42 +01:00
|
|
|
char line[MAX_STR_SIZE];
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message.");
|
2020-11-24 22:41:42 +01:00
|
|
|
} else {
|
2021-01-24 03:17:46 +01:00
|
|
|
if (strcmp(line, "/clear") != 0) {
|
|
|
|
line_info_add(self, false, NULL, NULL, PROMPT, 0, 0, "%s", line);
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:41:42 +01:00
|
|
|
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-12-04 20:15:31 +01:00
|
|
|
}
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
wclear(ctx->linewin);
|
2020-11-30 05:26:51 +01:00
|
|
|
wmove(self->window, y2, 0);
|
2014-06-29 00:40:22 +02:00
|
|
|
reset_buf(ctx);
|
2013-07-30 01:32:39 +02:00
|
|
|
}
|
2020-10-13 22:12:55 +02:00
|
|
|
|
|
|
|
return input_ret;
|
2013-07-30 01:32:39 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 23:03:44 +02:00
|
|
|
static void prompt_onDraw(ToxWindow *self, Tox *m)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-11-30 05:26:51 +01:00
|
|
|
int x2;
|
|
|
|
int y2;
|
2014-06-29 00:40:22 +02:00
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-03-24 12:37:52 +01:00
|
|
|
line_info_print(self);
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
wclear(ctx->linewin);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->len > 0) {
|
2020-11-30 05:26:51 +01:00
|
|
|
mvwprintw(ctx->linewin, 0, 0, "%ls", &ctx->line[ctx->start]);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
curs_set(1);
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2015-08-28 03:29:34 +02:00
|
|
|
|
2013-09-28 01:55:11 +02:00
|
|
|
wmove(statusbar->topline, 0, 0);
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Connection connection = statusbar->connection;
|
2020-11-30 05:26:51 +01:00
|
|
|
Tox_User_Status status = statusbar->status;
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2021-11-26 05:05:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
|
|
|
wprintw(statusbar->topline, " [");
|
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
|
|
|
|
|
|
|
switch (connection) {
|
|
|
|
case TOX_CONNECTION_TCP:
|
|
|
|
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
|
|
|
wprintw(statusbar->topline, "TCP");
|
|
|
|
wattroff(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_CONNECTION_UDP:
|
|
|
|
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
|
|
|
wprintw(statusbar->topline, "UDP");
|
|
|
|
wattroff(statusbar->topline, A_BOLD | COLOR_PAIR(STATUS_ONLINE));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
|
|
|
wprintw(statusbar->topline, "Offline");
|
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
|
|
|
wprintw(statusbar->topline, "]");
|
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
|
|
|
|
|
|
|
if (status != TOX_USER_STATUS_NONE) {
|
2015-03-26 03:56:45 +01:00
|
|
|
int colour = MAGENTA;
|
2015-07-04 07:19:16 +02:00
|
|
|
const char *status_text = "ERROR";
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
switch (status) {
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_AWAY:
|
2020-12-05 21:39:33 +01:00
|
|
|
colour = STATUS_AWAY;
|
2021-11-26 05:05:33 +01:00
|
|
|
status_text = "Away";
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_BUSY:
|
2020-12-05 21:39:33 +01:00
|
|
|
colour = STATUS_BUSY;
|
2021-11-26 05:05:33 +01:00
|
|
|
status_text = "Busy";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(statusbar->topline, " [");
|
2020-12-05 21:39:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
|
|
|
|
wattron(statusbar->topline, A_BOLD | COLOR_PAIR(colour));
|
|
|
|
wprintw(statusbar->topline, "%s", status_text);
|
|
|
|
wattroff(statusbar->topline, A_BOLD | COLOR_PAIR(colour));
|
|
|
|
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(statusbar->topline, "]");
|
2020-12-05 21:39:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
2014-03-15 12:40:13 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-03-15 12:40:13 +01:00
|
|
|
wprintw(statusbar->topline, " %s", statusbar->nick);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2013-09-07 01:59:45 +02:00
|
|
|
} else {
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
2020-11-30 05:26:51 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-09-25 10:31:45 +02:00
|
|
|
wprintw(statusbar->topline, " %s", statusbar->nick);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
int s_y;
|
|
|
|
int s_x;
|
|
|
|
getyx(statusbar->topline, s_y, s_x);
|
|
|
|
|
|
|
|
mvwhline(statusbar->topline, s_y, s_x, ' ', x2 - s_x);
|
2020-12-05 21:39:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
2020-11-30 05:26:51 +01:00
|
|
|
|
2014-08-10 06:29:18 +02:00
|
|
|
/* Reset statusbar->statusmsg on window resize */
|
|
|
|
if (x2 != self->x) {
|
2015-03-26 03:56:45 +01:00
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
2014-08-10 06:29:18 +02:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2021-11-26 14:51:38 +01:00
|
|
|
|
2015-04-10 06:16:01 +02:00
|
|
|
size_t slen = tox_self_get_status_message_size(m);
|
2018-07-18 17:33:16 +02:00
|
|
|
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
2021-11-26 14:51:38 +01:00
|
|
|
|
2015-04-10 06:16:01 +02:00
|
|
|
statusmsg[slen] = '\0';
|
2014-08-10 06:29:18 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
|
|
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
2021-11-26 14:51:38 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-08-10 06:29:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
self->x = x2;
|
|
|
|
|
|
|
|
/* Truncate note if it doesn't fit in statusbar */
|
|
|
|
uint16_t maxlen = x2 - getcurx(statusbar->topline) - 3;
|
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2021-11-26 14:51:38 +01:00
|
|
|
size_t statusmsg_len = statusbar->statusmsg_len;
|
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2015-08-28 03:29:34 +02:00
|
|
|
|
2021-11-26 14:51:38 +01:00
|
|
|
if (statusmsg_len > maxlen) {
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
|
|
|
statusbar->statusmsg[maxlen - 3] = 0;
|
2014-08-10 06:29:18 +02:00
|
|
|
strcat(statusbar->statusmsg, "...");
|
|
|
|
statusbar->statusmsg_len = maxlen;
|
2021-11-26 14:51:38 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-08-10 06:29:18 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:51:38 +01:00
|
|
|
if (statusmsg_len) {
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(statusbar->topline, " | ");
|
2020-12-05 21:39:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_ACCENT));
|
2020-11-30 05:26:51 +01:00
|
|
|
|
2020-12-05 21:39:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
2021-11-26 14:51:38 +01:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(statusbar->topline, "%s", statusbar->statusmsg);
|
2021-11-26 14:51:38 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2020-12-05 21:39:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(BAR_TEXT));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-15 12:40:13 +01:00
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
int y;
|
|
|
|
int x;
|
2014-07-01 05:56:47 +02:00
|
|
|
getyx(self->window, y, x);
|
2020-03-30 18:56:42 +02:00
|
|
|
|
|
|
|
UNUSED_VAR(x);
|
2014-07-07 04:15:35 +02:00
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
int new_x = ctx->start ? x2 - 1 : MAX(0, wcswidth(ctx->line, ctx->pos));
|
2020-11-30 05:26:51 +01:00
|
|
|
wmove(self->window, y, new_x);
|
|
|
|
|
|
|
|
draw_window_bar(self);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2016-07-27 02:07:31 +02:00
|
|
|
wnoutrefresh(self->window);
|
2014-07-05 20:46:16 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->help->active) {
|
2014-07-04 09:24:29 +02:00
|
|
|
help_onDraw(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-07-30 01:32:39 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, uint32_t friendnum, Tox_Connection connection_status)
|
2013-09-23 07:22:21 +02:00
|
|
|
{
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-12-06 11:07:35 +01:00
|
|
|
|
2014-07-08 20:31:59 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH] = {0}; /* stop removing this initiation */
|
|
|
|
get_nick_truncate(m, nick, friendnum);
|
2014-04-01 08:48:37 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!nick[0]) {
|
2013-09-23 07:22:21 +02:00
|
|
|
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-23 07:22:21 +02:00
|
|
|
|
2014-07-27 01:16:07 +02:00
|
|
|
const char *msg;
|
2014-03-02 00:06:35 +01:00
|
|
|
|
2016-02-25 23:06:49 +01:00
|
|
|
if (user_settings->show_connection_msg == SHOW_WELCOME_MSG_OFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-01 00:39:42 +02:00
|
|
|
if (connection_status != TOX_CONNECTION_NONE && Friends.list[friendnum].connection_status == TOX_CONNECTION_NONE) {
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "has come online";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, true, nick, NULL, CONNECTION, 0, GREEN, msg);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2014-07-22 20:38:32 +02:00
|
|
|
|
2018-07-18 17:56:21 +02:00
|
|
|
if (self->active_box != -1) {
|
2015-03-17 20:25:15 +01:00
|
|
|
box_notify2(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, self->active_box,
|
2018-07-18 17:33:16 +02:00
|
|
|
"%s has come online", nick);
|
2018-07-18 17:56:21 +02:00
|
|
|
} else {
|
2014-08-02 00:37:02 +02:00
|
|
|
box_notify(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, &self->active_box,
|
2018-07-18 17:33:16 +02:00
|
|
|
"Toxic", "%s has come online", nick);
|
2018-07-18 17:56:21 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
} else if (connection_status == TOX_CONNECTION_NONE) {
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "has gone offline";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, true, nick, NULL, DISCONNECTION, 0, RED, msg);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2014-07-22 20:38:32 +02:00
|
|
|
|
2018-07-18 17:56:21 +02:00
|
|
|
if (self->active_box != -1) {
|
2015-03-17 20:25:15 +01:00
|
|
|
box_notify2(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, self->active_box,
|
2018-07-18 17:33:16 +02:00
|
|
|
"%s has gone offline", nick);
|
2018-07-18 17:56:21 +02:00
|
|
|
} else {
|
2014-08-02 00:37:02 +02:00
|
|
|
box_notify(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL, &self->active_box,
|
2018-07-18 17:33:16 +02:00
|
|
|
"Toxic", "%s has gone offline", nick);
|
2018-07-18 17:56:21 +02:00
|
|
|
}
|
2013-09-23 07:22:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, const char *data, size_t length)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-02 00:06:35 +01:00
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, true, NULL, NULL, SYS_MSG, 0, 0, "Friend request with the message '%s'", data);
|
2015-07-04 07:19:16 +02:00
|
|
|
write_to_log("Friend request with the message '%s'", "", ctx->log, true);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2014-08-20 02:49:29 +02:00
|
|
|
int n = add_friend_request(key, data);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-09-22 10:32:51 +02:00
|
|
|
if (n == -1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
const char *errmsg = "Friend request queue is full. Discarding request.";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
2013-09-22 10:32:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Type \"/accept %d\" or \"/decline %d\"", n, n);
|
2014-08-02 00:37:02 +02:00
|
|
|
sound_notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND, NULL);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 18:43:43 +02:00
|
|
|
void prompt_init_statusbar(ToxWindow *self, Tox *m, bool first_time_run)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2014-03-25 08:17:22 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
exit_toxic_err("failed in prompt_init_statusbar", FATALERR_CURSES);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2020-03-30 18:56:42 +02:00
|
|
|
UNUSED_VAR(y2);
|
2013-09-07 01:59:45 +02:00
|
|
|
|
|
|
|
/* Init statusbar info */
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2015-03-26 03:56:45 +01:00
|
|
|
statusbar->status = TOX_USER_STATUS_NONE;
|
2015-03-28 07:56:54 +01:00
|
|
|
statusbar->connection = TOX_CONNECTION_NONE;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2015-03-28 07:56:54 +01:00
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
size_t n_len = tox_self_get_name_size(m);
|
|
|
|
tox_self_get_name(m, (uint8_t *) nick);
|
|
|
|
|
|
|
|
size_t s_len = tox_self_get_status_message_size(m);
|
|
|
|
tox_self_get_status_message(m, (uint8_t *) statusmsg);
|
2014-03-13 12:34:14 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_User_Status status = tox_self_get_status(m);
|
2014-03-13 12:34:14 +01:00
|
|
|
|
2014-04-01 04:00:17 +02:00
|
|
|
nick[n_len] = '\0';
|
|
|
|
statusmsg[s_len] = '\0';
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2018-10-04 18:43:43 +02:00
|
|
|
if (first_time_run) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(statusmsg, sizeof(statusmsg), "Toxing on Toxic");
|
2014-04-19 23:58:13 +02:00
|
|
|
s_len = strlen(statusmsg);
|
2014-04-01 04:00:17 +02:00
|
|
|
statusmsg[s_len] = '\0';
|
|
|
|
}
|
2014-02-22 10:46:35 +01:00
|
|
|
|
2014-08-12 09:01:18 +02:00
|
|
|
prompt_update_statusmessage(prompt, m, statusmsg);
|
2014-03-15 12:40:13 +01:00
|
|
|
prompt_update_status(prompt, status);
|
2014-07-07 04:15:35 +02:00
|
|
|
prompt_update_nick(prompt, nick);
|
2013-09-07 01:59:45 +02:00
|
|
|
|
|
|
|
/* Init statusbar subwindow */
|
2020-11-30 05:26:51 +01:00
|
|
|
statusbar->topline = subwin(self->window, TOP_BAR_HEIGHT, x2, 0, 0);
|
2014-03-25 08:17:22 +01:00
|
|
|
}
|
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
static void print_welcome_msg(ToxWindow *self)
|
|
|
|
{
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, BLUE, " _____ _____ _____ ____ ");
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, BLUE, " |_ _/ _ \\ \\/ /_ _/ ___|");
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, BLUE, " | || | | \\ / | | | ");
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, BLUE, " | || |_| / \\ | | |___ ");
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, BLUE, " |_| \\___/_/\\_\\___\\____| v." TOXICVER);
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "");
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2020-02-10 23:16:56 +01:00
|
|
|
const char *msg = "Welcome to Toxic, a free, open source Tox-based instant messaging client.";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, CYAN, msg);
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "Type \"/help\" for assistance. Further help may be found via the man page.";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 1, CYAN, msg);
|
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "");
|
2014-07-04 09:24:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
static void prompt_init_log(ToxWindow *self, Tox *m, const char *self_name)
|
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
char myid[TOX_ADDRESS_SIZE];
|
|
|
|
tox_self_get_address(m, (uint8_t *) myid);
|
|
|
|
|
|
|
|
if (log_init(ctx->log, self->name, myid, NULL, LOG_TYPE_PROMPT) != 0) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
|
2020-11-17 22:05:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_settings->autolog == AUTOLOG_ON) {
|
|
|
|
if (log_enable(ctx->log) == -1) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Warning: Failed to enable log.");
|
2020-11-17 22:05:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 08:17:22 +01:00
|
|
|
static void prompt_onInit(ToxWindow *self, Tox *m)
|
|
|
|
{
|
|
|
|
curs_set(1);
|
2020-11-30 05:26:51 +01:00
|
|
|
|
|
|
|
int y2;
|
|
|
|
int x2;
|
2014-03-25 08:17:22 +01:00
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
exit_toxic_err("failed in prompt_onInit", FATALERR_CURSES);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2020-11-30 05:26:51 +01:00
|
|
|
|
|
|
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT - WINDOW_BAR_HEIGHT, x2, 0, 0);
|
|
|
|
self->window_bar = subwin(self->window, WINDOW_BAR_HEIGHT, x2, y2 - (CHATBOX_HEIGHT + WINDOW_BAR_HEIGHT), 0);
|
|
|
|
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - WINDOW_BAR_HEIGHT, 0);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-07-04 19:24:18 +02:00
|
|
|
ctx->log = calloc(1, sizeof(struct chatlog));
|
|
|
|
ctx->hst = calloc(1, sizeof(struct history));
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->log == NULL || ctx->hst == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in prompt_onInit", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-25 08:17:22 +01:00
|
|
|
|
|
|
|
line_info_init(ctx->hst);
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
prompt_init_log(self, m, self->name);
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
scrollok(ctx->history, 0);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (user_settings->show_welcome_msg == SHOW_WELCOME_MSG_ON) {
|
2014-09-19 07:06:18 +02:00
|
|
|
print_welcome_msg(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *new_prompt(void)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
if (ret == NULL) {
|
|
|
|
exit_toxic_err("failed in new_prompt", FATALERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->num = -1;
|
2020-11-09 23:01:22 +01:00
|
|
|
ret->type = WINDOW_TYPE_PROMPT;
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->onKey = &prompt_onKey;
|
|
|
|
ret->onDraw = &prompt_onDraw;
|
|
|
|
ret->onInit = &prompt_onInit;
|
|
|
|
ret->onConnectionChange = &prompt_onConnectionChange;
|
|
|
|
ret->onFriendRequest = &prompt_onFriendRequest;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2020-11-19 07:30:30 +01:00
|
|
|
strcpy(ret->name, "Home");
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
2013-09-13 08:02:49 +02:00
|
|
|
StatusBar *stb = calloc(1, sizeof(StatusBar));
|
2014-07-04 09:24:29 +02:00
|
|
|
Help *help = calloc(1, sizeof(Help));
|
2013-09-12 00:07:26 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (stb == NULL || chatwin == NULL || help == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in new_prompt", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-18 21:54:05 +02:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->chatwin = chatwin;
|
|
|
|
ret->stb = stb;
|
|
|
|
ret->help = help;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->active_box = -1;
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
return ret;
|
2013-12-01 22:59:46 +01:00
|
|
|
}
|