mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-04 07:21:14 -03:00
Don't initialize interactive reader redundantly
Commands like fish -C 'read' create two top-level readers one after the other. The second one is the fish REPL. Both run some initialization of globals and parser variables. This is weird; it should not be necessary. Let's call reader_interactive_init() only once.
This commit is contained in:
@@ -404,6 +404,8 @@ pub enum CancelBehavior {
|
||||
}
|
||||
|
||||
pub struct Parser {
|
||||
pub interactive_initialized: RelaxedAtomicBool,
|
||||
|
||||
/// A shared line counter. This is handed out to each execution context
|
||||
/// so they can communicate the line number back to this Parser.
|
||||
line_counter: ScopedRefCell<LineCounter<ast::JobPipeline>>,
|
||||
@@ -449,6 +451,7 @@ impl Parser {
|
||||
/// Create a parser.
|
||||
pub fn new(variables: EnvStack, cancel_behavior: CancelBehavior) -> Parser {
|
||||
let result = Self {
|
||||
interactive_initialized: RelaxedAtomicBool::new(false),
|
||||
line_counter: ScopedRefCell::new(LineCounter::empty()),
|
||||
job_list: RefCell::default(),
|
||||
wait_handles: RefCell::new(WaitHandleStore::new()),
|
||||
|
||||
@@ -315,12 +315,11 @@ pub fn reader_push<'a>(parser: &'a Parser, history_name: &wstr, conf: ReaderConf
|
||||
assert_is_main_thread();
|
||||
let hist = History::with_name(history_name);
|
||||
hist.resolve_pending();
|
||||
let is_top_level = reader_data_stack().is_empty();
|
||||
let data = ReaderData::new(hist, conf, is_top_level);
|
||||
let data = ReaderData::new(hist, conf, reader_data_stack().is_empty());
|
||||
reader_data_stack().push(data);
|
||||
let data = current_data().unwrap();
|
||||
data.command_line_changed(EditableLineTag::Commandline, AutosuggestionUpdate::Remove);
|
||||
if is_top_level {
|
||||
if !parser.interactive_initialized.swap(true) {
|
||||
reader_interactive_init(parser);
|
||||
}
|
||||
Reader { data, parser }
|
||||
@@ -335,7 +334,7 @@ pub fn reader_pop() {
|
||||
.screen
|
||||
.reset_abandoning_line(usize::try_from(termsize_last().width).unwrap());
|
||||
} else {
|
||||
reader_interactive_destroy();
|
||||
Outputter::stdoutput().borrow_mut().reset_text_face();
|
||||
*commandline_state_snapshot() = CommandlineState::new();
|
||||
}
|
||||
}
|
||||
@@ -4548,11 +4547,6 @@ fn reader_interactive_init(parser: &Parser) {
|
||||
initialize_tty_metadata();
|
||||
}
|
||||
|
||||
/// Destroy data for interactive use.
|
||||
fn reader_interactive_destroy() {
|
||||
Outputter::stdoutput().borrow_mut().reset_text_face();
|
||||
}
|
||||
|
||||
/// Return whether fish is currently unwinding the stack in preparation to exit.
|
||||
pub fn fish_is_unwinding_for_exit() -> bool {
|
||||
let exit_state = EXIT_STATE.load(Ordering::Relaxed);
|
||||
|
||||
Reference in New Issue
Block a user