Change MainThread<T> abstraction

Don't force the internal use of `RefCell<T>`, let the caller place that into
`MainThread<>` manually. This lets us remove the reference to `MainThread<>`
from the definition of `Screen` again and reduces the number of
`assert_is_main_thread()` calls.
This commit is contained in:
Mahmoud Al-Qudsi
2024-03-01 19:42:43 -06:00
parent 5c94ebd095
commit 2ecbc56de9
4 changed files with 47 additions and 59 deletions

View File

@@ -1902,7 +1902,8 @@ fn readline(&mut self, nchars: Option<NonZeroUsize>) -> Option<WString> {
perror("tcsetattr"); // return to previous mode
}
Outputter::stdoutput()
.with_mut(|output| output.set_color(RgbColor::RESET, RgbColor::RESET));
.borrow_mut()
.set_color(RgbColor::RESET, RgbColor::RESET);
}
rls.finished.then(|| zelf.command_line.text().to_owned())
}
@@ -2941,9 +2942,9 @@ fn handle_readline_command(&mut self, c: ReadlineCmd, rls: &mut ReadlineLoopStat
el.end_edit_group();
}
rl::DisableMouseTracking => {
Outputter::stdoutput().with_mut(|outp| {
outp.write_wstr(L!("\x1B[?1000l"));
});
Outputter::stdoutput()
.borrow_mut()
.write_wstr(L!("\x1B[?1000l"));
}
rl::ClearScreenAndRepaint => {
self.parser().libdata_mut().pods.is_repaint = true;
@@ -2954,9 +2955,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd, rls: &mut ReadlineLoopStat
// and *then* reexecute the prompt and overdraw it.
// This removes the flicker,
// while keeping the prompt up-to-date.
Outputter::stdoutput().with_mut(|outp| {
outp.write_wstr(&clear);
});
Outputter::stdoutput().borrow_mut().write_wstr(&clear);
self.screen.reset_line(/*repaint_prompt=*/ true);
self.layout_and_repaint(L!("readline"));
}
@@ -3488,9 +3487,9 @@ fn reader_interactive_init(parser: &Parser) {
/// Destroy data for interactive use.
fn reader_interactive_destroy() {
Outputter::stdoutput().with_mut(|outp| {
outp.set_color(RgbColor::RESET, RgbColor::RESET);
});
Outputter::stdoutput()
.borrow_mut()
.set_color(RgbColor::RESET, RgbColor::RESET);
}
/// \return whether fish is currently unwinding the stack in preparation to exit.
@@ -3571,9 +3570,9 @@ pub fn reader_write_title(
let _ = write_loop(&STDOUT_FILENO, &narrow);
}
Outputter::stdoutput().with_mut(|outp| {
outp.set_color(RgbColor::RESET, RgbColor::RESET);
});
Outputter::stdoutput()
.borrow_mut()
.set_color(RgbColor::RESET, RgbColor::RESET);
if reset_cursor_position && !lst.is_empty() {
// Put the cursor back at the beginning of the line (issue #2453).
let _ = write_to_fd(b"\r", STDOUT_FILENO);
@@ -4585,7 +4584,9 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes {
}
reader_write_title(cmd, parser, true);
Outputter::stdoutput().with_mut(|outp| outp.set_color(RgbColor::NORMAL, RgbColor::NORMAL));
Outputter::stdoutput()
.borrow_mut()
.set_color(RgbColor::NORMAL, RgbColor::NORMAL);
term_donate(false);
let time_before = Instant::now();