From c92b26880924c49de97d70a37620a7bec57cf32d Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 8 Feb 2012 23:12:34 +0000 Subject: [PATCH] Closing chat windows --- app.c | 17 +++++++++++++---- windows.c | 35 +++++++++++++++++++++++++++++------ windows.h | 3 +-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app.c b/app.c index f6cc32af..c1c0cc99 100644 --- a/app.c +++ b/app.c @@ -19,7 +19,6 @@ void start_profanity(void) break; } else if (strncmp(cmd, "/help", 5) == 0) { cons_help(); - cons_show(); inp_clear(); } else if (strncmp(cmd, "/connect ", 9) == 0) { char *user; @@ -35,7 +34,6 @@ void start_profanity(void) break; } else { cons_bad_command(cmd); - cons_show(); inp_clear(); } } @@ -98,15 +96,26 @@ static void main_event_loop(void) cons_help(); inp_clear(); - // send message to recipient if chat window + // /close -> close the current chat window, if in chat + } else if (strncmp(command, "/close", 6) == 0) { + if (in_chat()) { + close_win(); + } else { + cons_bad_command(command); + } + inp_clear(); + + // send message to recipient, if in chat } else { if (in_chat()) { char recipient[100] = ""; get_recipient(recipient); jabber_send(command, recipient); show_outgoing_msg("me", command); - inp_clear(); + } else { + cons_bad_command(command); } + inp_clear(); } } diff --git a/windows.c b/windows.c index fcddcb7e..983583a5 100644 --- a/windows.c +++ b/windows.c @@ -60,6 +60,23 @@ void switch_to(int i) curr_win = i; } +void close_win(void) +{ + // reset the chat win to unused + strcpy(wins[curr_win].from, ""); + wclear(wins[curr_win].win); + + // set it as inactive in the status bar + mvwaddch(inp_bar, 0, 30 + curr_win, ' '); + if (curr_win == 9) + mvwaddch(inp_bar, 0, 30 + curr_win + 1, ' '); + wrefresh(inp_bar); + + // go back to console window + touchwin(wins[0].win); + wrefresh(wins[0].win); +} + int in_chat(void) { return (curr_win != 0); @@ -213,17 +230,23 @@ void cons_help(void) waddstr(wins[0].win, "----\n"); waddstr(wins[0].win, "/quit - Quits Profanity.\n"); waddstr(wins[0].win, "/connect - Login to jabber.\n"); + + // if its the current window, draw it + if (curr_win == 0) { + touchwin(wins[0].win); + wrefresh(wins[0].win); + } } void cons_bad_command(char *cmd) { wprintw(wins[0].win, "Unknown command: %s\n", cmd); -} - -void cons_show(void) -{ - touchwin(wins[0].win); - wrefresh(wins[0].win); + + // if its the current window, draw it + if (curr_win == 0) { + touchwin(wins[0].win); + wrefresh(wins[0].win); + } } static void create_title_bar(void) diff --git a/windows.h b/windows.h index a4c089dc..3e2918fb 100644 --- a/windows.h +++ b/windows.h @@ -12,6 +12,7 @@ struct prof_win { void gui_init(void); void gui_close(void); void switch_to(int i); +void close_win(void); int in_chat(void); void get_recipient(char *recipient); void show_incomming_msg(char *from, char *message); @@ -23,7 +24,5 @@ void inp_non_block(void); void inp_get_password(char *passwd); void bar_print_message(char *msg); void cons_help(void); -void cons_show(void); -void chat_show(void); void cons_bad_command(char *cmd); #endif