summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-10-28 21:17:34 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-10-28 21:17:34 +0000
commit858ed4b1ef5869e2d2ba28d08c0b2397447618af (patch)
treef46709322ad27b98169579561e48d8ed8ac98457
parent3826079dbab92df9fcab1430b9eee90bc8a2eb32 (diff)
downloadirssi-858ed4b1ef5869e2d2ba28d08c0b2397447618af.zip
Some resize fixes. With terminfo + /SET indent_always OFF, doubleclicking
long words (URLs mostly) that get split into two lines, selects the word fully. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1929 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r--src/fe-text/gui-windows.c2
-rw-r--r--src/fe-text/irssi.c2
-rw-r--r--src/fe-text/term-curses.c18
-rw-r--r--src/fe-text/term-terminfo.c22
-rw-r--r--src/fe-text/term.c43
-rw-r--r--src/fe-text/term.h5
-rw-r--r--src/fe-text/textbuffer-view.c33
7 files changed, 73 insertions, 52 deletions
diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c
index 1ce50fb6..eb1487e0 100644
--- a/src/fe-text/gui-windows.c
+++ b/src/fe-text/gui-windows.c
@@ -46,7 +46,7 @@ static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
settings_get_bool("scroll"));
textbuffer_view_set_default_indent(gui->view,
settings_get_int("indent"),
- settings_get_bool("indent_always"),
+ !settings_get_bool("indent_always"),
get_default_indent_func());
return gui;
}
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index 863adfd3..311a2321 100644
--- a/src/fe-text/irssi.c
+++ b/src/fe-text/irssi.c
@@ -107,6 +107,8 @@ static void dirty_check(void)
if (!dirty)
return;
+ term_resize_dirty();
+
if (full_redraw) {
full_redraw = FALSE;
diff --git a/src/fe-text/term-curses.c b/src/fe-text/term-curses.c
index e3b8e87b..dad1fedc 100644
--- a/src/fe-text/term-curses.c
+++ b/src/fe-text/term-curses.c
@@ -160,9 +160,8 @@ void term_resize(int width, int height)
#ifdef HAVE_CURSES_RESIZETERM
if (width < 0 || height < 0) {
#endif
- term_deinit_int();
- term_init_int();
- mainwindows_recreate();
+ term_deinit_int();
+ term_init_int();
#ifdef HAVE_CURSES_RESIZETERM
} else if (term_width != width || term_height != height) {
term_width = width;
@@ -172,6 +171,16 @@ void term_resize(int width, int height)
#endif
}
+void term_resize_final(int width, int height)
+{
+#ifdef HAVE_CURSES_RESIZETERM
+ if (width < 0 || height < 0)
+ mainwindows_recreate();
+#else
+ mainwindows_recreate();
+#endif
+}
+
/* Returns TRUE if terminal has colors */
int term_has_colors(void)
{
@@ -187,6 +196,7 @@ void term_force_colors(int set)
/* Clear screen */
void term_clear(void)
{
+ term_set_color(root_window, 0);
clear();
}
@@ -205,6 +215,8 @@ TERM_WINDOW *term_window_create(int x, int y, int width, int height)
window->x = x; window->y = y;
window->width = width; window->height = height;
window->win = newwin(height, width, y, x);
+ if (window->win == NULL)
+ g_error("newwin() failed: %d,%d %d,%d", x, y, width, height);
idlok(window->win, 1);
return window;
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
index bf9fd22e..9beccbf0 100644
--- a/src/fe-text/term-terminfo.c
+++ b/src/fe-text/term-terminfo.c
@@ -114,10 +114,14 @@ void term_resize(int width, int height)
vcx = vcy = -1;
}
+void term_resize_final(int width, int height)
+{
+}
+
/* Returns TRUE if terminal has colors */
int term_has_colors(void)
{
- return terminfo_has_colors(current_term);
+ return current_term->has_colors;
}
/* Force the colors on any way you can */
@@ -217,7 +221,8 @@ void term_set_color(TERM_WINDOW *window, int col)
if ((col & 0x0f) != last_fg &&
((col & 0x0f) != 0 || (col & ATTR_RESETFG) == 0)) {
last_fg = col & 0x0f;
- terminfo_set_fg(last_fg);
+ if (term_use_colors)
+ terminfo_set_fg(last_fg);
}
/* set background color */
@@ -229,7 +234,8 @@ void term_set_color(TERM_WINDOW *window, int col)
if ((col & 0xf0) >> 4 != last_bg &&
((col & 0xf0) != 0 || (col & ATTR_RESETBG) == 0)) {
last_bg = (col & 0xf0) >> 4;
- terminfo_set_bg(last_bg);
+ if (term_use_colors)
+ terminfo_set_bg(last_bg);
}
/* bold */
@@ -263,19 +269,13 @@ void term_move(TERM_WINDOW *window, int x, int y)
void term_addch(TERM_WINDOW *window, int chr)
{
putc(chr, window->term->out);
- if (++vcx == window->width) {
- vcx = 0; vcy++;
- }
+ vcx++; /* ignore if cursor gets past the screen */
}
void term_addstr(TERM_WINDOW *window, char *str)
{
fputs(str, window->term->out);
- vcx += strlen(str);
- while (vcx > window->width) {
- vcx -= window->width;
- vcy++;
- }
+ vcx += strlen(str); /* ignore if cursor gets past the screen */
}
void term_clrtoeol(TERM_WINDOW *window)
diff --git a/src/fe-text/term.c b/src/fe-text/term.c
index a20f7b50..2889f8eb 100644
--- a/src/fe-text/term.c
+++ b/src/fe-text/term.c
@@ -32,60 +32,60 @@
#include <signal.h>
#include <termios.h>
-#define RESIZE_TIMEOUT 500 /* how often to check if the terminal has been resized */
#define MIN_SCREEN_WIDTH 20
int term_use_colors;
-#ifdef SIGWINCH
-static int resize_timeout_tag;
-#endif
-static int resize_needed;
+static int resize_dirty;
-static int resize_timeout(void)
+/* Resize the terminal if needed */
+void term_resize_dirty(void)
{
#ifdef TIOCGWINSZ
struct winsize ws;
#endif
+ int width, height;
- if (!resize_needed)
- return TRUE;
+ if (!resize_dirty)
+ return;
- resize_needed = FALSE;
+ resize_dirty = FALSE;
#ifdef TIOCGWINSZ
/* Get new window size */
if (ioctl(0, TIOCGWINSZ, &ws) < 0)
- return TRUE;
+ return;
if (ws.ws_row == term_height && ws.ws_col == term_width) {
/* Same size, abort. */
- return TRUE;
+ return;
}
if (ws.ws_col < MIN_SCREEN_WIDTH)
ws.ws_col = MIN_SCREEN_WIDTH;
- term_resize(ws.ws_col, ws.ws_row);
+ width = ws.ws_col;
+ height = ws.ws_row;
#else
- term_resize(-1, -1);
+ width = height = -1;
#endif
+ term_resize(width, height);
mainwindows_resize(term_width, term_height);
-
- return TRUE;
+ term_resize_final(width, height);
}
#ifdef SIGWINCH
static void sig_winch(int p)
{
- resize_needed = TRUE;
+ irssi_set_dirty();
+ resize_dirty = TRUE;
}
#endif
static void cmd_resize(void)
{
- resize_needed = TRUE;
- resize_timeout();
+ resize_dirty = TRUE;
+ term_resize_dirty();
}
static void read_settings(void)
@@ -129,18 +129,11 @@ void term_common_init(void)
act.sa_flags = 0;
act.sa_handler = sig_winch;
sigaction(SIGWINCH, &act, NULL);
-
- resize_timeout_tag = g_timeout_add(RESIZE_TIMEOUT,
- (GSourceFunc) resize_timeout, NULL);
#endif
}
void term_common_deinit(void)
{
-#ifdef SIGWINCH
- g_source_remove(resize_timeout_tag);
-#endif
-
command_unbind("resize", (SIGNAL_FUNC) cmd_resize);
signal_remove("beep", (SIGNAL_FUNC) term_beep);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
diff --git a/src/fe-text/term.h b/src/fe-text/term.h
index 5aa89e59..bda89462 100644
--- a/src/fe-text/term.h
+++ b/src/fe-text/term.h
@@ -32,6 +32,9 @@ void term_deinit(void);
/* Resize terminal - if width or height is negative,
the new size is unknown and should be figured out somehow */
void term_resize(int width, int height);
+void term_resize_final(int width, int height);
+/* Resize the terminal if needed */
+void term_resize_dirty(void);
/* Returns TRUE if terminal has colors */
int term_has_colors(void);
@@ -76,6 +79,4 @@ int term_getch(void);
void term_common_init(void);
void term_common_deinit(void);
-void term_force_resize(void);
-
#endif
diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c
index 540721e7..8578cfdf 100644
--- a/src/fe-text/textbuffer-view.c
+++ b/src/fe-text/textbuffer-view.c
@@ -195,7 +195,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
if (xpos == view->width && sub != NULL &&
(last_space <= indent_pos || last_space <= 10) &&
- !view->longword_noindent) {
+ view->longword_noindent) {
/* long word, remove the indentation from this line */
xpos -= sub->indent;
sub->indent = 0;
@@ -211,7 +211,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
color = last_color;
ptr = last_space_ptr;
while (*ptr == ' ') ptr++;
- } else if (!view->longword_noindent) {
+ } else if (view->longword_noindent) {
/* long word, no indentation in next line */
xpos = 0;
sub->continues = TRUE;
@@ -305,7 +305,7 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
LINE_CACHE_REC *cache;
const unsigned char *text, *text_newline;
char *tmp;
- int xpos, color, drawcount, first;
+ int xpos, color, drawcount, first, need_move, need_clrtoeol;
if (view->dirty) /* don't bother drawing anything - redraw is coming */
return 0;
@@ -314,11 +314,17 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
if (subline >= cache->count)
return 0;
+ need_move = TRUE; need_clrtoeol = FALSE;
xpos = color = drawcount = 0; first = TRUE;
text_newline = text =
subline == 0 ? line->text : cache->lines[subline-1].start;
for (;;) {
if (text == text_newline) {
+ if (need_clrtoeol && need_move) {
+ term_set_color(view->window, ATTR_RESET);
+ term_clrtoeol(view->window);
+ }
+
if (first)
first = FALSE;
else {
@@ -327,11 +333,6 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
break;
}
- /* first clear the line */
- term_set_color(view->window, ATTR_RESET);
- term_move(view->window, 0, ypos);
- term_clrtoeol(view->window);
-
if (subline > 0) {
indent_func = cache->lines[subline-1].indent_func;
xpos = indent_func != NULL ?
@@ -340,13 +341,25 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
color = cache->lines[subline-1].color;
}
- term_move(view->window, xpos, ypos);
+ if (need_move || xpos > 0) {
+ /* first clear the line */
+ if (xpos == 0)
+ need_clrtoeol = TRUE;
+ else {
+ term_set_color(view->window, ATTR_RESET);
+ term_move(view->window, 0, ypos);
+ term_clrtoeol(view->window);
+ }
+
+ term_move(view->window, xpos, ypos);
+ }
term_set_color(view->window, color);
/* get the beginning of the next subline */
text_newline = subline == cache->count-1 ? NULL :
cache->lines[subline].start;
+ need_move = !cache->lines[subline].continues;
drawcount++;
subline++;
}
@@ -509,7 +522,7 @@ void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
{
if (default_indent != -1)
view->default_indent = default_indent;
- if (view->longword_noindent != -1)
+ if (longword_noindent != -1)
view->longword_noindent = longword_noindent;
view->default_indent_func = indent_func;