1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2015-12-06 02:13:31 +00:00
commit 82af1b2f42
3 changed files with 123 additions and 73 deletions

View File

@ -85,8 +85,7 @@ prefs_load(void)
}
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
NULL);
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
err = NULL;
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
@ -920,6 +919,25 @@ prefs_get_aliases(void)
}
}
gchar*
prefs_get_inputrc(void)
{
gchar *xdg_config = xdg_get_config_home();
GString *inputrc_file = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(inputrc_file, "/profanity/inputrc");
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
gchar *result = strdup(inputrc_file->str);
g_string_free(inputrc_file, TRUE);
return result;
}
return NULL;
}
void
_free_alias(ProfAlias *alias)
{

View File

@ -222,4 +222,6 @@ gboolean prefs_get_room_notify(const char *const roomjid);
gboolean prefs_get_room_notify_mention(const char *const roomjid);
gboolean prefs_get_room_notify_trigger(const char *const roomjid);
gchar* prefs_get_inputrc(void);
#endif

View File

@ -87,26 +87,27 @@ static void _inp_win_handle_scroll(void);
static int _inp_offset_to_col(char *str, int offset);
static void _inp_write(char *line, int offset);
static void _inp_rl_addfuncs(void);
static int _inp_rl_getc(FILE *stream);
static void _inp_rl_linehandler(char *line);
static int _inp_rl_tab_handler(int count, int key);
static int _inp_rl_clear_handler(int count, int key);
static int _inp_rl_win1_handler(int count, int key);
static int _inp_rl_win2_handler(int count, int key);
static int _inp_rl_win3_handler(int count, int key);
static int _inp_rl_win4_handler(int count, int key);
static int _inp_rl_win5_handler(int count, int key);
static int _inp_rl_win6_handler(int count, int key);
static int _inp_rl_win7_handler(int count, int key);
static int _inp_rl_win8_handler(int count, int key);
static int _inp_rl_win9_handler(int count, int key);
static int _inp_rl_win0_handler(int count, int key);
static int _inp_rl_altleft_handler(int count, int key);
static int _inp_rl_altright_handler(int count, int key);
static int _inp_rl_pageup_handler(int count, int key);
static int _inp_rl_pagedown_handler(int count, int key);
static int _inp_rl_altpageup_handler(int count, int key);
static int _inp_rl_altpagedown_handler(int count, int key);
static int _inp_rl_win_clear_handler(int count, int key);
static int _inp_rl_win_1_handler(int count, int key);
static int _inp_rl_win_2_handler(int count, int key);
static int _inp_rl_win_3_handler(int count, int key);
static int _inp_rl_win_4_handler(int count, int key);
static int _inp_rl_win_5_handler(int count, int key);
static int _inp_rl_win_6_handler(int count, int key);
static int _inp_rl_win_7_handler(int count, int key);
static int _inp_rl_win_8_handler(int count, int key);
static int _inp_rl_win_9_handler(int count, int key);
static int _inp_rl_win_0_handler(int count, int key);
static int _inp_rl_win_prev_handler(int count, int key);
static int _inp_rl_win_next_handler(int count, int key);
static int _inp_rl_win_pageup_handler(int count, int key);
static int _inp_rl_win_pagedown_handler(int count, int key);
static int _inp_rl_subwin_pageup_handler(int count, int key);
static int _inp_rl_subwin_pagedown_handler(int count, int key);
static int _inp_rl_startup_hook(void);
void
@ -120,6 +121,7 @@ create_input_window(void)
discard = fopen("/dev/null", "a");
rl_outstream = discard;
rl_readline_name = "profanity";
_inp_rl_addfuncs();
rl_getc_function = _inp_rl_getc;
rl_startup_hook = _inp_rl_startup_hook;
rl_callback_handler_install(NULL, _inp_rl_linehandler);
@ -341,56 +343,77 @@ _inp_win_handle_scroll(void)
}
}
static void
_inp_rl_addfuncs(void)
{
rl_add_funmap_entry("prof_win_1", _inp_rl_win_1_handler);
rl_add_funmap_entry("prof_win_2", _inp_rl_win_2_handler);
rl_add_funmap_entry("prof_win_3", _inp_rl_win_3_handler);
rl_add_funmap_entry("prof_win_4", _inp_rl_win_4_handler);
rl_add_funmap_entry("prof_win_5", _inp_rl_win_5_handler);
rl_add_funmap_entry("prof_win_6", _inp_rl_win_6_handler);
rl_add_funmap_entry("prof_win_7", _inp_rl_win_7_handler);
rl_add_funmap_entry("prof_win_8", _inp_rl_win_8_handler);
rl_add_funmap_entry("prof_win_9", _inp_rl_win_9_handler);
rl_add_funmap_entry("prof_win_0", _inp_rl_win_0_handler);
rl_add_funmap_entry("prof_win_prev", _inp_rl_win_prev_handler);
rl_add_funmap_entry("prof_win_next", _inp_rl_win_next_handler);
rl_add_funmap_entry("prof_win_pageup", _inp_rl_win_pageup_handler);
rl_add_funmap_entry("prof_win_pagedown", _inp_rl_win_pagedown_handler);
rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler);
rl_add_funmap_entry("prof_subwin_pagedown", _inp_rl_subwin_pagedown_handler);
rl_add_funmap_entry("prof_win_clear", _inp_rl_win_clear_handler);
}
// Readline callbacks
static int
_inp_rl_startup_hook(void)
{
rl_bind_keyseq("\\e1", _inp_rl_win1_handler);
rl_bind_keyseq("\\e2", _inp_rl_win2_handler);
rl_bind_keyseq("\\e3", _inp_rl_win3_handler);
rl_bind_keyseq("\\e4", _inp_rl_win4_handler);
rl_bind_keyseq("\\e5", _inp_rl_win5_handler);
rl_bind_keyseq("\\e6", _inp_rl_win6_handler);
rl_bind_keyseq("\\e7", _inp_rl_win7_handler);
rl_bind_keyseq("\\e8", _inp_rl_win8_handler);
rl_bind_keyseq("\\e9", _inp_rl_win9_handler);
rl_bind_keyseq("\\e0", _inp_rl_win0_handler);
rl_bind_keyseq("\\e1", _inp_rl_win_1_handler);
rl_bind_keyseq("\\e2", _inp_rl_win_2_handler);
rl_bind_keyseq("\\e3", _inp_rl_win_3_handler);
rl_bind_keyseq("\\e4", _inp_rl_win_4_handler);
rl_bind_keyseq("\\e5", _inp_rl_win_5_handler);
rl_bind_keyseq("\\e6", _inp_rl_win_6_handler);
rl_bind_keyseq("\\e7", _inp_rl_win_7_handler);
rl_bind_keyseq("\\e8", _inp_rl_win_8_handler);
rl_bind_keyseq("\\e9", _inp_rl_win_9_handler);
rl_bind_keyseq("\\e0", _inp_rl_win_0_handler);
rl_bind_keyseq("\\eOP", _inp_rl_win1_handler);
rl_bind_keyseq("\\eOQ", _inp_rl_win2_handler);
rl_bind_keyseq("\\eOR", _inp_rl_win3_handler);
rl_bind_keyseq("\\eOS", _inp_rl_win4_handler);
rl_bind_keyseq("\\e[15~", _inp_rl_win5_handler);
rl_bind_keyseq("\\e[17~", _inp_rl_win6_handler);
rl_bind_keyseq("\\e[18~", _inp_rl_win7_handler);
rl_bind_keyseq("\\e[19~", _inp_rl_win8_handler);
rl_bind_keyseq("\\e[20~", _inp_rl_win9_handler);
rl_bind_keyseq("\\e[21~", _inp_rl_win0_handler);
rl_bind_keyseq("\\eOP", _inp_rl_win_1_handler);
rl_bind_keyseq("\\eOQ", _inp_rl_win_2_handler);
rl_bind_keyseq("\\eOR", _inp_rl_win_3_handler);
rl_bind_keyseq("\\eOS", _inp_rl_win_4_handler);
rl_bind_keyseq("\\e[15~", _inp_rl_win_5_handler);
rl_bind_keyseq("\\e[17~", _inp_rl_win_6_handler);
rl_bind_keyseq("\\e[18~", _inp_rl_win_7_handler);
rl_bind_keyseq("\\e[19~", _inp_rl_win_8_handler);
rl_bind_keyseq("\\e[20~", _inp_rl_win_9_handler);
rl_bind_keyseq("\\e[21~", _inp_rl_win_0_handler);
rl_bind_keyseq("\\e[1;9D", _inp_rl_altleft_handler);
rl_bind_keyseq("\\e[1;3D", _inp_rl_altleft_handler);
rl_bind_keyseq("\\e\\e[D", _inp_rl_altleft_handler);
rl_bind_keyseq("\\e[1;9D", _inp_rl_win_prev_handler);
rl_bind_keyseq("\\e[1;3D", _inp_rl_win_prev_handler);
rl_bind_keyseq("\\e\\e[D", _inp_rl_win_prev_handler);
rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler);
rl_bind_keyseq("\\e[1;3C", _inp_rl_altright_handler);
rl_bind_keyseq("\\e\\e[C", _inp_rl_altright_handler);
rl_bind_keyseq("\\e[1;9C", _inp_rl_win_next_handler);
rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler);
rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler);
rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler);
rl_bind_keyseq("\\e[5;3~", _inp_rl_altpageup_handler);
rl_bind_keyseq("\\e\\eOy", _inp_rl_altpageup_handler);
rl_bind_keyseq("\\e\\e[5~", _inp_rl_subwin_pageup_handler);
rl_bind_keyseq("\\e[5;3~", _inp_rl_subwin_pageup_handler);
rl_bind_keyseq("\\e\\eOy", _inp_rl_subwin_pageup_handler);
rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler);
rl_bind_keyseq("\\e[6;3~", _inp_rl_altpagedown_handler);
rl_bind_keyseq("\\e\\eOs", _inp_rl_altpagedown_handler);
rl_bind_keyseq("\\e\\e[6~", _inp_rl_subwin_pagedown_handler);
rl_bind_keyseq("\\e[6;3~", _inp_rl_subwin_pagedown_handler);
rl_bind_keyseq("\\e\\eOs", _inp_rl_subwin_pagedown_handler);
rl_bind_keyseq("\\e[5~", _inp_rl_pageup_handler);
rl_bind_keyseq("\\eOy", _inp_rl_pageup_handler);
rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler);
rl_bind_keyseq("\\eOs", _inp_rl_pagedown_handler);
rl_bind_keyseq("\\e[5~", _inp_rl_win_pageup_handler);
rl_bind_keyseq("\\eOy", _inp_rl_win_pageup_handler);
rl_bind_keyseq("\\e[6~", _inp_rl_win_pagedown_handler);
rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);
rl_bind_key('\t', _inp_rl_tab_handler);
rl_bind_key(CTRL('L'), _inp_rl_clear_handler);
// unbind unwanted mappings
rl_bind_keyseq("\\e=", NULL);
@ -398,6 +421,13 @@ _inp_rl_startup_hook(void)
// disable readline completion
rl_variable_bind("disable-completion", "on");
// check for and load ~/.config/profanity/inputrc
char *inputrc = prefs_get_inputrc();
if (inputrc) {
rl_read_init_file(inputrc);
free(inputrc);
}
return 0;
}
@ -424,7 +454,7 @@ _inp_rl_getc(FILE *stream)
}
static int
_inp_rl_clear_handler(int count, int key)
_inp_rl_win_clear_handler(int count, int key)
{
ProfWin *win = wins_get_current();
win_clear(win);
@ -469,77 +499,77 @@ _go_to_win(int i)
}
static int
_inp_rl_win1_handler(int count, int key)
_inp_rl_win_1_handler(int count, int key)
{
_go_to_win(1);
return 0;
}
static int
_inp_rl_win2_handler(int count, int key)
_inp_rl_win_2_handler(int count, int key)
{
_go_to_win(2);
return 0;
}
static int
_inp_rl_win3_handler(int count, int key)
_inp_rl_win_3_handler(int count, int key)
{
_go_to_win(3);
return 0;
}
static int
_inp_rl_win4_handler(int count, int key)
_inp_rl_win_4_handler(int count, int key)
{
_go_to_win(4);
return 0;
}
static int
_inp_rl_win5_handler(int count, int key)
_inp_rl_win_5_handler(int count, int key)
{
_go_to_win(5);
return 0;
}
static int
_inp_rl_win6_handler(int count, int key)
_inp_rl_win_6_handler(int count, int key)
{
_go_to_win(6);
return 0;
}
static int
_inp_rl_win7_handler(int count, int key)
_inp_rl_win_7_handler(int count, int key)
{
_go_to_win(7);
return 0;
}
static int
_inp_rl_win8_handler(int count, int key)
_inp_rl_win_8_handler(int count, int key)
{
_go_to_win(8);
return 0;
}
static int
_inp_rl_win9_handler(int count, int key)
_inp_rl_win_9_handler(int count, int key)
{
_go_to_win(9);
return 0;
}
static int
_inp_rl_win0_handler(int count, int key)
_inp_rl_win_0_handler(int count, int key)
{
_go_to_win(0);
return 0;
}
static int
_inp_rl_altleft_handler(int count, int key)
_inp_rl_win_prev_handler(int count, int key)
{
ProfWin *window = wins_get_previous();
if (window) {
@ -549,7 +579,7 @@ _inp_rl_altleft_handler(int count, int key)
}
static int
_inp_rl_altright_handler(int count, int key)
_inp_rl_win_next_handler(int count, int key)
{
ProfWin *window = wins_get_next();
if (window) {
@ -559,7 +589,7 @@ _inp_rl_altright_handler(int count, int key)
}
static int
_inp_rl_pageup_handler(int count, int key)
_inp_rl_win_pageup_handler(int count, int key)
{
ProfWin *current = wins_get_current();
win_page_up(current);
@ -567,7 +597,7 @@ _inp_rl_pageup_handler(int count, int key)
}
static int
_inp_rl_pagedown_handler(int count, int key)
_inp_rl_win_pagedown_handler(int count, int key)
{
ProfWin *current = wins_get_current();
win_page_down(current);
@ -575,7 +605,7 @@ _inp_rl_pagedown_handler(int count, int key)
}
static int
_inp_rl_altpageup_handler(int count, int key)
_inp_rl_subwin_pageup_handler(int count, int key)
{
ProfWin *current = wins_get_current();
win_sub_page_up(current);
@ -583,7 +613,7 @@ _inp_rl_altpageup_handler(int count, int key)
}
static int
_inp_rl_altpagedown_handler(int count, int key)
_inp_rl_subwin_pagedown_handler(int count, int key)
{
ProfWin *current = wins_get_current();
win_sub_page_down(current);