From 986ccff8851a36a03b41fc407d3c579dd55273f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 9 Jun 2017 21:54:52 +0200 Subject: [PATCH] fset: add keys F11/F12 to scroll fset buffer horizontally, add input "<" and ">", add option fset.look.scroll_horizontal --- src/plugins/fset/fset-buffer.c | 40 ++++++++++++----------- src/plugins/fset/fset-command.c | 57 +++++++++++++++++++++++++++++++++ src/plugins/fset/fset-config.c | 9 ++++++ src/plugins/fset/fset-config.h | 1 + 4 files changed, 89 insertions(+), 18 deletions(-) diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index bbb05b5f9..379a65d19 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -805,7 +805,9 @@ fset_buffer_input_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *input_data) { - char *actions[][2] = { { "t", "toggle" }, + char *actions[][2] = { { "<", "left" }, + { ">", "right" }, + { "t", "toggle" }, { "-", "add -1" }, { "+", "add 1" }, { "r", "reset" }, @@ -928,26 +930,28 @@ fset_buffer_set_callbacks () void fset_buffer_set_keys () { - char *keys[][2] = { { "meta-meta2-1~", "go 0" }, - { "meta-meta2-4~", "go end" }, - { "meta- ", "toggle" }, - { "meta--", "add -1" }, - { "meta-+", "add 1" }, - { "meta-fmeta-r", "reset" }, - { "meta-fmeta-u", "unset" }, - { "meta-ctrl-J", "set" }, - { "meta-ctrl-M", "set" }, - { "meta-fmeta-a", "append" }, - { "meta-,", "mark 1" }, - { "meta2-a", "mark -1" }, - { "meta2-b", "mark 1" }, - { "meta-v", "toggle_bar" }, - { NULL, NULL } }; + char *keys[][2] = { { "meta2-A", "up" }, + { "meta2-B", "down" }, + { "meta-meta2-1~", "go 0" }, + { "meta-meta2-4~", "go end" }, + { "meta2-23~", "left" }, + { "meta2-24~", "right" }, + { "meta- ", "toggle" }, + { "meta--", "add -1" }, + { "meta-+", "add 1" }, + { "meta-fmeta-r", "reset" }, + { "meta-fmeta-u", "unset" }, + { "meta-ctrl-J", "set" }, + { "meta-ctrl-M", "set" }, + { "meta-fmeta-a", "append" }, + { "meta-,", "mark 1" }, + { "meta2-a", "mark -1" }, + { "meta2-b", "mark 1" }, + { "meta-v", "toggle_bar" }, + { NULL, NULL } }; char str_key[64], str_command[64]; int i; - weechat_buffer_set (fset_buffer, "key_bind_meta2-A", "/fset -up"); - weechat_buffer_set (fset_buffer, "key_bind_meta2-B", "/fset -down"); for (i = 0; keys[i][0]; i++) { if (weechat_config_boolean (fset_config_look_use_keys)) diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index ecbf8ba5d..7772f0730 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -82,8 +82,10 @@ fset_command_fset (const void *pointer, void *data, char **argv, char **argv_eol) { int num_options, line, append, value, i; + char str_command[512]; struct t_fset_option *ptr_fset_option; struct t_config_option *ptr_option; + struct t_gui_window *ptr_window; /* make C compiler happy */ (void) pointer; @@ -166,6 +168,54 @@ fset_command_fset (const void *pointer, void *data, return WEECHAT_RC_OK; } + if (weechat_strcasecmp (argv[1], "-left") == 0) + { + if (fset_buffer) + { + ptr_window = weechat_window_search_with_buffer (fset_buffer); + if (ptr_window) + { + value = fset_command_get_int_arg ( + argc, argv, 2, + weechat_config_integer (fset_config_look_scroll_horizontal)); + if (value < 1) + value = 1; + else if (value > 100) + value = 100; + snprintf (str_command, sizeof (str_command), + "/window scroll_horiz -window %d -%d%%", + weechat_window_get_integer (ptr_window, "number"), + value); + weechat_command (fset_buffer, str_command); + } + } + return WEECHAT_RC_OK; + } + + if (weechat_strcasecmp (argv[1], "-right") == 0) + { + if (fset_buffer) + { + ptr_window = weechat_window_search_with_buffer (fset_buffer); + if (ptr_window) + { + value = fset_command_get_int_arg ( + argc, argv, 2, + weechat_config_integer (fset_config_look_scroll_horizontal)); + if (value < 1) + value = 1; + else if (value > 100) + value = 100; + snprintf (str_command, sizeof (str_command), + "/window scroll_horiz -window %d %d%%", + weechat_window_get_integer (ptr_window, "number"), + value); + weechat_command (fset_buffer, str_command); + } + } + return WEECHAT_RC_OK; + } + if (weechat_strcasecmp (argv[1], "-go") == 0) { if (fset_buffer) @@ -470,6 +520,7 @@ fset_command_init () " || -toggle_bar" " || -refresh" " || -up|-down []" + " || -left|-right []" " || -go |end" " || -toggle" " || -add []" @@ -484,6 +535,10 @@ fset_command_init () " -refresh: force the refresh of the \"fset\" bar item\n" " -up: move the selected line up by \"number\" lines\n" " -down: move the selected line down by \"number\" lines\n" + " -left: scroll the fset buffer by \"percent\" of width " + "on the left\n" + " -right: scroll the fset buffer by \"percent\" of width " + "on the right\n" " -go: select a line by number, first line number is 0 " "(\"end\" to select the last line)\n" " -toggle: toggle the boolean value\n" @@ -597,6 +652,8 @@ fset_command_init () " || -refresh" " || -up 1|2|3|4|5" " || -down 1|2|3|4|5" + " || -left 10|20|30|40|50|60|70|80|90|100" + " || -right 10|20|30|40|50|60|70|80|90|100" " || -go" " || -toggle" " || -add -1|1" diff --git a/src/plugins/fset/fset-config.c b/src/plugins/fset/fset-config.c index 0b69d68b6..5dac8c165 100644 --- a/src/plugins/fset/fset-config.c +++ b/src/plugins/fset/fset-config.c @@ -37,6 +37,7 @@ struct t_config_file *fset_config_file = NULL; struct t_config_option *fset_config_look_auto_unmark; struct t_config_option *fset_config_look_condition_catch_set; struct t_config_option *fset_config_look_marked_string; +struct t_config_option *fset_config_look_scroll_horizontal; struct t_config_option *fset_config_look_show_help_bar; struct t_config_option *fset_config_look_show_plugin_description; struct t_config_option *fset_config_look_sort; @@ -322,6 +323,14 @@ fset_config_init () NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + fset_config_look_scroll_horizontal = weechat_config_new_option ( + fset_config_file, ptr_section, + "scroll_horizontal", "integer", + N_("left/right scroll in fset buffer (percent of width)"), + NULL, 1, 100, "10", NULL, 0, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); fset_config_look_show_help_bar = weechat_config_new_option ( fset_config_file, ptr_section, "show_help_bar", "boolean", diff --git a/src/plugins/fset/fset-config.h b/src/plugins/fset/fset-config.h index 14905d9bc..184992f87 100644 --- a/src/plugins/fset/fset-config.h +++ b/src/plugins/fset/fset-config.h @@ -27,6 +27,7 @@ extern struct t_config_file *fset_config_file; extern struct t_config_option *fset_config_look_auto_unmark; extern struct t_config_option *fset_config_look_condition_catch_set; extern struct t_config_option *fset_config_look_marked_string; +extern struct t_config_option *fset_config_look_scroll_horizontal; extern struct t_config_option *fset_config_look_show_help_bar; extern struct t_config_option *fset_config_look_show_plugin_description; extern struct t_config_option *fset_config_look_sort;