1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 19:23:13 +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:
Sebastien Helleu
2014-02-16 11:29:03 +01:00
parent 20a70c80f8
commit 39be4e3387
46 changed files with 706 additions and 577 deletions
+3
View File
@@ -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;
+147
View File
@@ -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;
}
+1
View File
@@ -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++)
+17 -16
View File
@@ -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)
+72 -32
View File
@@ -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.
*
-1
View File
@@ -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);