mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
core: add automatic reset of color pairs, new option weechat.look.color_pairs_auto_reset
This commit is contained in:
@@ -4754,8 +4754,9 @@ command_init ()
|
||||
" color: color number (>= 0, max depends on terminal, "
|
||||
"commonly 63 or 255)\n"
|
||||
" name: alias name for color (for example: \"orange\")\n"
|
||||
" reset: reset all color pairs (useful when no more "
|
||||
"pairs are available)\n\n"
|
||||
" reset: reset all color pairs (required when no more "
|
||||
"color pairs are available if automatic reset is disabled, "
|
||||
"see option weechat.look.color_pairs_auto_reset)\n\n"
|
||||
"Without argument, this command displays colors in a new "
|
||||
"buffer.\n\n"
|
||||
"Examples:\n"
|
||||
|
||||
@@ -79,6 +79,7 @@ struct t_config_option *config_startup_display_version;
|
||||
struct t_config_option *config_look_align_end_of_lines;
|
||||
struct t_config_option *config_look_buffer_notify_default;
|
||||
struct t_config_option *config_look_buffer_time_format;
|
||||
struct t_config_option *config_look_color_pairs_auto_reset;
|
||||
struct t_config_option *config_look_color_real_white;
|
||||
struct t_config_option *config_look_command_chars;
|
||||
struct t_config_option *config_look_confirm_quit;
|
||||
@@ -1556,6 +1557,14 @@ config_weechat_init_options ()
|
||||
"\"${color}\", for example french time: "
|
||||
"\"${lightblue}%H${white}%M${lightred}%S\""),
|
||||
NULL, 0, 0, "%H:%M:%S", NULL, 0, NULL, NULL, &config_change_buffer_time_format, NULL, NULL, NULL);
|
||||
config_look_color_pairs_auto_reset = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"color_pairs_auto_reset", "integer",
|
||||
N_("automatically reset table of color pairs when number of available "
|
||||
"pairs is lower or equal to this number (-1 = disable automatic "
|
||||
"reset, and then a manual \"/color reset\" is needed when table "
|
||||
"is full)"),
|
||||
NULL, -1, 256, "5", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
config_look_color_real_white = config_file_new_option (
|
||||
weechat_config_file, ptr_section,
|
||||
"color_real_white", "boolean",
|
||||
|
||||
@@ -108,6 +108,7 @@ extern struct t_config_option *config_look_buffer_notify_default;
|
||||
extern struct t_config_option *config_look_buffer_time_format;
|
||||
extern struct t_config_option *config_look_command_chars;
|
||||
extern struct t_config_option *config_look_confirm_quit;
|
||||
extern struct t_config_option *config_look_color_pairs_auto_reset;
|
||||
extern struct t_config_option *config_look_color_real_white;
|
||||
extern struct t_config_option *config_look_day_change;
|
||||
extern struct t_config_option *config_look_day_change_time_format;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-config.h"
|
||||
@@ -80,6 +81,9 @@ int gui_color_num_pairs = 63; /* number of pairs used by WeeChat */
|
||||
short *gui_color_pairs = NULL; /* table with pair for each fg+bg */
|
||||
int gui_color_pairs_used = 0; /* number of pairs currently used */
|
||||
int gui_color_warning_pairs_full = 0; /* warning displayed? */
|
||||
int gui_color_pairs_auto_reset = 0; /* auto reset of pairs needed */
|
||||
int gui_color_pairs_auto_reset_pending = 0; /* auto reset is pending */
|
||||
time_t gui_color_pairs_auto_reset_last = 0; /* time of last auto reset */
|
||||
|
||||
/* color buffer */
|
||||
struct t_gui_buffer *gui_color_buffer = NULL; /* buffer with colors */
|
||||
@@ -343,8 +347,10 @@ gui_color_get_pair (int fg, int bg)
|
||||
if (gui_color_pairs_used >= gui_color_num_pairs)
|
||||
{
|
||||
/* oh no, no more pair available! */
|
||||
if (!gui_color_warning_pairs_full)
|
||||
if (!gui_color_warning_pairs_full
|
||||
&& (CONFIG_INTEGER(config_look_color_pairs_auto_reset) < 0))
|
||||
{
|
||||
/* display warning if auto reset of pairs is disabled */
|
||||
hook_timer (NULL, 1, 0, 1,
|
||||
&gui_color_timer_warning_pairs_full, NULL);
|
||||
gui_color_warning_pairs_full = 1;
|
||||
@@ -356,6 +362,12 @@ gui_color_get_pair (int fg, int bg)
|
||||
gui_color_pairs_used++;
|
||||
gui_color_pairs[index] = gui_color_pairs_used;
|
||||
init_pair (gui_color_pairs_used, fg, bg);
|
||||
if ((gui_color_num_pairs > 1) && !gui_color_pairs_auto_reset_pending
|
||||
&& (CONFIG_INTEGER(config_look_color_pairs_auto_reset) >= 0)
|
||||
&& (gui_color_num_pairs - gui_color_pairs_used <= CONFIG_INTEGER(config_look_color_pairs_auto_reset)))
|
||||
{
|
||||
gui_color_pairs_auto_reset = 1;
|
||||
}
|
||||
gui_color_buffer_refresh_needed = 1;
|
||||
}
|
||||
|
||||
@@ -812,6 +824,13 @@ gui_color_buffer_display ()
|
||||
|
||||
if (gui_color_buffer_extra_info)
|
||||
{
|
||||
/* display time of last auto reset of color pairs */
|
||||
y++;
|
||||
gui_chat_printf_y (gui_color_buffer, y++,
|
||||
_("Last auto reset of pairs: %s"),
|
||||
(gui_color_pairs_auto_reset_last == 0) ?
|
||||
"-" : ctime (&gui_color_pairs_auto_reset_last));
|
||||
|
||||
/* display WeeChat basic colors */
|
||||
y++;
|
||||
gui_chat_printf_y (gui_color_buffer, y++,
|
||||
@@ -1074,7 +1093,7 @@ gui_color_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else if (string_strcasecmp (input_data, "z") == 0)
|
||||
{
|
||||
gui_color_reset_pairs (buffer);
|
||||
gui_color_reset_pairs ();
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-command.h"
|
||||
@@ -224,7 +225,7 @@ gui_main_refreshs ()
|
||||
struct t_gui_window *ptr_win;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
|
||||
/* refresh color buffer if needed */
|
||||
if (gui_color_buffer_refresh_needed)
|
||||
{
|
||||
@@ -325,11 +326,22 @@ gui_main_loop ()
|
||||
|
||||
/* execute hook timers */
|
||||
hook_timer_exec ();
|
||||
|
||||
/* auto reset of color pairs */
|
||||
if (gui_color_pairs_auto_reset)
|
||||
{
|
||||
gui_color_reset_pairs ();
|
||||
gui_color_pairs_auto_reset_last = time (NULL);
|
||||
gui_color_pairs_auto_reset = 0;
|
||||
gui_color_pairs_auto_reset_pending = 1;
|
||||
}
|
||||
|
||||
gui_main_refreshs ();
|
||||
if (gui_window_refresh_needed)
|
||||
gui_main_refreshs ();
|
||||
|
||||
gui_color_pairs_auto_reset_pending = 0;
|
||||
|
||||
/* wait for keyboard or network activity */
|
||||
FD_ZERO (&read_fds);
|
||||
FD_ZERO (&write_fds);
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef __WEECHAT_GUI_CURSES_H
|
||||
#define __WEECHAT_GUI_CURSES_H 1
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_NCURSESW_CURSES_H
|
||||
#include <ncursesw/ncurses.h>
|
||||
#elif HAVE_NCURSES_H
|
||||
@@ -59,6 +61,9 @@ extern int gui_term_cols, gui_term_lines;
|
||||
extern struct t_gui_color gui_weechat_colors[];
|
||||
extern int gui_color_term_colors;
|
||||
extern int gui_color_num_pairs;
|
||||
extern int gui_color_pairs_auto_reset;
|
||||
extern int gui_color_pairs_auto_reset_pending;
|
||||
extern time_t gui_color_pairs_auto_reset_last;
|
||||
extern int gui_color_buffer_refresh_needed;
|
||||
|
||||
/* color functions */
|
||||
|
||||
Reference in New Issue
Block a user