diff options
Diffstat (limited to 'terminal.c')
-rw-r--r-- | terminal.c | 87 |
1 files changed, 83 insertions, 4 deletions
@@ -1,6 +1,6 @@ /* terminal.c -- controlling the terminal with termcap. */ -/* Copyright (C) 1996-2021 Free Software Foundation, Inc. +/* Copyright (C) 1996-2022 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -185,6 +185,11 @@ static char *_rl_term_kN; static char *_rl_term_vs; /* very visible */ static char *_rl_term_ve; /* normal */ +/* User-settable color sequences to begin and end the active region. Defaults + are rl_term_so and rl_term_se on non-dumb terminals. */ +char *_rl_active_region_start_color = NULL; +char *_rl_active_region_end_color = NULL; + /* It's not clear how HPUX is so broken here. */ #ifdef TGETENT_BROKEN # define TGETENT_SUCCESS 0 @@ -466,7 +471,7 @@ _rl_init_terminal_io (const char *terminal_name) { const char *term; char *buffer; - int tty, tgetent_ret, dumbterm; + int tty, tgetent_ret, dumbterm, reset_region_colors; term = terminal_name ? terminal_name : sh_get_env_value ("TERM"); _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = _rl_term_clrscroll = (char *)NULL; @@ -477,6 +482,8 @@ _rl_init_terminal_io (const char *terminal_name) dumbterm = STREQ (term, "dumb"); + reset_region_colors = 1; + #ifdef __MSDOS__ _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; @@ -562,6 +569,11 @@ _rl_init_terminal_io (const char *terminal_name) escape sequences */ _rl_enable_bracketed_paste = 0; + /* No terminal so/se capabilities. */ + _rl_enable_active_region = 0; + _rl_reset_region_color (0, NULL); + _rl_reset_region_color (1, NULL); + /* Reasonable defaults for tgoto(). Readline currently only uses tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we change that later... */ @@ -616,8 +628,14 @@ _rl_init_terminal_io (const char *terminal_name) /* There's no way to determine whether or not a given terminal supports bracketed paste mode, so we assume a terminal named "dumb" does not. */ if (dumbterm) - _rl_enable_bracketed_paste = 0; - + _rl_enable_bracketed_paste = _rl_enable_active_region = 0; + + if (reset_region_colors) + { + _rl_reset_region_color (0, _rl_term_so); + _rl_reset_region_color (1, _rl_term_se); + } + return 0; } @@ -791,6 +809,67 @@ _rl_standout_off (void) /* **************************************************************** */ /* */ +/* Controlling color for a portion of the line */ +/* */ +/* **************************************************************** */ + +/* Reset the region color variables to VALUE depending on WHICH (0 == start, + 1 == end). This is where all the memory allocation for the color variable + strings is performed. We might want to pass a flag saying whether or not + to translate VALUE like a key sequence, but it doesn't really matter. */ +int +_rl_reset_region_color (int which, const char *value) +{ + int len; + + if (which == 0) + { + xfree (_rl_active_region_start_color); + if (value && *value) + { + _rl_active_region_start_color = (char *)xmalloc (2 * strlen (value) + 1); + rl_translate_keyseq (value, _rl_active_region_start_color, &len); + _rl_active_region_start_color[len] = '\0'; + } + else + _rl_active_region_start_color = NULL; + } + else + { + xfree (_rl_active_region_end_color); + if (value && *value) + { + _rl_active_region_end_color = (char *)xmalloc (2 * strlen (value) + 1); + rl_translate_keyseq (value, _rl_active_region_end_color, &len); + _rl_active_region_end_color[len] = '\0'; + } + else + _rl_active_region_end_color = NULL; + } + + return 0; +} + +void +_rl_region_color_on (void) +{ +#ifndef __MSDOS__ + if (_rl_active_region_start_color && _rl_active_region_end_color) + tputs (_rl_active_region_start_color, 1, _rl_output_character_function); +#endif +} + +void +_rl_region_color_off (void) +{ +#ifndef __MSDOS__ + if (_rl_active_region_start_color && _rl_active_region_end_color) + tputs (_rl_active_region_end_color, 1, _rl_output_character_function); +#endif +} + +/* **************************************************************** */ +/* */ /* Controlling the Meta Key and Keypad */ /* */ /* **************************************************************** */ |