mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 16:53:14 +02:00
core: add horizontal scrolling for buffers with free content (command /window scroll_horiz) (task #11112)
This commit is contained in:
@@ -255,7 +255,7 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
|
||||
int max_chars_on_screen, int display)
|
||||
{
|
||||
char *next_char, *output, utf_char[16];
|
||||
int chars_displayed, size_on_screen;
|
||||
int chars_displayed, display_char, size_on_screen;
|
||||
|
||||
if (display)
|
||||
wmove (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
@@ -279,6 +279,9 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
|
||||
if (!gui_chat_utf_char_valid (utf_char))
|
||||
snprintf (utf_char, sizeof (utf_char), " ");
|
||||
|
||||
display_char = (window->buffer->type != GUI_BUFFER_TYPE_FREE)
|
||||
|| (chars_displayed >= window->scroll->start_col);
|
||||
|
||||
size_on_screen = utf8_strlen_screen (utf_char);
|
||||
if (max_chars_on_screen > 0)
|
||||
{
|
||||
@@ -286,7 +289,7 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string,
|
||||
return chars_displayed;
|
||||
chars_displayed += size_on_screen;
|
||||
}
|
||||
if (size_on_screen > 0)
|
||||
if (display_char && (size_on_screen > 0))
|
||||
{
|
||||
output = string_iconv_from_internal (NULL, utf_char);
|
||||
wprintw (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
|
||||
@@ -180,6 +180,7 @@ gui_window_scroll_init (struct t_gui_window_scroll *window_scroll,
|
||||
window_scroll->start_line = NULL;
|
||||
window_scroll->start_line_pos = 0;
|
||||
window_scroll->scrolling = 0;
|
||||
window_scroll->start_col = 0;
|
||||
window_scroll->lines_after = 0;
|
||||
window_scroll->reset_allowed = 0;
|
||||
window_scroll->prev_scroll = NULL;
|
||||
@@ -241,6 +242,7 @@ gui_window_scroll_remove_not_scrolled (struct t_gui_window *window)
|
||||
&& (ptr_scroll->start_line == NULL)
|
||||
&& (ptr_scroll->start_line_pos == 0)
|
||||
&& (ptr_scroll->scrolling == 0)
|
||||
&& (ptr_scroll->start_col == 0)
|
||||
&& (ptr_scroll->lines_after == 0)
|
||||
&& (ptr_scroll->reset_allowed == 0))
|
||||
{
|
||||
@@ -958,6 +960,75 @@ gui_window_scroll (struct t_gui_window *window, char *scroll)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_scroll_horiz: horizontal scroll window
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_scroll_horiz (struct t_gui_window *window, char *scroll)
|
||||
{
|
||||
int direction, percentage, start_col;
|
||||
char saved_char, *pos, *error;
|
||||
long number;
|
||||
|
||||
if (window->buffer->lines->first_line)
|
||||
{
|
||||
direction = 1;
|
||||
number = 0;
|
||||
percentage = 0;
|
||||
|
||||
/* search direction */
|
||||
if (scroll[0] == '-')
|
||||
{
|
||||
direction = -1;
|
||||
scroll++;
|
||||
}
|
||||
else if (scroll[0] == '+')
|
||||
{
|
||||
direction = +1;
|
||||
scroll++;
|
||||
}
|
||||
|
||||
/* search number and percentage */
|
||||
pos = scroll;
|
||||
while (pos && pos[0] && isdigit (pos[0]))
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
if (pos && (pos > scroll))
|
||||
{
|
||||
percentage = (pos[0] == '%') ? 1 : 0;
|
||||
saved_char = pos[0];
|
||||
pos[0] = '\0';
|
||||
error = NULL;
|
||||
number = strtol (scroll, &error, 10);
|
||||
if (!error || error[0])
|
||||
number = 0;
|
||||
pos[0] = saved_char;
|
||||
}
|
||||
|
||||
/* for percentage, compute number of columns */
|
||||
if (percentage)
|
||||
{
|
||||
number = (window->win_chat_width * number) / 100;
|
||||
}
|
||||
|
||||
/* number must be different from 0 */
|
||||
if (number == 0)
|
||||
return;
|
||||
|
||||
/* do the horizontal scroll! */
|
||||
start_col = window->scroll->start_col + (number * direction);
|
||||
if (start_col < 0)
|
||||
start_col = 0;
|
||||
if (start_col != window->scroll->start_col)
|
||||
{
|
||||
window->scroll->start_col = start_col;
|
||||
gui_buffer_ask_chat_refresh (window->buffer, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_scroll_previous_highlight: scroll to previous highlight
|
||||
*/
|
||||
@@ -1298,6 +1369,7 @@ gui_window_print_log ()
|
||||
log_printf (" start_line. . . . . : 0x%lx", ptr_scroll->start_line);
|
||||
log_printf (" start_line_pos. . . : %d", ptr_scroll->start_line_pos);
|
||||
log_printf (" scrolling . . . . . : %d", ptr_scroll->scrolling);
|
||||
log_printf (" start_col . . . . . : %d", ptr_scroll->start_col);
|
||||
log_printf (" lines_after . . . . : %d", ptr_scroll->lines_after);
|
||||
log_printf (" reset_allowed . . . : %d", ptr_scroll->reset_allowed);
|
||||
log_printf (" prev_scroll . . . . : 0x%lx", ptr_scroll->prev_scroll);
|
||||
|
||||
@@ -84,6 +84,8 @@ struct t_gui_window_scroll
|
||||
struct t_gui_line *start_line; /* pointer to line if scrolling */
|
||||
int start_line_pos; /* position in first line displayed */
|
||||
int scrolling; /* = 1 if "MORE" should be displayed */
|
||||
int start_col; /* first column displayed */
|
||||
/* (for horizontal scrolling) */
|
||||
int lines_after; /* number of lines after last line */
|
||||
/* displayed (with scrolling) */
|
||||
int reset_allowed; /* reset scroll allowed (when using */
|
||||
@@ -145,6 +147,7 @@ extern void gui_window_switch_next (struct t_gui_window *window);
|
||||
extern void gui_window_switch_by_buffer (struct t_gui_window *window,
|
||||
int buffer_number);
|
||||
extern void gui_window_scroll (struct t_gui_window *window, char *scroll);
|
||||
extern void gui_window_scroll_horiz (struct t_gui_window *window, char *scroll);
|
||||
extern void gui_window_scroll_previous_highlight (struct t_gui_window *window);
|
||||
extern void gui_window_scroll_next_highlight (struct t_gui_window *window);
|
||||
extern void gui_window_search_start (struct t_gui_window *window);
|
||||
|
||||
Reference in New Issue
Block a user