Skip to content

Commit

Permalink
Clear status line to preserve clean conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfrishkorn committed Dec 19, 2023
1 parent 731828f commit e7b4d81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
};

// print the response
status.print("\n"); // reset cursor after progress output
status.print("\n"); // newline for readability
// print the response after clearing the status line
status.clear_line();
personality.speak(&text);
status.print("\n"); // I really like readability

Expand Down
8 changes: 8 additions & 0 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ impl Status {
Self { silent: true }
}

/// Clear a partially printed line that has not printed a final newline character
pub fn clear_line(&self) {
for _ in 0..100 {
self.print("\u{8}");
self.print("\r"); // just to be sure
}
}

/// Print text to standard error
pub fn print(&self, text: &str) {
if self.silent {
Expand Down

0 comments on commit e7b4d81

Please sign in to comment.