mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Clean up input initialization and destruction
This commit is contained in:
parent
dc1073f905
commit
ecf51b575e
6 changed files with 8 additions and 25 deletions
|
@ -298,7 +298,6 @@ static void setup_and_process_keys(bool continuous_mode) {
|
|||
process_input(continuous_mode);
|
||||
restore_term_mode();
|
||||
restore_term_foreground_process_group();
|
||||
input_destroy();
|
||||
}
|
||||
|
||||
static bool parse_debug_level_flag() {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <termios.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -153,9 +154,6 @@ static std::vector<terminfo_mapping_t> terminfo_mappings;
|
|||
/// List of all terminfo mappings.
|
||||
static std::vector<terminfo_mapping_t> mappings;
|
||||
|
||||
/// Set to true when the input subsystem has been initialized.
|
||||
bool input_initialized = false;
|
||||
|
||||
/// Initialize terminfo.
|
||||
static void init_input_terminfo();
|
||||
|
||||
|
@ -263,9 +261,15 @@ static int interrupt_handler() {
|
|||
return R_NULL;
|
||||
}
|
||||
|
||||
static std::atomic<bool> input_initialized{false};
|
||||
|
||||
/// Set up arrays used by readch to detect escape sequences for special keys and perform related
|
||||
/// initializations for our input subsystem.
|
||||
void init_input() {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
if (input_initialized.load(std::memory_order_relaxed)) return;
|
||||
input_initialized.store(true, std::memory_order_relaxed);
|
||||
|
||||
input_common_init(&interrupt_handler);
|
||||
init_input_terminfo();
|
||||
|
||||
|
@ -285,14 +289,6 @@ void init_input() {
|
|||
input_mapping_add(L"\x1B[C", L"forward-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
|
||||
input_mapping_add(L"\x1B[D", L"backward-char", DEFAULT_BIND_MODE, DEFAULT_BIND_MODE, false);
|
||||
}
|
||||
|
||||
input_initialized = true;
|
||||
}
|
||||
|
||||
void input_destroy() {
|
||||
if (!input_initialized) return;
|
||||
input_initialized = false;
|
||||
input_common_destroy();
|
||||
}
|
||||
|
||||
void input_function_push_arg(wchar_t arg) {
|
||||
|
|
|
@ -16,16 +16,10 @@ class environment_t;
|
|||
|
||||
wcstring describe_char(wint_t c);
|
||||
|
||||
/// Set to true when the input subsytem has been initialized.
|
||||
extern bool input_initialized;
|
||||
|
||||
/// Set up arrays used by readch to detect escape sequences for special keys and perform related
|
||||
/// initializations for our input subsystem.
|
||||
void init_input();
|
||||
|
||||
/// free up memory used by terminal functions.
|
||||
void input_destroy();
|
||||
|
||||
/// Read a character from fd 0. Try to convert some escape sequences into character constants, but
|
||||
/// do not permanently block the escape character.
|
||||
///
|
||||
|
|
|
@ -61,8 +61,6 @@ static int (*interrupt_handler)();
|
|||
|
||||
void input_common_init(int (*ih)()) { interrupt_handler = ih; }
|
||||
|
||||
void input_common_destroy() {}
|
||||
|
||||
/// Internal function used by input_common_readch to read one byte from fd 0. This function should
|
||||
/// only be called by input_common_readch().
|
||||
static wint_t readb() {
|
||||
|
|
|
@ -85,9 +85,6 @@ enum {
|
|||
/// Init the library.
|
||||
void input_common_init(int (*ih)());
|
||||
|
||||
/// Free memory used by the library.
|
||||
void input_common_destroy();
|
||||
|
||||
/// Adjust the escape timeout.
|
||||
void update_wait_on_escape_ms(const environment_t &vars);
|
||||
|
||||
|
|
|
@ -1731,7 +1731,7 @@ static void reader_interactive_init() {
|
|||
// See if we are running interactively.
|
||||
pid_t shell_pgid;
|
||||
|
||||
if (!input_initialized) init_input();
|
||||
init_input();
|
||||
shell_pgid = getpgrp();
|
||||
|
||||
// This should enable job control on fish, even if our parent process did not enable it for us.
|
||||
|
@ -1846,7 +1846,6 @@ static void reader_interactive_init() {
|
|||
/// Destroy data for interactive use.
|
||||
static void reader_interactive_destroy() {
|
||||
outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset());
|
||||
input_destroy();
|
||||
}
|
||||
|
||||
void reader_sanity_check() {
|
||||
|
|
Loading…
Reference in a new issue