Skip to content

Commit

Permalink
Flush I/O after writing to it
Browse files Browse the repository at this point in the history
May help in some cases where line buffering is preventing the
application of the clearing sequences. See #1.
  • Loading branch information
passcod committed May 22, 2021
1 parent 4e92381 commit 347afec
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib.rs
Expand Up @@ -441,6 +441,7 @@ impl ClearScreen {

if let Some(seq) = info.get::<capability::ClearScreen>() {
seq.expand().with(&mut ctx).to(&mut w)?;
w.flush()?;
} else {
return Err(Error::TerminfoCap("clear"));
}
Expand All @@ -452,15 +453,17 @@ impl ClearScreen {
Self::TerminfoScreen => {
let info = Database::from_env()?;
if let Some(seq) = info.get::<capability::ClearScreen>() {
seq.expand().to(w)?;
seq.expand().to(&mut w)?;
w.flush()?;
} else {
return Err(Error::TerminfoCap("clear"));
}
}
Self::TerminfoScrollback => {
let info = Database::from_env()?;
if let Some(seq) = info.get::<ResetScrollback>() {
seq.expand().to(w)?;
seq.expand().to(&mut w)?;
w.flush()?;
} else {
return Err(Error::TerminfoCap("E3"));
}
Expand All @@ -487,6 +490,8 @@ impl ClearScreen {
seq.expand().with(&mut ctx).to(&mut w)?;
}

w.flush()?;

if reset {
return Ok(());
}
Expand All @@ -508,6 +513,8 @@ impl ClearScreen {
seq.expand().with(&mut ctx).to(&mut w)?;
}

w.flush()?;

if !reset {
return Err(Error::TerminfoCap("reset"));
}
Expand All @@ -525,6 +532,8 @@ impl ClearScreen {

w.write_all(CSI)?;
w.write_all(ERASE_SCROLLBACK)?;

w.flush()?;
}
Self::XtermReset => {
const STR: &[u8] = b"!p";
Expand All @@ -550,6 +559,8 @@ impl ClearScreen {

w.write_all(CSI)?;
w.write_all(RESET_MARGINS)?;

w.flush()?;
}
Self::TputClear => {
let status = Command::new("tput").arg("clear").status()?;
Expand Down Expand Up @@ -583,11 +594,13 @@ impl ClearScreen {
Self::VtRis => {
w.write_all(ESC)?;
w.write_all(RIS)?;
w.flush()?;
}
Self::VtLeaveAlt => {
const LEAVE_ALT: &[u8] = b"?1049l";
w.write_all(CSI)?;
w.write_all(LEAVE_ALT)?;
w.flush()?;
}
Self::VtCooked => unix::vt_cooked()?,
Self::VtWellDone => unix::vt_well_done()?,
Expand Down

0 comments on commit 347afec

Please sign in to comment.