Fix #809: clear screen before starting process, not on every event (#821)

This commit is contained in:
Félix Saparelli 2024-04-21 00:15:52 +12:00 committed by GitHub
parent 8ad12b1f65
commit 7535e17661
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -236,11 +236,40 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
);
});
let show_events = || {
if print_events {
trace!("print events to stderr");
for (n, event) in action.events.iter().enumerate() {
eprintln!("[EVENT {n}] {event}");
let show_events = {
let events = action.events.clone();
move || {
if print_events {
trace!("print events to stderr");
for (n, event) in events.iter().enumerate() {
eprintln!("[EVENT {n}] {event}");
}
}
}
};
let clear_screen = {
let events = action.events.clone();
move || {
if let Some(mode) = clear {
match mode {
ClearMode::Clear => {
clearscreen::clear().ok();
debug!("cleared screen");
}
ClearMode::Reset => {
reset_screen();
debug!("hard-reset screen");
}
}
}
// re-show events after clearing
if print_events {
trace!("print events to stderr");
for (n, event) in events.iter().enumerate() {
eprintln!("[EVENT {n}] {event}");
}
}
}
};
@ -333,28 +362,6 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
return action;
}
// clear the screen before printing events
if let Some(mode) = clear {
match mode {
ClearMode::Clear => {
clearscreen::clear().ok();
debug!("cleared screen");
}
ClearMode::Reset => {
for cs in [
ClearScreen::WindowsCooked,
ClearScreen::WindowsVt,
ClearScreen::VtLeaveAlt,
ClearScreen::VtWellDone,
ClearScreen::default(),
] {
cs.clear().ok();
}
debug!("hard-reset screen");
}
}
}
show_events();
if let Some(delay) = delay_run {
@ -388,6 +395,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
OnBusyUpdate::Restart if cfg!(windows) => {
job.restart();
job.run(move |context| {
clear_screen();
setup_process(
innerjob.clone(),
context.command.clone(),
@ -401,6 +409,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
stop_timeout,
);
job.run(move |context| {
clear_screen();
setup_process(
innerjob.clone(),
context.command.clone(),
@ -424,6 +433,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
trace!("job finished, starting queued");
job.start();
job.run(move |context| {
clear_screen();
setup_process(
innerjob.clone(),
context.command.clone(),
@ -442,6 +452,7 @@ pub fn make_config(args: &Args, state: &State) -> Result<Config> {
trace!("job is not running, start it");
job.start();
job.run(move |context| {
clear_screen();
setup_process(
innerjob.clone(),
context.command.clone(),