1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00
profanity/profanity.c

95 lines
2.0 KiB
C
Raw Normal View History

2012-02-09 17:24:03 -05:00
#include <string.h>
#include <unistd.h>
#include <ncurses.h>
#include "profanity.h"
2012-02-05 10:10:10 -05:00
#include "log.h"
2012-02-05 18:08:15 -05:00
#include "windows.h"
2012-02-09 17:24:03 -05:00
#include "jabber.h"
2012-02-09 18:15:53 -05:00
#include "command.h"
2012-02-09 17:24:03 -05:00
static void profanity_main(void);
2012-02-09 17:50:19 -05:00
static void profanity_event_loop(int *ch, char *cmd, int *size);
2012-02-09 17:24:03 -05:00
void profanity_start(void)
{
int cmd_result = AWAIT_COMMAND;
char cmd[50];
while (cmd_result == AWAIT_COMMAND) {
inp_get_command_str(cmd);
2012-02-09 17:50:19 -05:00
cmd_result = handle_start_command(cmd);
2012-02-09 17:24:03 -05:00
}
if (cmd_result == START_MAIN) {
profanity_main();
}
}
2012-02-09 17:50:19 -05:00
static void profanity_main(void)
{
2012-02-09 18:15:53 -05:00
int cmd_result = TRUE;
2012-02-09 17:50:19 -05:00
inp_non_block();
2012-02-09 18:15:53 -05:00
while(cmd_result == TRUE) {
2012-02-09 17:50:19 -05:00
int ch = ERR;
char cmd[100];
int size = 0;
while(ch != '\n')
profanity_event_loop(&ch, cmd, &size);
cmd[size++] = '\0';
2012-02-09 18:15:53 -05:00
cmd_result = handle_command(cmd);
2012-02-09 17:50:19 -05:00
}
jabber_disconnect();
}
static void profanity_event_loop(int *ch, char *cmd, int *size)
{
usleep(1);
2012-02-09 19:28:39 -05:00
inp_bar_update_time();
2012-02-09 17:50:19 -05:00
// handle incoming messages
jabber_process_events();
// determine if they changed windows
if (*ch == KEY_F(1)) {
2012-02-12 16:36:01 -05:00
if (is_active(0))
switch_to(0);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(2)) {
2012-02-12 16:36:01 -05:00
if (is_active(1))
switch_to(1);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(3)) {
2012-02-12 16:36:01 -05:00
if (is_active(2))
switch_to(2);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(4)) {
2012-02-12 16:36:01 -05:00
if (is_active(3))
switch_to(3);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(5)) {
2012-02-12 16:36:01 -05:00
if (is_active(4))
switch_to(4);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(6)) {
2012-02-12 16:36:01 -05:00
if (is_active(5))
switch_to(5);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(7)) {
2012-02-12 16:36:01 -05:00
if (is_active(6))
switch_to(6);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(8)) {
2012-02-12 16:36:01 -05:00
if (is_active(7))
switch_to(7);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(9)) {
2012-02-12 16:36:01 -05:00
if (is_active(8))
switch_to(8);
2012-02-09 17:50:19 -05:00
} else if (*ch == KEY_F(10)) {
2012-02-12 16:36:01 -05:00
if (is_active(9))
switch_to(9);
2012-02-09 17:50:19 -05:00
}
// get another character from the command box
inp_poll_char(ch, cmd, size);
}