mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 23:36:37 +02:00
core: add horizontal scrolling for buffers with free content (command /window scroll_horiz) (task #11112)
This commit is contained in:
+40
-24
@@ -4364,6 +4364,25 @@ COMMAND_CALLBACK(window)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* vertical scroll in window */
|
||||
if (string_strcasecmp (argv[1], "scroll") == 0)
|
||||
{
|
||||
if (argc > 2)
|
||||
gui_window_scroll (gui_current_window, argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* horizontal scroll in window (for buffers with free content) */
|
||||
if (string_strcasecmp (argv[1], "scroll_horiz") == 0)
|
||||
{
|
||||
if ((argc > 2)
|
||||
&& (gui_current_window->buffer->type == GUI_BUFFER_TYPE_FREE))
|
||||
{
|
||||
gui_window_scroll_horiz (gui_current_window, argv[2]);
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* scroll up current window */
|
||||
if (string_strcasecmp (argv[1], "scroll_up") == 0)
|
||||
{
|
||||
@@ -4517,18 +4536,6 @@ COMMAND_CALLBACK(window)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* jump to window by buffer number */
|
||||
if (string_strncasecmp (argv[1], "b", 1) == 0)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (argv[1] + 1, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_switch_by_buffer (gui_current_window, number);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* switch to previous window */
|
||||
if (string_strcasecmp (argv[1], "-1") == 0)
|
||||
{
|
||||
@@ -4571,14 +4578,6 @@ COMMAND_CALLBACK(window)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* scroll in window */
|
||||
if (string_strcasecmp (argv[1], "scroll") == 0)
|
||||
{
|
||||
if (argc > 2)
|
||||
gui_window_scroll (gui_current_window, argv[2]);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* swap windows */
|
||||
if (string_strcasecmp (argv[1], "swap") == 0)
|
||||
{
|
||||
@@ -4616,6 +4615,18 @@ COMMAND_CALLBACK(window)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/* jump to window by buffer number */
|
||||
if (string_strncasecmp (argv[1], "b", 1) == 0)
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (argv[1] + 1, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_switch_by_buffer (gui_current_window, number);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
||||
|
||||
gui_chat_printf (NULL,
|
||||
_("%sError: unknown option for \"%s\" "
|
||||
"command"),
|
||||
@@ -5271,7 +5282,9 @@ command_init ()
|
||||
" || merge [all]"
|
||||
" || page_up|page_down"
|
||||
" || refresh"
|
||||
" || scroll|scroll_up|scroll_down|scroll_top|"
|
||||
" || scroll [+/-]<value>[s|m|h|d|M|y]"
|
||||
" || scroll_horiz [+/-]<value>[%]"
|
||||
" || scroll_up|scroll_down|scroll_top|"
|
||||
"scroll_bottom|scroll_previous_highlight|"
|
||||
"scroll_next_highlight"
|
||||
" || swap [up|down|left|right]"
|
||||
@@ -5295,8 +5308,11 @@ command_init ()
|
||||
" page_up: scroll one page up\n"
|
||||
" page_down: scroll one page down\n"
|
||||
" refresh: refresh screen\n"
|
||||
" scroll: scroll number of lines (+/-N) or with time: "
|
||||
" scroll: scroll a number of lines (+/-N) or with time: "
|
||||
"s=seconds, m=minutes, h=hours, d=days, M=months, y=years\n"
|
||||
" scroll_horiz: scroll horizontally a number of columns "
|
||||
"(+/-N) or percentage of window size (this scrolling is "
|
||||
"possible only on buffers with free content)\n"
|
||||
" scroll_up: scroll a few lines up\n"
|
||||
" scroll_down: scroll a few lines down\n"
|
||||
" scroll_top: scroll to top of buffer\n"
|
||||
@@ -5321,8 +5337,8 @@ command_init ()
|
||||
" /window scroll -d"),
|
||||
"list || -1 || +1 || up || down || left || right"
|
||||
" || splith || splitv || resize || balance || page_up"
|
||||
" || page_down || refresh || scroll || scroll_up"
|
||||
" || scroll_down || scroll_top || scroll_bottom"
|
||||
" || page_down || refresh || scroll || scroll_horiz"
|
||||
" || scroll_up || scroll_down || scroll_top || scroll_bottom"
|
||||
" || scroll_previous_highlight || scroll_next_highlight"
|
||||
" || swap up|down|left|right || zoom || merge all",
|
||||
&command_window, NULL);
|
||||
|
||||
@@ -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