1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 23:43:29 +01:00

partially fix bug where input line eats prompt messages

This commit is contained in:
Jfreegman 2013-12-06 05:07:35 -05:00
parent 18a7bbea3d
commit ce45580c83
7 changed files with 53 additions and 10 deletions

View File

@ -66,6 +66,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; nick[TOXIC_MAX_NAME_LENGTH] = '\0';
wprintw(prompt->window, "%s: %s\n", nick, str); wprintw(prompt->window, "%s: %s\n", nick, str);
prep_prompt_win();
wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wprintw(prompt->window, "* Warning: Too many windows are open.\n");
wattron(prompt->window, COLOR_PAIR(RED)); 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); tox_get_name(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; nick[TOXIC_MAX_NAME_LENGTH] = '\0';
prep_prompt_win();
wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* File transfer from %s failed: too many windows are open.\n", nick); wprintw(prompt->window, "* File transfer from %s failed: too many windows are open.\n", nick);
wattron(prompt->window, COLOR_PAIR(RED)); 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); tox_get_name(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; nick[TOXIC_MAX_NAME_LENGTH] = '\0';
prep_prompt_win();
wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Group chat invite from %s failed: too many windows are open.\n", nick); wprintw(prompt->window, "* Group chat invite from %s failed: too many windows are open.\n", nick);
wattron(prompt->window, COLOR_PAIR(RED)); 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)); friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
set_active_window(friends[f].chatwin); set_active_window(friends[f].chatwin);
} else { } else {
prep_prompt_win();
wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Warning: Too many windows are open.\n"); wprintw(prompt->window, "* Warning: Too many windows are open.\n");
wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, COLOR_PAIR(RED));

View File

@ -233,6 +233,7 @@ static void do_tox(Tox *m, ToxWindow *prompt)
static bool dht_on = false; static bool dht_on = false;
if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) { if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) {
prep_prompt_win();
if (!conn_err) { if (!conn_err) {
wprintw(prompt->window, "Establishing connection...\n"); wprintw(prompt->window, "Establishing connection...\n");
if ((conn_err = init_connection(m))) 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)) { } else if (!dht_on && tox_isconnected(m)) {
dht_on = true; dht_on = true;
prompt_update_connectionstatus(prompt, dht_on); prompt_update_connectionstatus(prompt, dht_on);
prep_prompt_win();
wprintw(prompt->window, "\nDHT connected.\n"); wprintw(prompt->window, "\nDHT connected.\n");
} else if (dht_on && !tox_isconnected(m)) { } else if (dht_on && !tox_isconnected(m)) {
dht_on = false; dht_on = false;
prompt_update_connectionstatus(prompt, dht_on); prompt_update_connectionstatus(prompt, dht_on);
prep_prompt_win();
wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
} }
@ -522,6 +527,7 @@ int main(int argc, char *argv[])
load_data(m, DATA_FILE); load_data(m, DATA_FILE);
if (f_flag == -1) { if (f_flag == -1) {
prep_prompt_win();
attron(COLOR_PAIR(RED) | A_BOLD); attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "You passed '-f' without giving an argument.\n" wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
"defaulting to 'data' for a keyfile...\n"); "defaulting to 'data' for a keyfile...\n");
@ -529,6 +535,7 @@ int main(int argc, char *argv[])
} }
if (config_err) { if (config_err) {
prep_prompt_win();
attron(COLOR_PAIR(RED) | A_BOLD); attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "Unable to determine configuration directory.\n" wprintw(prompt->window, "Unable to determine configuration directory.\n"
"defaulting to 'data' for a keyfile...\n"); "defaulting to 'data' for a keyfile...\n");

View File

@ -211,7 +211,7 @@ void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len)
--(*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) void discard_buf(wchar_t *buf, size_t *pos, size_t *len)
{ {
if (*pos <= 0) if (*pos <= 0)
@ -227,7 +227,7 @@ void discard_buf(wchar_t *buf, size_t *pos, size_t *len)
*len = c - 1; *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) void kill_buf(wchar_t *buf, size_t *pos, size_t *len)
{ {
if (*len == *pos) if (*len == *pos)

View File

@ -50,5 +50,11 @@ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len);
/* Deletes the character at pos */ /* Deletes the character at pos */
void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len); 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 */ /* nulls buf and sets pos and len to 0 */
void reset_buf(wchar_t *buf, size_t *pos, size_t *len); void reset_buf(wchar_t *buf, size_t *pos, size_t *len);

View File

@ -16,6 +16,26 @@
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0}; uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0};
uint8_t num_frnd_requests = 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 */ /* Updates own nick in prompt statusbar */
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len) 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) { if (prt->len > 0) {
mvwprintw(self->window, prt->orig_y, X_OFST, wcs_to_char(prt->line)); 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 k = prt->orig_y + ((prt->len + p_ofst) / px2);
int bot = prt->orig_y + ((prt->len + p_ofst) / px2) == y2;
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 */ /* 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->orig_y;
prt->scroll = false; prt->scroll = false;
} }
@ -245,6 +266,8 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , u
if (friendnum < 0) if (friendnum < 0)
return; return;
prep_prompt_win();
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
if (tox_get_name(m, friendnum, nick) == -1) 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 // make sure message data is null-terminated
data[length - 1] = 0; 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); int n = add_friend_request(key);

View File

@ -8,6 +8,7 @@
#define X_OFST 2 /* offset to account for prompt char */ #define X_OFST 2 /* offset to account for prompt char */
ToxWindow new_prompt(void); ToxWindow new_prompt(void);
void prep_prompt_win(void);
void prompt_init_statusbar(ToxWindow *self, Tox *m); void prompt_init_statusbar(ToxWindow *self, Tox *m);
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len); void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len);
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len); void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len);

View File

@ -117,8 +117,9 @@ struct PromptBuf {
wchar_t line[MAX_STR_SIZE]; wchar_t line[MAX_STR_SIZE];
size_t pos; size_t pos;
size_t len; size_t len;
int orig_y; /* y axis point of origin for line */ bool at_bottom; /* true if line end is at bottom of window */
bool scroll; /* used for prompt window hack to determine when to scroll down */ int orig_y; /* y axis point of line origin */
bool scroll; /* used for prompt window hack to determine when to scroll down */
WINDOW *linewin; WINDOW *linewin;
}; };