mirror of https://github.com/fdehau/tui-rs
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.9 KiB
Rust
45 lines
1.9 KiB
Rust
4 years ago
|
use tui::{
|
||
|
backend::TestBackend,
|
||
|
buffer::Buffer,
|
||
|
layout::{Constraint, Direction, Layout},
|
||
|
widgets::{Block, Borders, Gauge},
|
||
|
Terminal,
|
||
|
};
|
||
6 years ago
|
|
||
|
#[test]
|
||
|
fn gauge_render() {
|
||
|
let backend = TestBackend::new(40, 10);
|
||
|
let mut terminal = Terminal::new(backend).unwrap();
|
||
|
terminal
|
||
|
.draw(|mut f| {
|
||
|
let chunks = Layout::default()
|
||
|
.direction(Direction::Vertical)
|
||
|
.margin(2)
|
||
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||
6 years ago
|
.split(f.size());
|
||
6 years ago
|
|
||
5 years ago
|
let gauge = Gauge::default()
|
||
6 years ago
|
.block(Block::default().title("Percentage").borders(Borders::ALL))
|
||
5 years ago
|
.percent(43);
|
||
|
f.render_widget(gauge, chunks[0]);
|
||
|
let gauge = Gauge::default()
|
||
6 years ago
|
.block(Block::default().title("Ratio").borders(Borders::ALL))
|
||
5 years ago
|
.ratio(0.211_313_934_313_1);
|
||
|
f.render_widget(gauge, chunks[1]);
|
||
6 years ago
|
})
|
||
|
.unwrap();
|
||
6 years ago
|
let expected = Buffer::with_lines(vec![
|
||
|
" ",
|
||
|
" ",
|
||
|
" ┌Percentage────────────────────────┐ ",
|
||
|
" │ 43% │ ",
|
||
|
" └──────────────────────────────────┘ ",
|
||
|
" ┌Ratio─────────────────────────────┐ ",
|
||
|
" │ 21% │ ",
|
||
|
" └──────────────────────────────────┘ ",
|
||
|
" ",
|
||
|
" ",
|
||
|
]);
|
||
4 years ago
|
terminal.backend().assert_buffer(&expected);
|
||
6 years ago
|
}
|