mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 00:53:01 +01:00
partially fix bug where input line eats prompt messages
This commit is contained in:
parent
18a7bbea3d
commit
ce45580c83
@ -66,6 +66,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
wprintw(prompt->window, "%s: %s\n", nick, str);
|
||||
|
||||
prep_prompt_win();
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
@ -166,6 +167,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
|
||||
prep_prompt_win();
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
wprintw(prompt->window, "* File transfer from %s failed: too many windows are open.\n", nick);
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
@ -188,6 +190,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
|
||||
prep_prompt_win();
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
wprintw(prompt->window, "* Group chat invite from %s failed: too many windows are open.\n", nick);
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
@ -245,6 +248,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
|
||||
set_active_window(friends[f].chatwin);
|
||||
} else {
|
||||
prep_prompt_win();
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
|
@ -233,6 +233,7 @@ static void do_tox(Tox *m, ToxWindow *prompt)
|
||||
static bool dht_on = false;
|
||||
|
||||
if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) {
|
||||
prep_prompt_win();
|
||||
if (!conn_err) {
|
||||
wprintw(prompt->window, "Establishing connection...\n");
|
||||
if ((conn_err = init_connection(m)))
|
||||
@ -241,10 +242,14 @@ static void do_tox(Tox *m, ToxWindow *prompt)
|
||||
} else if (!dht_on && tox_isconnected(m)) {
|
||||
dht_on = true;
|
||||
prompt_update_connectionstatus(prompt, dht_on);
|
||||
|
||||
prep_prompt_win();
|
||||
wprintw(prompt->window, "\nDHT connected.\n");
|
||||
} else if (dht_on && !tox_isconnected(m)) {
|
||||
dht_on = false;
|
||||
prompt_update_connectionstatus(prompt, dht_on);
|
||||
|
||||
prep_prompt_win();
|
||||
wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
|
||||
}
|
||||
|
||||
@ -522,6 +527,7 @@ int main(int argc, char *argv[])
|
||||
load_data(m, DATA_FILE);
|
||||
|
||||
if (f_flag == -1) {
|
||||
prep_prompt_win();
|
||||
attron(COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
|
||||
"defaulting to 'data' for a keyfile...\n");
|
||||
@ -529,6 +535,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (config_err) {
|
||||
prep_prompt_win();
|
||||
attron(COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(prompt->window, "Unable to determine configuration directory.\n"
|
||||
"defaulting to 'data' for a keyfile...\n");
|
||||
|
@ -211,7 +211,7 @@ void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len)
|
||||
--(*len);
|
||||
}
|
||||
|
||||
/* Deletes the entire line before pos */
|
||||
/* Deletes the line from beginning to pos */
|
||||
void discard_buf(wchar_t *buf, size_t *pos, size_t *len)
|
||||
{
|
||||
if (*pos <= 0)
|
||||
@ -227,7 +227,7 @@ void discard_buf(wchar_t *buf, size_t *pos, size_t *len)
|
||||
*len = c - 1;
|
||||
}
|
||||
|
||||
/* Deletes the entire line in front of pos */
|
||||
/* Deletes the line from pos to len */
|
||||
void kill_buf(wchar_t *buf, size_t *pos, size_t *len)
|
||||
{
|
||||
if (*len == *pos)
|
||||
|
@ -50,5 +50,11 @@ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len);
|
||||
/* Deletes the character at pos */
|
||||
void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
||||
/* Deletes the line from beginning to pos */
|
||||
void discard_buf(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
||||
/* Deletes the line from pos to len */
|
||||
void kill_buf(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
||||
/* nulls buf and sets pos and len to 0 */
|
||||
void reset_buf(wchar_t *buf, size_t *pos, size_t *len);
|
||||
|
36
src/prompt.c
36
src/prompt.c
@ -16,6 +16,26 @@
|
||||
|
||||
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0};
|
||||
uint8_t num_frnd_requests = 0;
|
||||
extern ToxWindow *prompt;
|
||||
|
||||
/* prevents input string from eating system messages: call this prior to printing a prompt message
|
||||
TODO: This is only a partial fix */
|
||||
void prep_prompt_win(void)
|
||||
{
|
||||
PromptBuf *prt = prompt->promptbuf;
|
||||
|
||||
if (prt->len <= 0)
|
||||
return;
|
||||
|
||||
wprintw(prompt->window, "\n");
|
||||
|
||||
if (!prt->at_bottom) {
|
||||
wmove(prompt->window, prt->orig_y - 1, X_OFST);
|
||||
++prt->orig_y;
|
||||
} else {
|
||||
wmove(prompt->window, prt->orig_y - 2, X_OFST);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates own nick in prompt statusbar */
|
||||
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
|
||||
@ -166,14 +186,15 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
if (prt->len > 0) {
|
||||
mvwprintw(self->window, prt->orig_y, X_OFST, wcs_to_char(prt->line));
|
||||
/* y distance between pos and len */
|
||||
int d = y2 - y - 1;
|
||||
|
||||
/* 1 if end of line is touching bottom of window, 0 otherwise */
|
||||
int bot = prt->orig_y + ((prt->len + p_ofst) / px2) == y2;
|
||||
int k = prt->orig_y + ((prt->len + p_ofst) / px2);
|
||||
|
||||
prt->at_bottom = k == y2 - 1;
|
||||
bool botm = k == y2;
|
||||
bool edge = (prt->len + p_ofst) % px2 == 0;
|
||||
|
||||
/* move point of line origin up when input scrolls screen down */
|
||||
if (prt->scroll && (y + d == y2 - bot) && ((prt->len + p_ofst) % px2 == 0) ) {
|
||||
if (prt->scroll && edge && botm) {
|
||||
--prt->orig_y;
|
||||
prt->scroll = false;
|
||||
}
|
||||
@ -245,6 +266,8 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , u
|
||||
if (friendnum < 0)
|
||||
return;
|
||||
|
||||
prep_prompt_win();
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
|
||||
if (tox_get_name(m, friendnum, nick) == -1)
|
||||
@ -275,7 +298,8 @@ static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data,
|
||||
// make sure message data is null-terminated
|
||||
data[length - 1] = 0;
|
||||
|
||||
wprintw(self->window, "\nFriend request with the message: %s\n", data);
|
||||
prep_prompt_win();
|
||||
wprintw(self->window, "\nFriend request with the message: '%s'\n", data);
|
||||
|
||||
int n = add_friend_request(key);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define X_OFST 2 /* offset to account for prompt char */
|
||||
|
||||
ToxWindow new_prompt(void);
|
||||
void prep_prompt_win(void);
|
||||
void prompt_init_statusbar(ToxWindow *self, Tox *m);
|
||||
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len);
|
||||
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len);
|
||||
|
@ -117,8 +117,9 @@ struct PromptBuf {
|
||||
wchar_t line[MAX_STR_SIZE];
|
||||
size_t pos;
|
||||
size_t len;
|
||||
int orig_y; /* y axis point of origin for line */
|
||||
bool scroll; /* used for prompt window hack to determine when to scroll down */
|
||||
bool at_bottom; /* true if line end is at bottom of window */
|
||||
int orig_y; /* y axis point of line origin */
|
||||
bool scroll; /* used for prompt window hack to determine when to scroll down */
|
||||
WINDOW *linewin;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user