From 0468c5d912fc8a89bd552611ef6243bd1c889df7 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Wed, 13 Sep 2017 13:58:00 +0200 Subject: add new function to set the position in bytes fixes #752 --- src/fe-text/gui-entry.c | 20 ++++++++++++++++++++ src/fe-text/gui-entry.h | 1 + src/fe-text/gui-readline.c | 6 ++---- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index f05decd2..e91fcfb3 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -936,6 +936,26 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos) gui_entry_draw(entry); } +void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes) +{ + int pos; + const char *ptr; + + g_return_if_fail(entry != NULL); + + gui_entry_set_text(entry, str); + + if (entry->utf8) { + g_utf8_validate(str, pos_bytes, &ptr); + pos = g_utf8_pointer_to_offset(str, ptr); + } else if (term_type == TERM_TYPE_BIG5) + pos = strlen_big5((const unsigned char *)str) - strlen_big5((const unsigned char *)(str + pos_bytes)); + else + pos = pos_bytes; + + gui_entry_set_pos(entry, pos); +} + void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos) { g_return_if_fail(entry != NULL); diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h index 8777f083..000c5f03 100644 --- a/src/fe-text/gui-entry.h +++ b/src/fe-text/gui-entry.h @@ -50,6 +50,7 @@ void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8); void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str); char *gui_entry_get_text(GUI_ENTRY_REC *entry); char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos); +void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes); void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str); void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr); diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 2c2eac21..3688f15e 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -878,8 +878,7 @@ static void key_completion(int erase, int backward) g_free(text); if (line != NULL) { - gui_entry_set_text(active_entry, line); - gui_entry_set_pos(active_entry, pos); + gui_entry_set_text_and_pos_bytes(active_entry, line, pos); g_free(line); } } @@ -909,8 +908,7 @@ static void key_check_replaces(void) g_free(text); if (line != NULL) { - gui_entry_set_text(active_entry, line); - gui_entry_set_pos(active_entry, pos); + gui_entry_set_text_and_pos_bytes(active_entry, line, pos); g_free(line); } } -- cgit v1.2.3 From 1fd285dccfd43b740e88f7f4e168132387d39843 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 6 Oct 2017 14:58:47 +0200 Subject: refactor history to use history_entries list this allows access to the global history even when a using /window history named or /set window_history on, and you want to recall something from one of the other windows' histories. usage (default): ctrl+up/down --- src/fe-text/gui-readline.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/fe-text') diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 3688f15e..0528ed94 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -530,6 +530,28 @@ static void key_forward_history(void) g_free(line); } +static void key_backward_global_history(void) +{ + const char *text; + char *line; + + line = gui_entry_get_text(active_entry); + text = command_global_history_prev(active_win, line); + gui_entry_set_text(active_entry, text); + g_free(line); +} + +static void key_forward_global_history(void) +{ + const char *text; + char *line; + + line = gui_entry_get_text(active_entry); + text = command_global_history_next(active_win, line); + gui_entry_set_text(active_entry, text); + g_free(line); +} + static void key_beginning_of_line(void) { gui_entry_set_pos(active_entry, 0); @@ -1176,6 +1198,8 @@ void gui_readline_init(void) key_bind("key", NULL, "meta2-5C", "cright", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-1;5D", "cleft", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-1;5C", "cright", (SIGNAL_FUNC) key_combo); + key_bind("key", NULL, "meta2-1;5A", "cup", (SIGNAL_FUNC) key_combo); + key_bind("key", NULL, "meta2-1;5B", "cdown", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-1;3A", "mup", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-1;3B", "mdown", (SIGNAL_FUNC) key_combo); @@ -1217,6 +1241,8 @@ void gui_readline_init(void) /* history */ key_bind("backward_history", "Go back one line in the history", "up", NULL, (SIGNAL_FUNC) key_backward_history); key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history); + key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history); + key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history); /* line editing */ key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace); @@ -1310,6 +1336,8 @@ void gui_readline_deinit(void) key_unbind("backward_history", (SIGNAL_FUNC) key_backward_history); key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history); + key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history); + key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history); key_unbind("backspace", (SIGNAL_FUNC) key_backspace); key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character); -- cgit v1.2.3 From deac66f33c0fb1d6914d15ce63bde3f030a9c06d Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 6 Oct 2017 15:31:52 +0200 Subject: add a key binding to erase history entries it is possible to delete the current history entry using the erase_history_entry key binding --- src/fe-text/gui-readline.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/fe-text') diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 0528ed94..b3a78396 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -552,6 +552,17 @@ static void key_forward_global_history(void) g_free(line); } +static void key_erase_history_entry(void) +{ + const char *text; + char *line; + + line = gui_entry_get_text(active_entry); + text = command_history_delete_current(active_win, line); + gui_entry_set_text(active_entry, text); + g_free(line); +} + static void key_beginning_of_line(void) { gui_entry_set_pos(active_entry, 0); @@ -1243,6 +1254,7 @@ void gui_readline_init(void) key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history); key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history); key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history); + key_bind("erase_history_entry", "Erase the currently active entry from the history", NULL, NULL, (SIGNAL_FUNC) key_erase_history_entry); /* line editing */ key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace); @@ -1338,6 +1350,7 @@ void gui_readline_deinit(void) key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history); key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history); key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history); + key_unbind("erase_history_entry", (SIGNAL_FUNC) key_erase_history_entry); key_unbind("backspace", (SIGNAL_FUNC) key_backspace); key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character); -- cgit v1.2.3 From b0fa4dd46d8bf1cf63880fabf2105dd9134100df Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Wed, 1 Nov 2017 15:48:35 +0100 Subject: show initial nick and name on first start --- src/fe-text/irssi.c | 49 ++++++++++++++++++++++---------------------- src/fe-text/module-formats.c | 21 +++++++++++++++++++ src/fe-text/module-formats.h | 6 ++++++ 3 files changed, 52 insertions(+), 24 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index b5df47c9..6349ae2a 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -31,6 +31,7 @@ #include "printtext.h" #include "fe-common-core.h" +#include "fe-settings.h" #include "themes.h" #include "term.h" @@ -79,25 +80,8 @@ static int dirty, full_redraw; static GMainLoop *main_loop; int quitting; -static const char *banner_text = - " ___ _\n" - "|_ _|_ _ _____(_)\n" - " | || '_(_-<_-< |\n" - "|___|_| /__/__/_|\n" - "Irssi v" PACKAGE_VERSION " - http://www.irssi.org"; - -static const char *firsttimer_text = - "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" - "Hi there! If this is your first time using Irssi, you\n" - "might want to go to our website and read the startup\n" - "documentation to get you going.\n\n" - "Our community and staff are available to assist you or\n" - "to answer any questions you may have.\n\n" - "Use the /HELP command to get detailed information about\n" - "the available commands.\n" - "- - - - - - - - - - - - - - - - - - - - - - - - - - - -"; - static int display_firsttimer = FALSE; +static int user_settings_changed = 0; static void sig_exit(void) @@ -105,6 +89,11 @@ static void sig_exit(void) quitting = TRUE; } +static void sig_settings_userinfo_changed(gpointer changedp) +{ + user_settings_changed = GPOINTER_TO_INT(changedp); +} + /* redraw irssi's screen.. */ void irssi_redraw(void) { @@ -161,6 +150,7 @@ static void textui_init(void) fe_common_irc_init(); theme_register(gui_text_formats); + signal_add("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed); signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit); } @@ -199,14 +189,24 @@ static void textui_finish_init(void) statusbar_redraw(NULL, TRUE); if (servers == NULL && lookup_servers == NULL) { - printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, - "%s", banner_text); + printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_IRSSI_BANNER); } if (display_firsttimer) { - printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, - "%s", firsttimer_text); + printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_WELCOME_FIRSTTIME); } + + /* see irc-servers-setup.c:init_userinfo */ + if (user_settings_changed) + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WELCOME_INIT_SETTINGS); + if (user_settings_changed & (1<<0)) + fe_settings_set_print("real_name"); + if (user_settings_changed & (1<<1)) + fe_settings_set_print("user_name"); + if (user_settings_changed & (1<<2)) + fe_settings_set_print("nick"); + if (user_settings_changed & (1<<3)) + fe_settings_set_print("hostname"); } static void textui_deinit(void) @@ -223,6 +223,7 @@ static void textui_deinit(void) #endif dirty_check(); /* one last time to print any quit messages */ + signal_remove("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed); signal_remove("gui exit", (SIGNAL_FUNC) sig_exit); lastlog_deinit(); @@ -249,6 +250,7 @@ static void textui_deinit(void) core_deinit(); } + static void check_files(void) { struct stat statbuf; @@ -259,12 +261,11 @@ static void check_files(void) } } - int main(int argc, char **argv) { static int version = 0; static GOptionEntry options[] = { - { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display irssi version", NULL }, + { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL }, { NULL } }; int loglev; diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c index 899827c2..c4606197 100644 --- a/src/fe-text/module-formats.c +++ b/src/fe-text/module-formats.c @@ -78,5 +78,26 @@ FORMAT_REC gui_text_formats[] = { "paste_warning", "Pasting $0 lines to $1. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.", 2, { 1, 0 } }, { "paste_prompt", "Hit Ctrl-K to paste, Ctrl-C to abort?", 0 }, + /* ---- */ + { NULL, "Welcome", 0 }, + + { "irssi_banner", + " ___ _%:" + "|_ _|_ _ _____(_)%:" + " | || '_(_-<_-< |%:" + "|___|_| /__/__/_|%:" + "Irssi v$J - http://www.irssi.org", 0 }, + { "welcome_firsttime", + "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" + "Hi there! If this is your first time using Irssi, you%:" + "might want to go to our website and read the startup%:" + "documentation to get you going.%:%:" + "Our community and staff are available to assist you or%:" + "to answer any questions you may have.%:%:" + "Use the /HELP command to get detailed information about%:" + "the available commands.%:" + "- - - - - - - - - - - - - - - - - - - - - - - - - - - -", 0 }, + { "welcome_init_settings", "The following settings were initialized", 0 }, + { NULL, NULL, 0 } }; diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h index 3fa8c511..05e9438d 100644 --- a/src/fe-text/module-formats.h +++ b/src/fe-text/module-formats.h @@ -52,6 +52,12 @@ enum { TXT_PASTE_WARNING, TXT_PASTE_PROMPT, + TXT_FILL_5, /* Welcome */ + + TXT_IRSSI_BANNER, + TXT_WELCOME_FIRSTTIME, + TXT_WELCOME_INIT_SETTINGS, + TXT_COUNT }; -- cgit v1.2.3 From 02c677f467b398f8b91b1e90544502ff98a6e0da Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 10 Nov 2017 22:02:36 +0100 Subject: use enum --- src/fe-text/irssi.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index 6349ae2a..ef443670 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -81,7 +81,7 @@ static GMainLoop *main_loop; int quitting; static int display_firsttimer = FALSE; -static int user_settings_changed = 0; +static unsigned int user_settings_changed = 0; static void sig_exit(void) @@ -91,7 +91,7 @@ static void sig_exit(void) static void sig_settings_userinfo_changed(gpointer changedp) { - user_settings_changed = GPOINTER_TO_INT(changedp); + user_settings_changed = GPOINTER_TO_UINT(changedp); } /* redraw irssi's screen.. */ @@ -199,13 +199,13 @@ static void textui_finish_init(void) /* see irc-servers-setup.c:init_userinfo */ if (user_settings_changed) printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WELCOME_INIT_SETTINGS); - if (user_settings_changed & (1<<0)) + if (user_settings_changed & USER_SETTINGS_REAL_NAME) fe_settings_set_print("real_name"); - if (user_settings_changed & (1<<1)) + if (user_settings_changed & USER_SETTINGS_USER_NAME) fe_settings_set_print("user_name"); - if (user_settings_changed & (1<<2)) + if (user_settings_changed & USER_SETTINGS_NICK) fe_settings_set_print("nick"); - if (user_settings_changed & (1<<3)) + if (user_settings_changed & USER_SETTINGS_HOSTNAME) fe_settings_set_print("hostname"); } @@ -222,7 +222,7 @@ static void textui_deinit(void) fe_perl_deinit(); #endif - dirty_check(); /* one last time to print any quit messages */ + dirty_check(); /* one last time to print any quit messages */ signal_remove("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed); signal_remove("gui exit", (SIGNAL_FUNC) sig_exit); @@ -250,7 +250,6 @@ static void textui_deinit(void) core_deinit(); } - static void check_files(void) { struct stat statbuf; -- cgit v1.2.3