diff --git a/src/parser.rs b/src/parser.rs index dd4ef9f7d..b92385399 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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>, @@ -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()), diff --git a/src/reader.rs b/src/reader.rs index dae636d9f..3a2d53658 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -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);