mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added msg command
This commit is contained in:
parent
d77c397b18
commit
4148f05307
2
README
2
README
@ -15,7 +15,6 @@ WORKLIST:
|
|||||||
Features:
|
Features:
|
||||||
Show login attempts in console
|
Show login attempts in console
|
||||||
Show roster on login
|
Show roster on login
|
||||||
Add /msg command
|
|
||||||
Handle resize terminal in X windows
|
Handle resize terminal in X windows
|
||||||
Secure XMPP
|
Secure XMPP
|
||||||
Window buffers for scrolling, with page up and down
|
Window buffers for scrolling, with page up and down
|
||||||
@ -30,3 +29,4 @@ One day:
|
|||||||
Other IM protocols
|
Other IM protocols
|
||||||
Log chat history to file option
|
Log chat history to file option
|
||||||
Tab completion on commands
|
Tab completion on commands
|
||||||
|
Tab completion on users
|
||||||
|
21
app.c
21
app.c
@ -101,6 +101,25 @@ static void main_event_loop(void)
|
|||||||
jabber_roster_request();
|
jabber_roster_request();
|
||||||
inp_clear();
|
inp_clear();
|
||||||
|
|
||||||
|
// /msg -> send message to a user
|
||||||
|
} else if (strncmp(command, "/msg ", 5) == 0) {
|
||||||
|
char *usr_msg = NULL;
|
||||||
|
char *usr = NULL;
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
|
usr_msg = strndup(command+5, strlen(command)-5);
|
||||||
|
cons_show(usr_msg);
|
||||||
|
|
||||||
|
usr = strtok(usr_msg, " ");
|
||||||
|
if (usr != NULL) {
|
||||||
|
msg = strndup(command+5+strlen(usr)+1, strlen(command)-(5+strlen(usr)+1));
|
||||||
|
if (msg != NULL) {
|
||||||
|
jabber_send(msg, usr);
|
||||||
|
show_outgoing_msg("me", usr, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inp_clear();
|
||||||
|
|
||||||
// /close -> close the current chat window, if in chat
|
// /close -> close the current chat window, if in chat
|
||||||
} else if (strncmp(command, "/close", 6) == 0) {
|
} else if (strncmp(command, "/close", 6) == 0) {
|
||||||
if (in_chat()) {
|
if (in_chat()) {
|
||||||
@ -116,7 +135,7 @@ static void main_event_loop(void)
|
|||||||
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", recipient, command);
|
||||||
} else {
|
} else {
|
||||||
cons_bad_command(command);
|
cons_bad_command(command);
|
||||||
}
|
}
|
||||||
|
@ -15,3 +15,11 @@ void create_title_bar(void)
|
|||||||
mvwprintw(title_bar, 0, 0, title);
|
mvwprintw(title_bar, 0, 0, title);
|
||||||
wrefresh(title_bar);
|
wrefresh(title_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void title_bar_show(char *title)
|
||||||
|
{
|
||||||
|
wclear(title_bar);
|
||||||
|
mvwprintw(title_bar, 0, 0, title);
|
||||||
|
wrefresh(title_bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
54
windows.c
54
windows.c
@ -44,6 +44,8 @@ void switch_to(int i)
|
|||||||
touchwin(wins[i].win);
|
touchwin(wins[i].win);
|
||||||
wrefresh(wins[i].win);
|
wrefresh(wins[i].win);
|
||||||
curr_win = i;
|
curr_win = i;
|
||||||
|
|
||||||
|
title_bar_show(wins[i].from);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_win(void)
|
void close_win(void)
|
||||||
@ -76,7 +78,7 @@ void show_incomming_msg(char *from, char *message)
|
|||||||
strcpy(from_cpy, from);
|
strcpy(from_cpy, from);
|
||||||
|
|
||||||
char line[100];
|
char line[100];
|
||||||
char *short_from = strtok(from_cpy, "@");
|
char *short_from = strtok(from_cpy, "/");
|
||||||
char tstmp[80];
|
char tstmp[80];
|
||||||
get_time(tstmp);
|
get_time(tstmp);
|
||||||
|
|
||||||
@ -85,7 +87,7 @@ void show_incomming_msg(char *from, char *message)
|
|||||||
// find the chat window for sender
|
// find the chat window for sender
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < 10; i++)
|
for (i = 1; i < 10; i++)
|
||||||
if (strcmp(wins[i].from, from) == 0)
|
if (strcmp(wins[i].from, short_from) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// if we didn't find a window
|
// if we didn't find a window
|
||||||
@ -96,7 +98,7 @@ void show_incomming_msg(char *from, char *message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// set it up and print the message to it
|
// set it up and print the message to it
|
||||||
strcpy(wins[i].from, from);
|
strcpy(wins[i].from, short_from);
|
||||||
wclear(wins[i].win);
|
wclear(wins[i].win);
|
||||||
wprintw(wins[i].win, line);
|
wprintw(wins[i].win, line);
|
||||||
|
|
||||||
@ -125,16 +127,54 @@ void show_incomming_msg(char *from, char *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_outgoing_msg(char *from, char* message)
|
void show_outgoing_msg(char *from, char *to, char *message)
|
||||||
{
|
{
|
||||||
char line[100];
|
char line[100];
|
||||||
char tstmp[80];
|
char tstmp[80];
|
||||||
get_time(tstmp);
|
get_time(tstmp);
|
||||||
sprintf(line, " [%s] %s: %s\n", tstmp, from, message);
|
sprintf(line, " [%s] %s: %s\n", tstmp, from, message);
|
||||||
|
|
||||||
wprintw(wins[curr_win].win, line);
|
// find the chat window for recipient
|
||||||
touchwin(wins[curr_win].win);
|
int i;
|
||||||
wrefresh(wins[curr_win].win);
|
for (i = 1; i < 10; i++)
|
||||||
|
if (strcmp(wins[i].from, to) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if we didn't find a window
|
||||||
|
if (i == 10) {
|
||||||
|
// find the first unused one
|
||||||
|
for (i = 1; i < 10; i++)
|
||||||
|
if (strcmp(wins[i].from, "") == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// set it up and print the message to it
|
||||||
|
strcpy(wins[i].from, to);
|
||||||
|
wclear(wins[i].win);
|
||||||
|
wprintw(wins[i].win, line);
|
||||||
|
|
||||||
|
// signify active window in status bar
|
||||||
|
inp_bar_active(i);
|
||||||
|
|
||||||
|
// if its the current window, draw it
|
||||||
|
if (curr_win == i) {
|
||||||
|
touchwin(wins[i].win);
|
||||||
|
wrefresh(wins[i].win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// otherwise
|
||||||
|
else {
|
||||||
|
// add the line to the senders window
|
||||||
|
wprintw(wins[i].win, line);
|
||||||
|
|
||||||
|
// signify active window in status bar
|
||||||
|
inp_bar_active(i);
|
||||||
|
|
||||||
|
// if its the current window, draw it
|
||||||
|
if (curr_win == i) {
|
||||||
|
touchwin(wins[i].win);
|
||||||
|
wrefresh(wins[i].win);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cons_help(void)
|
void cons_help(void)
|
||||||
|
@ -27,12 +27,13 @@ void inp_bar_print_message(char *msg);
|
|||||||
|
|
||||||
void gui_init(void);
|
void gui_init(void);
|
||||||
void gui_close(void);
|
void gui_close(void);
|
||||||
|
void title_bar_show(char *title);
|
||||||
void switch_to(int i);
|
void switch_to(int i);
|
||||||
void close_win(void);
|
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);
|
||||||
void show_outgoing_msg(char *from, char *message);
|
void show_outgoing_msg(char *from, char *to, char *message);
|
||||||
void cons_help(void);
|
void cons_help(void);
|
||||||
void cons_bad_command(char *cmd);
|
void cons_bad_command(char *cmd);
|
||||||
void cons_show(char *cmd);
|
void cons_show(char *cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user