-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add synchronized output/update (#756)
- Loading branch information
1 parent
e7fc698
commit e065a56
Showing
6 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod attribute; | |
pub mod color; | ||
pub mod cursor; | ||
pub mod event; | ||
pub mod synchronized_output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::io::Write; | ||
|
||
use crossterm::{cursor, execute, style::Print, SynchronizedUpdate}; | ||
|
||
use crate::Result; | ||
|
||
fn render_slowly<W>(w: &mut W) -> Result<()> | ||
where | ||
W: Write, | ||
{ | ||
for i in 1..10 { | ||
execute!(w, Print(format!("{}", i)))?; | ||
std::thread::sleep(std::time::Duration::from_millis(50)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn test_slow_rendering<W>(w: &mut W) -> Result<()> | ||
where | ||
W: Write, | ||
{ | ||
execute!(w, Print("Rendering without synchronized update:"))?; | ||
execute!(w, cursor::MoveToNextLine(1))?; | ||
std::thread::sleep(std::time::Duration::from_millis(50)); | ||
render_slowly(w)?; | ||
|
||
execute!(w, cursor::MoveToNextLine(1))?; | ||
execute!(w, Print("Rendering with synchronized update:"))?; | ||
execute!(w, cursor::MoveToNextLine(1))?; | ||
std::thread::sleep(std::time::Duration::from_millis(50)); | ||
w.sync_update(render_slowly)??; | ||
|
||
execute!(w, cursor::MoveToNextLine(1))?; | ||
Ok(()) | ||
} | ||
|
||
pub fn run<W>(w: &mut W) -> Result<()> | ||
where | ||
W: Write, | ||
{ | ||
run_tests!(w, test_slow_rendering,); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters