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

109 lines
2.7 KiB
C
Raw Normal View History

2012-02-20 15:07:38 -05:00
/*
* profanity.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
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"
#include "input_buffer.h"
2012-02-09 17:24:03 -05:00
2012-02-12 17:09:07 -05:00
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
static void profanity_init(int disable_tls)
{
jabber_init(disable_tls);
inpbuf_init();
}
void profanity_main(int disable_tls)
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
profanity_init(disable_tls);
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;
2012-02-19 20:42:29 -05:00
char inp[100];
2012-02-09 17:50:19 -05:00
int size = 0;
2012-02-19 20:42:29 -05:00
while(ch != '\n')
_profanity_event_loop(&ch, inp, &size);
2012-02-16 19:42:41 -05:00
2012-02-19 20:42:29 -05:00
inp[size++] = '\0';
cmd_result = process_input(inp);
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);
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
}