0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-05 17:28:00 -04:00

Closing chat windows

This commit is contained in:
James Booth 2012-02-08 23:12:34 +00:00
parent 8c24a7c475
commit c92b268809
3 changed files with 43 additions and 12 deletions

17
app.c
View File

@ -19,7 +19,6 @@ void start_profanity(void)
break; break;
} else if (strncmp(cmd, "/help", 5) == 0) { } else if (strncmp(cmd, "/help", 5) == 0) {
cons_help(); cons_help();
cons_show();
inp_clear(); inp_clear();
} else if (strncmp(cmd, "/connect ", 9) == 0) { } else if (strncmp(cmd, "/connect ", 9) == 0) {
char *user; char *user;
@ -35,7 +34,6 @@ void start_profanity(void)
break; break;
} else { } else {
cons_bad_command(cmd); cons_bad_command(cmd);
cons_show();
inp_clear(); inp_clear();
} }
} }
@ -98,15 +96,26 @@ static void main_event_loop(void)
cons_help(); cons_help();
inp_clear(); 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 { } else {
if (in_chat()) { if (in_chat()) {
char recipient[100] = ""; char recipient[100] = "";
get_recipient(recipient); get_recipient(recipient);
jabber_send(command, recipient); jabber_send(command, recipient);
show_outgoing_msg("me", command); show_outgoing_msg("me", command);
inp_clear(); } else {
cons_bad_command(command);
} }
inp_clear();
} }
} }

View File

@ -60,6 +60,23 @@ void switch_to(int i)
curr_win = 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) int in_chat(void)
{ {
return (curr_win != 0); return (curr_win != 0);
@ -213,17 +230,23 @@ void cons_help(void)
waddstr(wins[0].win, "----\n"); waddstr(wins[0].win, "----\n");
waddstr(wins[0].win, "/quit - Quits Profanity.\n"); waddstr(wins[0].win, "/quit - Quits Profanity.\n");
waddstr(wins[0].win, "/connect <username@host> - Login to jabber.\n"); waddstr(wins[0].win, "/connect <username@host> - 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) void cons_bad_command(char *cmd)
{ {
wprintw(wins[0].win, "Unknown command: %s\n", cmd); wprintw(wins[0].win, "Unknown command: %s\n", cmd);
}
void cons_show(void) // if its the current window, draw it
{ if (curr_win == 0) {
touchwin(wins[0].win); touchwin(wins[0].win);
wrefresh(wins[0].win); wrefresh(wins[0].win);
}
} }
static void create_title_bar(void) static void create_title_bar(void)

View File

@ -12,6 +12,7 @@ struct prof_win {
void gui_init(void); void gui_init(void);
void gui_close(void); void gui_close(void);
void switch_to(int i); void switch_to(int i);
void close_win(void);
int in_chat(void); int in_chat(void);
void get_recipient(char *recipient); void get_recipient(char *recipient);
void show_incomming_msg(char *from, char *message); void show_incomming_msg(char *from, char *message);
@ -23,7 +24,5 @@ void inp_non_block(void);
void inp_get_password(char *passwd); void inp_get_password(char *passwd);
void bar_print_message(char *msg); void bar_print_message(char *msg);
void cons_help(void); void cons_help(void);
void cons_show(void);
void chat_show(void);
void cons_bad_command(char *cmd); void cons_bad_command(char *cmd);
#endif #endif