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

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
This commit is contained in:
Timo Sirainen 2001-10-28 21:17:34 +00:00 committed by cras
parent 3826079dba
commit 858ed4b1ef
7 changed files with 73 additions and 52 deletions

View File

@ -46,7 +46,7 @@ static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
settings_get_bool("scroll")); settings_get_bool("scroll"));
textbuffer_view_set_default_indent(gui->view, textbuffer_view_set_default_indent(gui->view,
settings_get_int("indent"), settings_get_int("indent"),
settings_get_bool("indent_always"), !settings_get_bool("indent_always"),
get_default_indent_func()); get_default_indent_func());
return gui; return gui;
} }

View File

@ -107,6 +107,8 @@ static void dirty_check(void)
if (!dirty) if (!dirty)
return; return;
term_resize_dirty();
if (full_redraw) { if (full_redraw) {
full_redraw = FALSE; full_redraw = FALSE;

View File

@ -160,9 +160,8 @@ void term_resize(int width, int height)
#ifdef HAVE_CURSES_RESIZETERM #ifdef HAVE_CURSES_RESIZETERM
if (width < 0 || height < 0) { if (width < 0 || height < 0) {
#endif #endif
term_deinit_int(); term_deinit_int();
term_init_int(); term_init_int();
mainwindows_recreate();
#ifdef HAVE_CURSES_RESIZETERM #ifdef HAVE_CURSES_RESIZETERM
} else if (term_width != width || term_height != height) { } else if (term_width != width || term_height != height) {
term_width = width; term_width = width;
@ -172,6 +171,16 @@ void term_resize(int width, int height)
#endif #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 */ /* Returns TRUE if terminal has colors */
int term_has_colors(void) int term_has_colors(void)
{ {
@ -187,6 +196,7 @@ void term_force_colors(int set)
/* Clear screen */ /* Clear screen */
void term_clear(void) void term_clear(void)
{ {
term_set_color(root_window, 0);
clear(); 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->x = x; window->y = y;
window->width = width; window->height = height; window->width = width; window->height = height;
window->win = newwin(height, width, y, x); 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); idlok(window->win, 1);
return window; return window;

View File

@ -114,10 +114,14 @@ void term_resize(int width, int height)
vcx = vcy = -1; vcx = vcy = -1;
} }
void term_resize_final(int width, int height)
{
}
/* Returns TRUE if terminal has colors */ /* Returns TRUE if terminal has colors */
int term_has_colors(void) int term_has_colors(void)
{ {
return terminfo_has_colors(current_term); return current_term->has_colors;
} }
/* Force the colors on any way you can */ /* 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 && if ((col & 0x0f) != last_fg &&
((col & 0x0f) != 0 || (col & ATTR_RESETFG) == 0)) { ((col & 0x0f) != 0 || (col & ATTR_RESETFG) == 0)) {
last_fg = col & 0x0f; last_fg = col & 0x0f;
terminfo_set_fg(last_fg); if (term_use_colors)
terminfo_set_fg(last_fg);
} }
/* set background color */ /* set background color */
@ -229,7 +234,8 @@ void term_set_color(TERM_WINDOW *window, int col)
if ((col & 0xf0) >> 4 != last_bg && if ((col & 0xf0) >> 4 != last_bg &&
((col & 0xf0) != 0 || (col & ATTR_RESETBG) == 0)) { ((col & 0xf0) != 0 || (col & ATTR_RESETBG) == 0)) {
last_bg = (col & 0xf0) >> 4; last_bg = (col & 0xf0) >> 4;
terminfo_set_bg(last_bg); if (term_use_colors)
terminfo_set_bg(last_bg);
} }
/* bold */ /* bold */
@ -263,19 +269,13 @@ void term_move(TERM_WINDOW *window, int x, int y)
void term_addch(TERM_WINDOW *window, int chr) void term_addch(TERM_WINDOW *window, int chr)
{ {
putc(chr, window->term->out); putc(chr, window->term->out);
if (++vcx == window->width) { vcx++; /* ignore if cursor gets past the screen */
vcx = 0; vcy++;
}
} }
void term_addstr(TERM_WINDOW *window, char *str) void term_addstr(TERM_WINDOW *window, char *str)
{ {
fputs(str, window->term->out); fputs(str, window->term->out);
vcx += strlen(str); vcx += strlen(str); /* ignore if cursor gets past the screen */
while (vcx > window->width) {
vcx -= window->width;
vcy++;
}
} }
void term_clrtoeol(TERM_WINDOW *window) void term_clrtoeol(TERM_WINDOW *window)

View File

@ -32,60 +32,60 @@
#include <signal.h> #include <signal.h>
#include <termios.h> #include <termios.h>
#define RESIZE_TIMEOUT 500 /* how often to check if the terminal has been resized */
#define MIN_SCREEN_WIDTH 20 #define MIN_SCREEN_WIDTH 20
int term_use_colors; int term_use_colors;
#ifdef SIGWINCH static int resize_dirty;
static int resize_timeout_tag;
#endif
static int resize_needed;
static int resize_timeout(void) /* Resize the terminal if needed */
void term_resize_dirty(void)
{ {
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
struct winsize ws; struct winsize ws;
#endif #endif
int width, height;
if (!resize_needed) if (!resize_dirty)
return TRUE; return;
resize_needed = FALSE; resize_dirty = FALSE;
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
/* Get new window size */ /* Get new window size */
if (ioctl(0, TIOCGWINSZ, &ws) < 0) if (ioctl(0, TIOCGWINSZ, &ws) < 0)
return TRUE; return;
if (ws.ws_row == term_height && ws.ws_col == term_width) { if (ws.ws_row == term_height && ws.ws_col == term_width) {
/* Same size, abort. */ /* Same size, abort. */
return TRUE; return;
} }
if (ws.ws_col < MIN_SCREEN_WIDTH) if (ws.ws_col < MIN_SCREEN_WIDTH)
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 #else
term_resize(-1, -1); width = height = -1;
#endif #endif
term_resize(width, height);
mainwindows_resize(term_width, term_height); mainwindows_resize(term_width, term_height);
term_resize_final(width, height);
return TRUE;
} }
#ifdef SIGWINCH #ifdef SIGWINCH
static void sig_winch(int p) static void sig_winch(int p)
{ {
resize_needed = TRUE; irssi_set_dirty();
resize_dirty = TRUE;
} }
#endif #endif
static void cmd_resize(void) static void cmd_resize(void)
{ {
resize_needed = TRUE; resize_dirty = TRUE;
resize_timeout(); term_resize_dirty();
} }
static void read_settings(void) static void read_settings(void)
@ -129,18 +129,11 @@ void term_common_init(void)
act.sa_flags = 0; act.sa_flags = 0;
act.sa_handler = sig_winch; act.sa_handler = sig_winch;
sigaction(SIGWINCH, &act, NULL); sigaction(SIGWINCH, &act, NULL);
resize_timeout_tag = g_timeout_add(RESIZE_TIMEOUT,
(GSourceFunc) resize_timeout, NULL);
#endif #endif
} }
void term_common_deinit(void) void term_common_deinit(void)
{ {
#ifdef SIGWINCH
g_source_remove(resize_timeout_tag);
#endif
command_unbind("resize", (SIGNAL_FUNC) cmd_resize); command_unbind("resize", (SIGNAL_FUNC) cmd_resize);
signal_remove("beep", (SIGNAL_FUNC) term_beep); signal_remove("beep", (SIGNAL_FUNC) term_beep);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings); signal_remove("setup changed", (SIGNAL_FUNC) read_settings);

View File

@ -32,6 +32,9 @@ void term_deinit(void);
/* Resize terminal - if width or height is negative, /* Resize terminal - if width or height is negative,
the new size is unknown and should be figured out somehow */ the new size is unknown and should be figured out somehow */
void term_resize(int width, int height); 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 */ /* Returns TRUE if terminal has colors */
int term_has_colors(void); int term_has_colors(void);
@ -76,6 +79,4 @@ int term_getch(void);
void term_common_init(void); void term_common_init(void);
void term_common_deinit(void); void term_common_deinit(void);
void term_force_resize(void);
#endif #endif

View File

@ -195,7 +195,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
if (xpos == view->width && sub != NULL && if (xpos == view->width && sub != NULL &&
(last_space <= indent_pos || last_space <= 10) && (last_space <= indent_pos || last_space <= 10) &&
!view->longword_noindent) { view->longword_noindent) {
/* long word, remove the indentation from this line */ /* long word, remove the indentation from this line */
xpos -= sub->indent; xpos -= sub->indent;
sub->indent = 0; sub->indent = 0;
@ -211,7 +211,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
color = last_color; color = last_color;
ptr = last_space_ptr; ptr = last_space_ptr;
while (*ptr == ' ') ptr++; while (*ptr == ' ') ptr++;
} else if (!view->longword_noindent) { } else if (view->longword_noindent) {
/* long word, no indentation in next line */ /* long word, no indentation in next line */
xpos = 0; xpos = 0;
sub->continues = TRUE; sub->continues = TRUE;
@ -305,7 +305,7 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
LINE_CACHE_REC *cache; LINE_CACHE_REC *cache;
const unsigned char *text, *text_newline; const unsigned char *text, *text_newline;
char *tmp; 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 */ if (view->dirty) /* don't bother drawing anything - redraw is coming */
return 0; return 0;
@ -314,11 +314,17 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
if (subline >= cache->count) if (subline >= cache->count)
return 0; return 0;
need_move = TRUE; need_clrtoeol = FALSE;
xpos = color = drawcount = 0; first = TRUE; xpos = color = drawcount = 0; first = TRUE;
text_newline = text = text_newline = text =
subline == 0 ? line->text : cache->lines[subline-1].start; subline == 0 ? line->text : cache->lines[subline-1].start;
for (;;) { for (;;) {
if (text == text_newline) { if (text == text_newline) {
if (need_clrtoeol && need_move) {
term_set_color(view->window, ATTR_RESET);
term_clrtoeol(view->window);
}
if (first) if (first)
first = FALSE; first = FALSE;
else { else {
@ -327,11 +333,6 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
break; 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) { if (subline > 0) {
indent_func = cache->lines[subline-1].indent_func; indent_func = cache->lines[subline-1].indent_func;
xpos = indent_func != NULL ? 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; 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); term_set_color(view->window, color);
/* get the beginning of the next subline */ /* get the beginning of the next subline */
text_newline = subline == cache->count-1 ? NULL : text_newline = subline == cache->count-1 ? NULL :
cache->lines[subline].start; cache->lines[subline].start;
need_move = !cache->lines[subline].continues;
drawcount++; drawcount++;
subline++; subline++;
} }
@ -509,7 +522,7 @@ void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
{ {
if (default_indent != -1) if (default_indent != -1)
view->default_indent = default_indent; view->default_indent = default_indent;
if (view->longword_noindent != -1) if (longword_noindent != -1)
view->longword_noindent = longword_noindent; view->longword_noindent = longword_noindent;
view->default_indent_func = indent_func; view->default_indent_func = indent_func;