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 7b57c91
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 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 @@ -453,6 +454,7 @@ impl ClearScreen {
let info = Database::from_env()?;
if let Some(seq) = info.get::<capability::ClearScreen>() {
seq.expand().to(w)?;
w.flush()?;
} else {
return Err(Error::TerminfoCap("clear"));
}
Expand All @@ -461,6 +463,7 @@ impl ClearScreen {
let info = Database::from_env()?;
if let Some(seq) = info.get::<ResetScrollback>() {
seq.expand().to(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 7b57c91

Please sign in to comment.