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
|
|
|
|
2012-02-12 17:09:07 -05:00
|
|
|
static void _profanity_main(void);
|
|
|
|
static void _profanity_event_loop(int *ch, char *cmd, int *size);
|
2012-02-12 17:53:53 -05:00
|
|
|
static void _process_special_keys(int *ch);
|
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) {
|
2012-02-12 17:44:00 -05:00
|
|
|
title_bar_refresh();
|
2012-02-12 17:34:31 -05:00
|
|
|
status_bar_refresh();
|
2012-02-09 17:24:03 -05:00
|
|
|
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) {
|
2012-02-12 17:09:07 -05:00
|
|
|
_profanity_main();
|
2012-02-09 17:24:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-12 17:09:07 -05:00
|
|
|
static void _profanity_main(void)
|
2012-02-09 17:50:19 -05:00
|
|
|
{
|
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')
|
2012-02-12 17:09:07 -05:00
|
|
|
_profanity_event_loop(&ch, cmd, &size);
|
2012-02-09 17:50:19 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-02-12 17:09:07 -05:00
|
|
|
static void _profanity_event_loop(int *ch, char *cmd, int *size)
|
2012-02-09 17:50:19 -05:00
|
|
|
{
|
|
|
|
usleep(1);
|
2012-02-12 20:25:47 -05:00
|
|
|
gui_refresh();
|
2012-02-09 17:50:19 -05:00
|
|
|
jabber_process_events();
|
2012-02-12 17:53:53 -05:00
|
|
|
_process_special_keys(ch);
|
|
|
|
inp_poll_char(ch, cmd, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _process_special_keys(int *ch)
|
|
|
|
{
|
2012-02-09 17:50:19 -05:00
|
|
|
if (*ch == KEY_F(1)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(0))
|
|
|
|
win_switch_to(0);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(2)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(1))
|
|
|
|
win_switch_to(1);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(3)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(2))
|
|
|
|
win_switch_to(2);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(4)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(3))
|
|
|
|
win_switch_to(3);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(5)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(4))
|
|
|
|
win_switch_to(4);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(6)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(5))
|
|
|
|
win_switch_to(5);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(7)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(6))
|
|
|
|
win_switch_to(6);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(8)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(7))
|
|
|
|
win_switch_to(7);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(9)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(8))
|
|
|
|
win_switch_to(8);
|
2012-02-09 17:50:19 -05:00
|
|
|
} else if (*ch == KEY_F(10)) {
|
2012-02-12 17:09:07 -05:00
|
|
|
if (win_is_active(9))
|
|
|
|
win_switch_to(9);
|
2012-02-09 17:50:19 -05:00
|
|
|
}
|
2012-02-12 17:53:53 -05:00
|
|
|
}
|