summaryrefslogtreecommitdiff
path: root/src/fe-text
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-text')
-rw-r--r--src/fe-text/gui-entry.c20
-rw-r--r--src/fe-text/gui-entry.h1
-rw-r--r--src/fe-text/gui-readline.c47
-rw-r--r--src/fe-text/gui-windows.c4
-rw-r--r--src/fe-text/irssi.c52
-rw-r--r--src/fe-text/mainwindows-layout.c10
-rw-r--r--src/fe-text/module-formats.c22
-rw-r--r--src/fe-text/module-formats.h7
-rw-r--r--src/fe-text/statusbar-items.c4
-rw-r--r--src/fe-text/term-terminfo.c48
-rw-r--r--src/fe-text/term.h2
-rw-r--r--src/fe-text/textbuffer-commands.c21
-rw-r--r--src/fe-text/textbuffer-view.c69
-rw-r--r--src/fe-text/textbuffer-view.h36
-rw-r--r--src/fe-text/textbuffer.c46
-rw-r--r--src/fe-text/textbuffer.h2
16 files changed, 305 insertions, 86 deletions
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..b3a78396 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -530,6 +530,39 @@ 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_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);
@@ -878,8 +911,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 +941,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);
}
}
@@ -1178,6 +1209,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);
@@ -1219,6 +1252,9 @@ 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);
+ 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);
@@ -1312,6 +1348,9 @@ 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("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);
diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c
index c63c495c..34c55772 100644
--- a/src/fe-text/gui-windows.c
+++ b/src/fe-text/gui-windows.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "settings.h"
#include "special-vars.h"
+#include "levels.h"
#include "term.h"
#include "gui-entry.h"
@@ -50,6 +51,7 @@ static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
!settings_get_bool("indent_always"),
get_default_indent_func());
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
+ textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
if (parent->active == window)
textbuffer_view_set_window(gui->view, parent->screen_win);
return gui;
@@ -204,6 +206,8 @@ void gui_windows_reset_settings(void)
WINDOW_REC *rec = tmp->data;
GUI_WINDOW_REC *gui = WINDOW_GUI(rec);
+ textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
+
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
textbuffer_view_set_default_indent(gui->view,
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index b5df47c9..0288e4f1 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 unsigned 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_UINT(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,26 @@ 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 & USER_SETTINGS_REAL_NAME)
+ fe_settings_set_print("real_name");
+ if (user_settings_changed & USER_SETTINGS_USER_NAME)
+ fe_settings_set_print("user_name");
+ if (user_settings_changed & USER_SETTINGS_NICK)
+ fe_settings_set_print("nick");
+ if (user_settings_changed & USER_SETTINGS_HOSTNAME)
+ fe_settings_set_print("hostname");
+
+ term_environment_check();
}
static void textui_deinit(void)
@@ -222,7 +224,8 @@ 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);
lastlog_deinit();
@@ -259,12 +262,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/mainwindows-layout.c b/src/fe-text/mainwindows-layout.c
index fae02539..acbcb6b9 100644
--- a/src/fe-text/mainwindows-layout.c
+++ b/src/fe-text/mainwindows-layout.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
+#include "levels.h"
#include "mainwindows.h"
#include "gui-windows.h"
@@ -41,6 +42,12 @@ static void sig_layout_window_save(WINDOW_REC *window, CONFIG_NODE *node)
iconfig_node_set_int(node, "parent", active->refnum);
}
+ if (gui->view->hidden_level != MSGLEVEL_HIDDEN) {
+ char *level = bits2level(gui->view->hidden_level);
+ iconfig_node_set_str(node, "hidelevel", level);
+ g_free(level);
+ }
+
if (gui->use_scroll)
iconfig_node_set_bool(node, "scroll", gui->scroll);
}
@@ -58,6 +65,9 @@ static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node)
if (config_node_get_bool(node, "sticky", FALSE))
gui_window_set_sticky(window);
+
+ textbuffer_view_set_hidden_level(gui->view, level2bits(config_node_get_str(node, "hidelevel", "HIDDEN"), NULL));
+
if (config_node_get_str(node, "scroll", NULL) != NULL) {
gui->use_scroll = TRUE;
gui->scroll = config_node_get_bool(node, "scroll", TRUE);
diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c
index 899827c2..b8a26192 100644
--- a/src/fe-text/module-formats.c
+++ b/src/fe-text/module-formats.c
@@ -50,6 +50,7 @@ FORMAT_REC gui_text_formats[] =
{ "window_info_scroll", "%#Scroll : $0", 1, { 0 } },
{ "window_scroll", "Window scroll mode is now $0", 1, { 0 } },
{ "window_scroll_unknown", "Unknown scroll mode $0, must be ON, OFF or DEFAULT", 1, { 0 } },
+ { "window_hidelevel", "Window hidden level is now $0", 1, { 0 } },
/* ---- */
{ NULL, "Statusbars", 0 },
@@ -78,5 +79,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..b753238b 100644
--- a/src/fe-text/module-formats.h
+++ b/src/fe-text/module-formats.h
@@ -26,6 +26,7 @@ enum {
TXT_WINDOW_INFO_SCROLL,
TXT_WINDOW_SCROLL,
TXT_WINDOW_SCROLL_UNKNOWN,
+ TXT_WINDOW_HIDELEVEL,
TXT_FILL_3,
@@ -52,6 +53,12 @@ enum {
TXT_PASTE_WARNING,
TXT_PASTE_PROMPT,
+ TXT_FILL_5, /* Welcome */
+
+ TXT_IRSSI_BANNER,
+ TXT_WELCOME_FIRSTTIME,
+ TXT_WELCOME_INIT_SETTINGS,
+
TXT_COUNT
};
diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c
index de4499b4..c7d6bcfb 100644
--- a/src/fe-text/statusbar-items.c
+++ b/src/fe-text/statusbar-items.c
@@ -369,8 +369,8 @@ static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
last_lag_unknown = lag_unknown;
if (lag_unknown) {
- // "??)" in C becomes ']'
- // See: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C
+ /* "??)" in C becomes ']'
+ See: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C */
g_snprintf(str, sizeof(str), "%d (?""?)", lag / 100);
} else {
if (lag % 100 == 0)
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
index 3098a4e4..ba8bdcaf 100644
--- a/src/fe-text/term-terminfo.c
+++ b/src/fe-text/term-terminfo.c
@@ -102,6 +102,17 @@ static GSourceFuncs sigcont_funcs = {
.dispatch = sigcont_dispatch
};
+static void term_atexit(void)
+{
+ if (!quitting && current_term && current_term->TI_rmcup) {
+ /* Unexpected exit, avoid switching out of alternate screen
+ to keep any on-screen errors (like noperl_die()'s) */
+ current_term->TI_rmcup = NULL;
+ }
+
+ term_deinit();
+}
+
int term_init(void)
{
struct sigaction act;
@@ -140,7 +151,7 @@ int term_init(void)
term_set_input_type(TERM_TYPE_8BIT);
term_common_init();
- atexit(term_deinit);
+ atexit(term_atexit);
return TRUE;
}
@@ -618,6 +629,13 @@ void term_stop(void)
{
terminfo_stop(current_term);
kill(getpid(), SIGTSTP);
+ /* this call needs to stay here in case the TSTP was ignored,
+ because then we never see a CONT to call the restoration
+ code. On the other hand we also cannot remove the CONT
+ handler because then nothing would restore the screen when
+ Irssi is killed with TSTP/STOP from external. */
+ terminfo_cont(current_term);
+ irssi_redraw();
}
static int input_utf8(const unsigned char *buffer, int size, unichar *result)
@@ -715,3 +733,31 @@ void term_gets(GArray *buffer, int *line_count)
}
}
}
+
+static const char* term_env_warning =
+ "You seem to be running Irssi inside %2$s, but the TERM environment variable "
+ "is set to '%1$s', which can cause display glitches.\n"
+ "Consider changing TERM to '%2$s' or '%2$s-256color' instead.";
+
+void term_environment_check(void)
+{
+ const char *term, *sty, *tmux, *multiplexer;
+
+ term = g_getenv("TERM");
+ sty = g_getenv("STY");
+ tmux = g_getenv("TMUX");
+
+ multiplexer = (sty && *sty) ? "screen" :
+ (tmux && *tmux) ? "tmux" : NULL;
+
+ if (!multiplexer) {
+ return;
+ }
+
+ if (term && (g_str_has_prefix(term, "screen") ||
+ g_str_has_prefix(term, "tmux"))) {
+ return;
+ }
+
+ g_warning(term_env_warning, term, multiplexer);
+}
diff --git a/src/fe-text/term.h b/src/fe-text/term.h
index 0c7847f6..4b1e2874 100644
--- a/src/fe-text/term.h
+++ b/src/fe-text/term.h
@@ -105,4 +105,6 @@ void term_gets(GArray *buffer, int *line_count);
void term_common_init(void);
void term_common_deinit(void);
+void term_environment_check(void);
+
#endif
diff --git a/src/fe-text/textbuffer-commands.c b/src/fe-text/textbuffer-commands.c
index 648862e7..97d897f3 100644
--- a/src/fe-text/textbuffer-commands.c
+++ b/src/fe-text/textbuffer-commands.c
@@ -89,6 +89,25 @@ static void cmd_window_scroll(const char *data)
gui->scroll : settings_get_bool("scroll"));
}
+/* SYNTAX: WINDOW HIDELEVEL [<level>] */
+static void cmd_window_hidelevel(const char *data)
+{
+ GUI_WINDOW_REC *gui;
+ char *level;
+
+ g_return_if_fail(data != NULL);
+
+ gui = WINDOW_GUI(active_win);
+ textbuffer_view_set_hidden_level(gui->view,
+ combine_level(gui->view->hidden_level, data));
+ textbuffer_view_redraw(gui->view);
+ level = gui->view->hidden_level == 0 ? g_strdup("NONE") :
+ bits2level(gui->view->hidden_level);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_HIDELEVEL, level);
+ g_free(level);
+}
+
static void cmd_scrollback(const char *data, SERVER_REC *server,
WI_ITEM_REC *item)
{
@@ -358,6 +377,7 @@ void textbuffer_commands_init(void)
{
command_bind("clear", NULL, (SIGNAL_FUNC) cmd_clear);
command_bind("window scroll", NULL, (SIGNAL_FUNC) cmd_window_scroll);
+ command_bind("window hidelevel", NULL, (SIGNAL_FUNC) cmd_window_hidelevel);
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
command_bind("scrollback levelclear", NULL, (SIGNAL_FUNC) cmd_scrollback_levelclear);
@@ -377,6 +397,7 @@ void textbuffer_commands_deinit(void)
{
command_unbind("clear", (SIGNAL_FUNC) cmd_clear);
command_unbind("window scroll", (SIGNAL_FUNC) cmd_window_scroll);
+ command_unbind("window hidelevel", (SIGNAL_FUNC) cmd_window_hidelevel);
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
command_unbind("scrollback levelclear", (SIGNAL_FUNC) cmd_scrollback_levelclear);
diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c
index 58bd36fb..b54f1c8e 100644
--- a/src/fe-text/textbuffer-view.c
+++ b/src/fe-text/textbuffer-view.c
@@ -41,9 +41,15 @@ static GSList *views;
#define view_is_bottom(view) \
((view)->ypos >= -1 && (view)->ypos < (view)->height)
-#define view_get_linecount(view, line) \
+#define view_get_linecount_hidden(view, line) \
textbuffer_view_get_line_cache(view, line)->count
+#define view_line_is_hidden(view, line) \
+ (((line)->info.level & (view)->hidden_level) != 0)
+
+#define view_get_linecount(view, line) \
+ (view_line_is_hidden(view, line) ? 0 : view_get_linecount_hidden(view, line))
+
static GSList *textbuffer_get_views(TEXT_BUFFER_REC *buffer)
{
GSList *tmp, *list;
@@ -114,7 +120,6 @@ static void update_cmd_color(unsigned char cmd, int *color)
if (cmd & LINE_COLOR_BG) {
/* set background color */
*color &= FGATTR;
- *color &= ~ATTR_FGCOLOR24;
if ((cmd & LINE_COLOR_DEFAULT) == 0)
*color |= (cmd & 0x0f) << BG_SHIFT;
else {
@@ -123,7 +128,6 @@ static void update_cmd_color(unsigned char cmd, int *color)
} else {
/* set foreground color */
*color &= BGATTR;
- *color &= ~ATTR_BGCOLOR24;
if ((cmd & LINE_COLOR_DEFAULT) == 0)
*color |= cmd & 0x0f;
else {
@@ -554,6 +558,9 @@ static void textbuffer_view_init_bottom(TEXT_BUFFER_VIEW_REC *view)
total = 0;
line = textbuffer_line_last(view->buffer);
for (; line != NULL; line = line->prev) {
+ if (view_line_is_hidden(view, line))
+ continue;
+
linecount = view_get_linecount(view, line);
if (line == view->bottom_startline) {
/* keep the old one, make sure that subline is ok */
@@ -616,6 +623,8 @@ TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
view->subline = view->bottom_subline;
view->bottom = TRUE;
+ view->hidden_level = 0;
+
textbuffer_view_init_ypos(view);
view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash,
@@ -728,8 +737,10 @@ static void view_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
return;
while (line != NULL && lines > 0) {
- linecount = view_line_draw(view, line, subline, ypos, lines);
- ypos += linecount; lines -= linecount;
+ if (!view_line_is_hidden(view, line)) {
+ linecount = view_line_draw(view, line, subline, ypos, lines);
+ ypos += linecount; lines -= linecount;
+ }
subline = 0;
line = line->next;
@@ -770,7 +781,12 @@ static void view_draw_bottom(TEXT_BUFFER_VIEW_REC *view, int lines)
view_draw(view, line, subline, maxline, lines, TRUE);
}
-/* Returns number of lines actually scrolled */
+/* lines: this pointer is scrolled by scrollcount screen lines
+ subline: this pointer contains the subline position
+ scrollcount: the number of lines to scroll down (negative: up)
+ draw_nonclean: whether to redraw the screen now
+
+ Returns number of lines actually scrolled */
static int view_scroll(TEXT_BUFFER_VIEW_REC *view, LINE_REC **lines,
int *subline, int scrollcount, int draw_nonclean)
{
@@ -1029,7 +1045,7 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
view->bottom = view_is_bottom(view);
}
- if (view->window != NULL) {
+ if (view->window != NULL && !view_line_is_hidden(view, line)) {
ypos = view->ypos+1 - view_get_linecount(view, line);
if (ypos >= 0)
subline = 0;
@@ -1044,7 +1060,7 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
}
}
- if (view->window != NULL)
+ if (view->window != NULL && !view_line_is_hidden(view, line))
term_refresh(view->window);
}
@@ -1124,6 +1140,12 @@ static int view_get_lines_height(TEXT_BUFFER_VIEW_REC *view,
return height < view->height ? height : view->height;
}
+/* line: line to remove
+ linecount: linecount of that line, to be offset when the line was in/below view
+
+ scroll the window maintaining the startline while removing line
+ if startline is removed, make the previous line the new startline
+*/
static void view_remove_line_update_startline(TEXT_BUFFER_VIEW_REC *view,
LINE_REC *line, int linecount)
{
@@ -1320,6 +1342,37 @@ LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
return g_hash_table_lookup(view->bookmarks, name);
}
+void textbuffer_view_set_hidden_level(TEXT_BUFFER_VIEW_REC *view, int level)
+{
+ g_return_if_fail(view != NULL);
+
+ if (view->hidden_level != level) {
+ if (view->empty_linecount > 0 && view->startline != NULL) {
+ int old_height, new_height;
+ LINE_REC *hidden_start;
+
+ hidden_start = view->startline;
+ while (hidden_start->prev != NULL && view_line_is_hidden(view, hidden_start->prev)) {
+ hidden_start = hidden_start->prev;
+ }
+
+ old_height = view_get_lines_height(view, hidden_start, view->subline, NULL);
+ view->hidden_level = level;
+ new_height = view_get_lines_height(view, hidden_start, view->subline, NULL);
+
+ view->empty_linecount -= new_height - old_height;
+
+ if (view->empty_linecount < 0)
+ view->empty_linecount = 0;
+ else if (view->empty_linecount > view->height)
+ view->empty_linecount = view->height;
+ } else {
+ view->hidden_level = level;
+ }
+ textbuffer_view_resize(view, view->width, view->height);
+ }
+}
+
/* Specify window where the changes in view should be drawn,
NULL disables it. */
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
diff --git a/src/fe-text/textbuffer-view.h b/src/fe-text/textbuffer-view.h
index 5e7a9d0a..a670df2b 100644
--- a/src/fe-text/textbuffer-view.h
+++ b/src/fe-text/textbuffer-view.h
@@ -49,41 +49,51 @@ typedef struct {
struct _TEXT_BUFFER_VIEW_REC {
TEXT_BUFFER_REC *buffer;
- GSList *siblings; /* other views that use the same buffer */
+ /* other views that use the same buffer */
+ GSList *siblings;
TERM_WINDOW *window;
int width, height;
int default_indent;
INDENT_FUNC default_indent_func;
- unsigned int longword_noindent:1;
- unsigned int scroll:1; /* scroll down automatically when at bottom */
- unsigned int utf8:1; /* use UTF8 in this view */
- unsigned int break_wide:1; /* Break wide chars in this view */
TEXT_BUFFER_CACHE_REC *cache;
- int ypos; /* cursor position - visible area is 0..height-1 */
+ /* cursor position - visible area is 0..height-1 */
+ int ypos;
- LINE_REC *startline; /* line at the top of the screen */
- int subline; /* number of "real lines" to skip from `startline' */
+ /* line at the top of the screen */
+ LINE_REC *startline;
+ /* number of "real lines" to skip from `startline' */
+ int subline;
/* marks the bottom of the text buffer */
LINE_REC *bottom_startline;
int bottom_subline;
+ /* Bookmarks to the lines in the buffer - removed automatically
+ when the line gets removed from buffer */
+ GHashTable *bookmarks;
+
+ /* these levels should be hidden */
+ int hidden_level;
/* how many empty lines are in screen. a screenful when started
or used /CLEAR */
int empty_linecount;
+
+ unsigned int longword_noindent:1;
+ /* scroll down automatically when at bottom */
+ unsigned int scroll:1;
+ /* use UTF8 in this view */
+ unsigned int utf8:1;
+ /* Break wide chars in this view */
+ unsigned int break_wide:1;
/* window is at the bottom of the text buffer */
unsigned int bottom:1;
/* if !bottom - new text has been printed since we were at bottom */
unsigned int more_text:1;
/* Window needs a redraw */
unsigned int dirty:1;
-
- /* Bookmarks to the lines in the buffer - removed automatically
- when the line gets removed from buffer */
- GHashTable *bookmarks;
};
/* Create new view. */
@@ -143,6 +153,8 @@ void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
/* Return the line for bookmark */
LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
const char *name);
+/* Set hidden level for view */
+void textbuffer_view_set_hidden_level(TEXT_BUFFER_VIEW_REC *view, int level);
/* Specify window where the changes in view should be drawn,
NULL disables it. */
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index 3668f4c7..01cdd118 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -24,13 +24,10 @@
#include "misc.h"
#include "formats.h"
#include "utf8.h"
+#include "iregex.h"
#include "textbuffer.h"
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
-
#define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*))
TEXT_BUFFER_REC *textbuffer_create(void)
@@ -233,6 +230,7 @@ LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer)
return buffer->cur_line;
}
+/* returns TRUE if `search' comes on or after `line' in the buffer */
int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search)
{
while (line != NULL) {
@@ -545,11 +543,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
int before, int after,
int regexp, int fullword, int case_sensitive)
{
-#ifdef USE_GREGEX
- GRegex *preg;
-#else
- regex_t preg;
-#endif
+ Regex *preg;
LINE_REC *line, *pre_line;
GList *matches;
GString *str;
@@ -559,23 +553,14 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
g_return_val_if_fail(buffer != NULL, NULL);
g_return_val_if_fail(text != NULL, NULL);
-#ifdef USE_GREGEX
preg = NULL;
if (regexp) {
- preg = g_regex_new(text, G_REGEX_RAW | (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
+ preg = i_regex_new(text, case_sensitive ? 0 : G_REGEX_CASELESS, 0, NULL);
if (preg == NULL)
return NULL;
}
-#else
- if (regexp) {
- int flags = REG_EXTENDED | REG_NOSUB |
- (case_sensitive ? 0 : REG_ICASE);
- if (regcomp(&preg, text, flags) != 0)
- return NULL;
- }
-#endif
matches = NULL; match_after = 0;
str = g_string_new(NULL);
@@ -596,11 +581,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
if (line_matched) {
line_matched = regexp ?
-#ifdef USE_GREGEX
- g_regex_match(preg, str->str, 0, NULL)
-#else
- regexec(&preg, str->str, 0, NULL, 0) == 0
-#endif
+ i_regex_match(preg, str->str, 0, NULL)
: match_func(str->str, text) != NULL;
}
}
@@ -610,33 +591,32 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
pre_line = line;
for (i = 0; i < before; i++) {
if (pre_line->prev == NULL ||
- g_list_find(matches, pre_line->prev) != NULL)
+ g_list_nth_data(matches, 0) == pre_line->prev ||
+ g_list_nth_data(matches, 1) == pre_line->prev)
break;
pre_line = pre_line->prev;
}
for (; pre_line != line; pre_line = pre_line->next)
- matches = g_list_append(matches, pre_line);
+ matches = g_list_prepend(matches, pre_line);
match_after = after;
}
if (line_matched || match_after > 0) {
/* matched */
- matches = g_list_append(matches, line);
+ matches = g_list_prepend(matches, line);
if ((!line_matched && --match_after == 0) ||
(line_matched && match_after == 0 && before > 0))
- matches = g_list_append(matches, NULL);
+ matches = g_list_prepend(matches, NULL);
}
}
-#ifdef USE_GREGEX
+ matches = g_list_reverse(matches);
+
if (preg != NULL)
- g_regex_unref(preg);
-#else
- if (regexp) regfree(&preg);
-#endif
+ i_regex_unref(preg);
g_string_free(str, TRUE);
return matches;
}
diff --git a/src/fe-text/textbuffer.h b/src/fe-text/textbuffer.h
index 303789a3..2aa22f1a 100644
--- a/src/fe-text/textbuffer.h
+++ b/src/fe-text/textbuffer.h
@@ -65,10 +65,10 @@ typedef struct {
LINE_REC *cur_line;
TEXT_CHUNK_REC *cur_text;
- unsigned int last_eol:1;
int last_fg;
int last_bg;
int last_flags;
+ unsigned int last_eol:1;
} TEXT_BUFFER_REC;
/* Create new buffer */