mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 09:13:14 +02:00
core: add bare display mode (for easy text selection and click on URLs)
New key: alt+"!", to swith to bare display (same key to come back to standard display). New options: - weechat.look.bare_display_exit_on_input (default: on): by default any changes in input will return to standard display - weechat.look.bare_display_time_format (default: "%H:%M"): the format of time used in bare display.
This commit is contained in:
@@ -411,6 +411,9 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
if (!gui_init_ok)
|
||||
return;
|
||||
|
||||
if (gui_window_bare_display)
|
||||
return;
|
||||
|
||||
if ((bar_window->x < 0) || (bar_window->y < 0))
|
||||
return;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -1843,6 +1844,144 @@ gui_chat_draw_free_buffer (struct t_gui_window *window, int clear_chat)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets line content in bare display.
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_chat_get_bare_line (struct t_gui_line *line)
|
||||
{
|
||||
char *prefix, *message, str_time[256], *str_line;
|
||||
const char *tag_prefix_nick;
|
||||
struct tm *local_time;
|
||||
int length;
|
||||
|
||||
prefix = NULL;
|
||||
message = NULL;
|
||||
str_line = NULL;
|
||||
|
||||
prefix = (line->data->prefix) ?
|
||||
gui_color_decode (line->data->prefix, NULL) : strdup ("");
|
||||
if (!prefix)
|
||||
goto end;
|
||||
message = (line->data->message) ?
|
||||
gui_color_decode (line->data->message, NULL) : strdup ("");
|
||||
if (!message)
|
||||
goto end;
|
||||
|
||||
str_time[0] = '\0';
|
||||
if ((line->data->date > 0)
|
||||
&& CONFIG_STRING(config_look_bare_display_time_format)
|
||||
&& CONFIG_STRING(config_look_bare_display_time_format)[0])
|
||||
{
|
||||
local_time = localtime (&line->data->date);
|
||||
strftime (str_time, sizeof (str_time),
|
||||
CONFIG_STRING(config_look_bare_display_time_format),
|
||||
local_time);
|
||||
}
|
||||
tag_prefix_nick = gui_line_search_tag_starting_with (line, "prefix_nick_");
|
||||
|
||||
length = strlen (str_time) + 1 + 1 + strlen (prefix) + 1 + 1
|
||||
+ strlen (message) + 1;
|
||||
str_line = malloc (length);
|
||||
if (str_line)
|
||||
{
|
||||
snprintf (str_line, length,
|
||||
"%s%s%s%s%s%s%s",
|
||||
str_time,
|
||||
(str_time[0]) ? " " : "",
|
||||
(prefix[0] && tag_prefix_nick) ? "<" : "",
|
||||
prefix,
|
||||
(prefix[0] && tag_prefix_nick) ? ">" : "",
|
||||
(prefix[0]) ? " " : "",
|
||||
message);
|
||||
}
|
||||
|
||||
end:
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
if (message)
|
||||
free (message);
|
||||
|
||||
return str_line;
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a buffer in bare display (not ncurses).
|
||||
*/
|
||||
|
||||
void
|
||||
gui_chat_draw_bare (struct t_gui_window *window)
|
||||
{
|
||||
struct t_gui_line *ptr_line;
|
||||
char *line;
|
||||
int y, length, num_lines;
|
||||
|
||||
/* in bare display, we display ONLY the current window/buffer */
|
||||
if (window != gui_current_window)
|
||||
return;
|
||||
|
||||
/* clear screen */
|
||||
printf ("\033[2J");
|
||||
|
||||
/* display lines */
|
||||
if ((window->buffer->type == GUI_BUFFER_TYPE_FREE)
|
||||
|| window->scroll->start_line)
|
||||
{
|
||||
/* display from top to bottom (starting with "start_line") */
|
||||
y = 0;
|
||||
ptr_line = (window->scroll->start_line) ?
|
||||
window->scroll->start_line : gui_line_get_first_displayed (window->buffer);
|
||||
while (ptr_line && (y < gui_term_lines))
|
||||
{
|
||||
line = gui_chat_get_bare_line (ptr_line);
|
||||
if (!line)
|
||||
break;
|
||||
length = utf8_strlen_screen (line);
|
||||
num_lines = length / gui_term_cols;
|
||||
if (length % gui_term_cols != 0)
|
||||
num_lines++;
|
||||
if (y + num_lines <= gui_term_lines)
|
||||
printf ("\033[%d;1H%s", y + 1, line);
|
||||
free (line);
|
||||
y += num_lines;
|
||||
ptr_line = gui_line_get_next_displayed (ptr_line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* display from bottom to top (starting with last line of buffer) */
|
||||
y = gui_term_lines;
|
||||
ptr_line = gui_line_get_last_displayed (window->buffer);
|
||||
while (ptr_line && (y >= 0))
|
||||
{
|
||||
line = gui_chat_get_bare_line (ptr_line);
|
||||
if (!line)
|
||||
break;
|
||||
length = utf8_strlen_screen (line);
|
||||
num_lines = length / gui_term_cols;
|
||||
if (length % gui_term_cols != 0)
|
||||
num_lines++;
|
||||
y -= num_lines;
|
||||
if (y >= 0)
|
||||
printf ("\033[%d;1H%s", y + 1, line);
|
||||
free (line);
|
||||
ptr_line = gui_line_get_prev_displayed (ptr_line);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* move cursor to top/left or bottom/right, according to type of buffer and
|
||||
* whether we are scrolling or not
|
||||
*/
|
||||
printf ("\033[%d;1H",
|
||||
(window->buffer->type == GUI_BUFFER_TYPE_FREE) ?
|
||||
((window->scroll->start_line) ? gui_term_lines : 1) :
|
||||
((window->scroll->start_line) ? 1 : gui_term_lines));
|
||||
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws chat window for a buffer.
|
||||
*/
|
||||
@@ -1858,6 +1997,13 @@ gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat)
|
||||
if (!gui_init_ok)
|
||||
return;
|
||||
|
||||
if (gui_window_bare_display)
|
||||
{
|
||||
if (gui_current_window && (gui_current_window->buffer == buffer))
|
||||
gui_chat_draw_bare (gui_current_window);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
|
||||
{
|
||||
if ((ptr_win->buffer->number == buffer->number)
|
||||
@@ -1914,5 +2060,6 @@ gui_chat_draw (struct t_gui_buffer *buffer, int clear_chat)
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
buffer->chat_refresh_needed = 0;
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ gui_key_default_bindings (int context)
|
||||
BIND(/* m-m */ "meta-m", "/mute mouse toggle");
|
||||
BIND(/* start paste */ "meta2-200~", "/input paste_start");
|
||||
BIND(/* end paste */ "meta2-201~", "/input paste_stop");
|
||||
BIND(/* bare display*/ "meta-!", "/window bare");
|
||||
|
||||
/* bind meta-j + {01..99} to switch to buffers # > 10 */
|
||||
for (i = 1; i < 100; i++)
|
||||
|
||||
@@ -59,10 +59,10 @@
|
||||
#include "gui-curses.h"
|
||||
|
||||
|
||||
int gui_reload_config = 0;
|
||||
int gui_signal_sigwinch_received = 0;
|
||||
int gui_term_cols = 0;
|
||||
int gui_term_lines = 0;
|
||||
int gui_reload_config = 0; /* 1 if config must be reloaded */
|
||||
int gui_signal_sigwinch_received = 0; /* sigwinch signal (term resized) */
|
||||
int gui_term_cols = 0; /* number of columns in terminal */
|
||||
int gui_term_lines = 0; /* number of lines in terminal */
|
||||
|
||||
|
||||
/*
|
||||
@@ -375,9 +375,7 @@ gui_main_refreshs ()
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
if (ptr_bar->bar_refresh_needed)
|
||||
{
|
||||
gui_bar_draw (ptr_bar);
|
||||
}
|
||||
}
|
||||
|
||||
/* refresh window if needed (if asked during refresh of bars) */
|
||||
@@ -393,7 +391,7 @@ gui_main_refreshs ()
|
||||
if (ptr_win->refresh_needed)
|
||||
{
|
||||
gui_window_switch_to_buffer (ptr_win, ptr_win->buffer, 0);
|
||||
gui_window_redraw_buffer (ptr_win->buffer);
|
||||
gui_chat_draw (ptr_win->buffer, 1);
|
||||
ptr_win->refresh_needed = 0;
|
||||
}
|
||||
}
|
||||
@@ -409,18 +407,21 @@ gui_main_refreshs ()
|
||||
}
|
||||
}
|
||||
|
||||
/* refresh bars if needed */
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
if (!gui_window_bare_display)
|
||||
{
|
||||
if (ptr_bar->bar_refresh_needed)
|
||||
/* refresh bars if needed */
|
||||
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
|
||||
{
|
||||
gui_bar_draw (ptr_bar);
|
||||
if (ptr_bar->bar_refresh_needed)
|
||||
{
|
||||
gui_bar_draw (ptr_bar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* move cursor (for cursor mode) */
|
||||
if (gui_cursor_mode)
|
||||
gui_window_move_cursor ();
|
||||
/* move cursor (for cursor mode) */
|
||||
if (gui_cursor_mode)
|
||||
gui_window_move_cursor ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -476,7 +477,7 @@ gui_main_loop ()
|
||||
}
|
||||
|
||||
gui_main_refreshs ();
|
||||
if (gui_window_refresh_needed)
|
||||
if (gui_window_refresh_needed && !gui_window_bare_display)
|
||||
gui_main_refreshs ();
|
||||
|
||||
if (gui_signal_sigwinch_received)
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "../gui-layout.h"
|
||||
#include "../gui-line.h"
|
||||
#include "../gui-main.h"
|
||||
#include "../gui-mouse.h"
|
||||
#include "../gui-nicklist.h"
|
||||
#include "gui-curses.h"
|
||||
|
||||
@@ -1161,38 +1162,6 @@ gui_window_draw_separators (struct t_gui_window *window)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Redraws a buffer.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_redraw_buffer (struct t_gui_buffer *buffer)
|
||||
{
|
||||
if (!gui_init_ok)
|
||||
return;
|
||||
|
||||
gui_chat_draw (buffer, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Redraws all buffers.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_redraw_all_buffers ()
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
if (!gui_init_ok)
|
||||
return;
|
||||
|
||||
for (ptr_buffer = gui_buffers; ptr_buffer;
|
||||
ptr_buffer = ptr_buffer->next_buffer)
|
||||
{
|
||||
gui_window_redraw_buffer (ptr_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Switches to another buffer in a window.
|
||||
*/
|
||||
@@ -2379,6 +2348,77 @@ gui_window_refresh_screen (int full_refresh)
|
||||
gui_window_refresh_windows ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for bare display timer.
|
||||
*/
|
||||
|
||||
int
|
||||
gui_window_bare_display_timer_cb (void *data, int remaining_calls)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
if (gui_window_bare_display)
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
|
||||
if (remaining_calls == 0)
|
||||
gui_window_bare_display_timer = NULL;
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Toggles bare display.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_bare_display_toggle (const char *delay)
|
||||
{
|
||||
long milliseconds;
|
||||
char *error;
|
||||
|
||||
gui_window_bare_display ^= 1;
|
||||
|
||||
if (gui_window_bare_display)
|
||||
{
|
||||
/* temporarily disable ncurses */
|
||||
endwin ();
|
||||
if (gui_mouse_enabled)
|
||||
gui_mouse_disable ();
|
||||
if (delay)
|
||||
{
|
||||
error = NULL;
|
||||
milliseconds = strtol (delay, &error, 10);
|
||||
if (error && !error[0] && (milliseconds >= 0))
|
||||
{
|
||||
if (gui_window_bare_display_timer)
|
||||
{
|
||||
unhook (gui_window_bare_display_timer);
|
||||
gui_window_bare_display_timer = NULL;
|
||||
}
|
||||
gui_window_bare_display_timer = hook_timer (
|
||||
NULL,
|
||||
milliseconds, 0, 1,
|
||||
&gui_window_bare_display_timer_cb, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* come back to standard display (with ncurses) */
|
||||
refresh ();
|
||||
if (gui_window_bare_display_timer)
|
||||
{
|
||||
unhook (gui_window_bare_display_timer);
|
||||
gui_window_bare_display_timer = NULL;
|
||||
}
|
||||
if (CONFIG_BOOLEAN(config_look_mouse))
|
||||
gui_mouse_enable ();
|
||||
}
|
||||
|
||||
gui_window_ask_refresh (2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets terminal title.
|
||||
*
|
||||
|
||||
@@ -99,7 +99,6 @@ extern int gui_key_read_cb (void *data, int fd);
|
||||
|
||||
/* window functions */
|
||||
extern void gui_window_read_terminal_size ();
|
||||
extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer);
|
||||
extern void gui_window_clear (WINDOW *window, int fg, int bg);
|
||||
extern void gui_window_clrtoeol (WINDOW *window);
|
||||
extern void gui_window_save_style (WINDOW *window);
|
||||
|
||||
@@ -123,6 +123,12 @@ gui_input_replace_input (struct t_gui_buffer *buffer, const char *new_input)
|
||||
void
|
||||
gui_input_paste_pending_signal ()
|
||||
{
|
||||
if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input)
|
||||
&& gui_window_bare_display)
|
||||
{
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
}
|
||||
|
||||
(void) hook_signal_send ("input_paste_pending",
|
||||
WEECHAT_HOOK_SIGNAL_STRING, NULL);
|
||||
}
|
||||
@@ -138,6 +144,12 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer,
|
||||
{
|
||||
char str_buffer[128], *new_input;
|
||||
|
||||
if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input)
|
||||
&& gui_window_bare_display)
|
||||
{
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
}
|
||||
|
||||
if (!gui_cursor_mode)
|
||||
{
|
||||
if (save_undo)
|
||||
@@ -178,6 +190,12 @@ gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer,
|
||||
void
|
||||
gui_input_text_cursor_moved_signal (struct t_gui_buffer *buffer)
|
||||
{
|
||||
if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input)
|
||||
&& gui_window_bare_display)
|
||||
{
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
}
|
||||
|
||||
(void) hook_signal_send ("input_text_cursor_moved",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
}
|
||||
@@ -189,6 +207,12 @@ gui_input_text_cursor_moved_signal (struct t_gui_buffer *buffer)
|
||||
void
|
||||
gui_input_search_signal (struct t_gui_buffer *buffer)
|
||||
{
|
||||
if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input)
|
||||
&& gui_window_bare_display)
|
||||
{
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
}
|
||||
|
||||
(void) hook_signal_send ("input_search",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
}
|
||||
@@ -385,6 +409,12 @@ gui_input_return (struct t_gui_buffer *buffer)
|
||||
struct t_gui_window *window;
|
||||
char *command;
|
||||
|
||||
if (CONFIG_BOOLEAN(config_look_bare_display_exit_on_input)
|
||||
&& gui_window_bare_display)
|
||||
{
|
||||
gui_window_bare_display_toggle (NULL);
|
||||
}
|
||||
|
||||
window = gui_window_search_with_buffer (buffer);
|
||||
if (window && window->buffer->input
|
||||
&& (window->buffer->input_buffer_size > 0))
|
||||
|
||||
+2
-1
@@ -1278,7 +1278,8 @@ gui_key_pressed (const char *key_str)
|
||||
if (pos)
|
||||
{
|
||||
pos[0] = '\0';
|
||||
gui_mouse_event_end ();
|
||||
if (!gui_window_bare_display)
|
||||
gui_mouse_event_end ();
|
||||
gui_mouse_event_init ();
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -67,6 +67,10 @@ struct t_gui_window_tree *gui_windows_tree = NULL; /* windows tree */
|
||||
int gui_window_cursor_x = 0; /* cursor pos on screen */
|
||||
int gui_window_cursor_y = 0; /* cursor pos on screen */
|
||||
|
||||
int gui_window_bare_display = 0; /* 1 for bare disp. (disable ncurses)*/
|
||||
struct t_hook *gui_window_bare_display_timer = NULL;
|
||||
/* timer for bare display */
|
||||
|
||||
|
||||
/*
|
||||
* Searches for a window by number.
|
||||
|
||||
@@ -124,6 +124,8 @@ extern struct t_gui_window *gui_current_window;
|
||||
extern struct t_gui_window_tree *gui_windows_tree;
|
||||
extern int gui_window_cursor_x;
|
||||
extern int gui_window_cursor_y;
|
||||
extern int gui_window_bare_display;
|
||||
extern struct t_hook *gui_window_bare_display_timer;
|
||||
|
||||
/* window functions */
|
||||
|
||||
@@ -229,6 +231,7 @@ extern void gui_window_switch_right (struct t_gui_window *window);
|
||||
extern int gui_window_balance (struct t_gui_window_tree *tree);
|
||||
extern void gui_window_swap (struct t_gui_window *window, int direction);
|
||||
extern void gui_window_refresh_screen (int full_refresh);
|
||||
extern void gui_window_bare_display_toggle (const char *delay);
|
||||
extern void gui_window_set_title (const char *title);
|
||||
extern void gui_window_send_clipboard (const char *storage_unit,
|
||||
const char *text);
|
||||
|
||||
Reference in New Issue
Block a user