mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-28 09:31:16 -03:00
Remove redundant saving of TTY flags
The logic added by 2dbaf10c36 (Also refresh TTY timestamps
after external commands from bindings, 2024-10-21) is obsoleted
by TtyHandoff. That module is also responsible for calling
reader_save_screen_state after it writes to the TTY, so we don't
actually need to check if it wrote anything.
This commit is contained in:
@@ -1344,7 +1344,6 @@ fn exec_process_in_job(
|
||||
piped_output_needs_buffering,
|
||||
),
|
||||
ProcessType::External => {
|
||||
parser.libdata_mut().exec_external_count += 1;
|
||||
exec_external_command(parser, j, p, &process_net_io_chain)?;
|
||||
// It's possible (though unlikely) that this is a background process which recycled a
|
||||
// pid from another, previous background process. Forget any such old process.
|
||||
|
||||
@@ -285,9 +285,6 @@ pub struct LibraryData {
|
||||
/// A counter incremented every time a command executes.
|
||||
pub exec_count: u64,
|
||||
|
||||
/// A counter incremented every time an external command executes.
|
||||
pub exec_external_count: u64,
|
||||
|
||||
/// A counter incremented every time a command produces a $status.
|
||||
pub status_count: u64,
|
||||
|
||||
|
||||
@@ -2366,9 +2366,7 @@ fn readline(
|
||||
}
|
||||
|
||||
// Disable tty protocols now that we're going to execute a command.
|
||||
if tty.disable_tty_protocols() {
|
||||
self.save_screen_state();
|
||||
}
|
||||
tty.disable_tty_protocols();
|
||||
|
||||
if self.conf.transient_prompt {
|
||||
self.exec_prompt(true, true);
|
||||
@@ -2428,20 +2426,13 @@ fn readline(
|
||||
|
||||
fn eval_bind_cmd(&mut self, cmd: &wstr) {
|
||||
let last_statuses = self.parser.vars().get_last_statuses();
|
||||
let prev_exec_external_count = self.parser.libdata().exec_external_count;
|
||||
// Disable TTY protocols while we run a bind command, because it may call out.
|
||||
let mut scoped_tty = TtyHandoff::new(reader_save_screen_state);
|
||||
let mut modified_tty = scoped_tty.disable_tty_protocols();
|
||||
scoped_tty.disable_tty_protocols();
|
||||
|
||||
self.parser.eval(cmd, &IoChain::new());
|
||||
self.parser.set_last_statuses(last_statuses);
|
||||
modified_tty |= scoped_tty.reclaim();
|
||||
if modified_tty
|
||||
|| (self.parser.libdata().exec_external_count != prev_exec_external_count
|
||||
&& self.data.left_prompt_buff.contains('\n'))
|
||||
{
|
||||
self.save_screen_state();
|
||||
}
|
||||
scoped_tty.reclaim();
|
||||
}
|
||||
|
||||
/// Run a sequence of commands from an input binding.
|
||||
@@ -2928,9 +2919,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) {
|
||||
let mut tty = TtyHandoff::new(reader_save_screen_state);
|
||||
tty.disable_tty_protocols();
|
||||
self.compute_and_apply_completions(c);
|
||||
if tty.reclaim() {
|
||||
self.save_screen_state();
|
||||
}
|
||||
tty.reclaim();
|
||||
}
|
||||
}
|
||||
rl::PagerToggleSearch => {
|
||||
|
||||
@@ -271,17 +271,17 @@ pub fn initialize_tty_protocols(vars: &dyn Environment) {
|
||||
// Enable or disable TTY protocols by writing the appropriate commands to the tty.
|
||||
// Return true if we emitted any bytes to the tty.
|
||||
// Note this does NOT intialize the TTY protocls if not already initialized.
|
||||
fn set_tty_protocols_active(on_write: fn(), enable: bool) -> bool {
|
||||
fn set_tty_protocols_active(on_write: fn(), enable: bool) {
|
||||
assert_is_main_thread();
|
||||
// Have protocols at all? We require someone else to have initialized them.
|
||||
let Some(protocols) = tty_protocols() else {
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
// Already set?
|
||||
// Note we don't need atomic swaps as this is only called on the main thread.
|
||||
// Also note we (logically) set and clear this even if we got SIGHUP.
|
||||
if TTY_PROTOCOLS_ACTIVE.load(Ordering::Relaxed) == enable {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if enable {
|
||||
TTY_PROTOCOLS_ACTIVE.store(true, Ordering::Release);
|
||||
@@ -289,7 +289,7 @@ fn set_tty_protocols_active(on_write: fn(), enable: bool) -> bool {
|
||||
|
||||
// Did we get SIGHUP?
|
||||
if TTY_INVALID.load() {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Write the commands to the tty, ignoring errors.
|
||||
@@ -308,7 +308,6 @@ fn set_tty_protocols_active(on_write: fn(), enable: bool) -> bool {
|
||||
ProtocolKind::None => (),
|
||||
};
|
||||
(on_write)();
|
||||
true
|
||||
}
|
||||
|
||||
// Helper to check if TTY protocols are active.
|
||||
@@ -385,22 +384,22 @@ pub fn new(on_write: fn()) -> Self {
|
||||
|
||||
/// Mark terminal modes as enabled.
|
||||
/// Return true if something was written to the tty.
|
||||
pub fn enable_tty_protocols(&mut self) -> bool {
|
||||
pub fn enable_tty_protocols(&mut self) {
|
||||
if self.tty_protocols_applied {
|
||||
return false; // Already enabled.
|
||||
return; // Already enabled.
|
||||
}
|
||||
self.tty_protocols_applied = true;
|
||||
set_tty_protocols_active(self.on_write, true)
|
||||
set_tty_protocols_active(self.on_write, true);
|
||||
}
|
||||
|
||||
/// Mark terminal modes as disabled.
|
||||
/// Return true if something was written to the tty.
|
||||
pub fn disable_tty_protocols(&mut self) -> bool {
|
||||
pub fn disable_tty_protocols(&mut self) {
|
||||
if !self.tty_protocols_applied {
|
||||
return false; // Already disabled.
|
||||
return; // Already disabled.
|
||||
};
|
||||
self.tty_protocols_applied = false;
|
||||
set_tty_protocols_active(self.on_write, false)
|
||||
set_tty_protocols_active(self.on_write, false);
|
||||
}
|
||||
|
||||
/// Transfer to the given job group, if it wants to own the terminal.
|
||||
@@ -415,7 +414,7 @@ pub fn to_job_group(&mut self, jg: &JobGroupRef) {
|
||||
/// Reclaim the tty if we transferred it.
|
||||
/// Returns true if data was written to the tty, as part of
|
||||
/// re-enabling terminal protocols.
|
||||
pub fn reclaim(mut self) -> bool {
|
||||
pub fn reclaim(mut self) {
|
||||
self.reclaim_impl()
|
||||
}
|
||||
|
||||
@@ -425,7 +424,7 @@ pub fn release(mut self) {
|
||||
}
|
||||
|
||||
/// Implementation of reclaim, factored out for use in Drop.
|
||||
fn reclaim_impl(&mut self) -> bool {
|
||||
fn reclaim_impl(&mut self) {
|
||||
assert!(!self.reclaimed, "Terminal already reclaimed");
|
||||
self.reclaimed = true;
|
||||
if self.owner.is_some() {
|
||||
@@ -442,9 +441,9 @@ fn reclaim_impl(&mut self) -> bool {
|
||||
}
|
||||
// Restore the terminal protocols. Note this does nothing if they were unchanged.
|
||||
if self.tty_protocols_initial {
|
||||
self.enable_tty_protocols()
|
||||
self.enable_tty_protocols();
|
||||
} else {
|
||||
self.disable_tty_protocols()
|
||||
self.disable_tty_protocols();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user