diff --git a/Cargo.toml b/Cargo.toml index 40b482b7..18a202c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ keywords = ["tui", "terminal", "dashboard"] repository = "https://github.com/fdehau/tui-rs" license = "MIT" exclude = ["docs/*", ".travis.yml"] +autoexamples = true [badges] travis-ci = { repository = "fdehau/tui-rs" } @@ -31,63 +32,7 @@ rustbox = { version = "0.11.0", optional = true } stderrlog = "0.3.0" rand = "0.4.2" -[[example]] -name = "barchart" -path = "examples/barchart.rs" - -[[example]] -name = "block" -path = "examples/block.rs" - -[[example]] -name = "canvas" -path = "examples/canvas.rs" - -[[example]] -name = "chart" -path = "examples/chart.rs" - -[[example]] -name = "custom_widget" -path = "examples/custom_widget.rs" - -[[example]] -name = "demo" -path = "examples/demo.rs" - -[[example]] -name = "gauge" -path = "examples/gauge.rs" - -[[example]] -name = "list" -path = "examples/list.rs" - -[[example]] -name = "paragraph" -path = "examples/paragraph.rs" - [[example]] name = "rustbox" path = "examples/rustbox.rs" required-features = ["rustbox"] - -[[example]] -name = "sparkline" -path = "examples/sparkline.rs" - -[[example]] -name = "table" -path = "examples/table.rs" - -[[example]] -name = "tabs" -path = "examples/tabs.rs" - -[[example]] -name = "user_input" -path = "examples/user_input.rs" - -[[example]] -name = "layout" -path = "examples/layout.rs" diff --git a/examples/barchart.rs b/examples/barchart.rs index 855f7081..2740e469 100644 --- a/examples/barchart.rs +++ b/examples/barchart.rs @@ -99,7 +99,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -117,15 +117,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) @@ -161,6 +160,5 @@ fn draw(t: &mut Terminal, app: &App) { .label_style(Style::default().fg(Color::Cyan).modifier(Modifier::Italic)) .render(&mut f, chunks[1]); } - } - t.draw().unwrap(); + }) } diff --git a/examples/block.rs b/examples/block.rs index c3ad44fc..8f459f36 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -18,14 +18,14 @@ fn main() { terminal.hide_cursor().unwrap(); let mut term_size = terminal.size().unwrap(); - draw(&mut terminal, term_size); + draw(&mut terminal, term_size).unwrap(); for c in stdin.keys() { let size = terminal.size().unwrap(); if term_size != size { terminal.resize(size).unwrap(); term_size = size; } - draw(&mut terminal, term_size); + draw(&mut terminal, term_size).unwrap(); let evt = c.unwrap(); if evt == event::Key::Char('q') { break; @@ -34,9 +34,8 @@ fn main() { terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, size: Rect) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, size: Rect) -> Result<(), io::Error> { + t.draw(|mut f| { // Wrapping block for a group // Just draw the block and the group on the same area and build the group // with at least a margin of 1 @@ -81,6 +80,5 @@ fn draw(t: &mut Terminal, size: Rect) { .borders(Borders::LEFT | Borders::RIGHT) .render(&mut f, chunks[1]); } - } - t.draw().unwrap(); + }) } diff --git a/examples/canvas.rs b/examples/canvas.rs index 59fe28e3..47d4b6c1 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -107,7 +107,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -141,15 +141,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Horizontal) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) @@ -201,7 +200,5 @@ fn draw(t: &mut Terminal, app: &App) { .x_bounds([10.0, 110.0]) .y_bounds([10.0, 110.0]) .render(&mut f, chunks[1]); - } - - t.draw().unwrap(); + }) } diff --git a/examples/chart.rs b/examples/chart.rs index c879a84e..89439109 100644 --- a/examples/chart.rs +++ b/examples/chart.rs @@ -97,7 +97,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -115,15 +115,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { Chart::default() .block( Block::default() @@ -164,6 +163,5 @@ fn draw(t: &mut Terminal, app: &App) { .data(&app.data2), ]) .render(&mut f, app.size); - } - t.draw().unwrap(); + }) } diff --git a/examples/custom_widget.rs b/examples/custom_widget.rs index cee9711a..54b13575 100644 --- a/examples/custom_widget.rs +++ b/examples/custom_widget.rs @@ -34,8 +34,9 @@ fn main() { let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap(); let size = terminal.size().unwrap(); terminal.clear().unwrap(); - Label::default() - .text("Test") - .render(&mut terminal.get_frame(), size); - terminal.draw().unwrap(); + terminal + .draw(|mut f| { + Label::default().text("Test").render(&mut f, size); + }) + .unwrap(); } diff --git a/examples/demo.rs b/examples/demo.rs index e18bf511..77616080 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -194,7 +194,7 @@ fn main() { let tx = tx.clone(); loop { tx.send(Event::Tick).unwrap(); - thread::sleep(time::Duration::from_millis(16)); + thread::sleep(time::Duration::from_millis(250)); } }); @@ -268,8 +268,7 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { - { - let mut f = t.get_frame(); + t.draw(|mut f| { let chunks = Layout::default() .constraints([Constraint::Length(3), Constraint::Min(0)].as_ref()) .split(app.size); @@ -289,8 +288,7 @@ fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { } _ => {} }; - } - t.draw() + }) } fn draw_first_tab(f: &mut Frame, app: &App, area: Rect) { diff --git a/examples/gauge.rs b/examples/gauge.rs index 5bc09983..bdc160fd 100644 --- a/examples/gauge.rs +++ b/examples/gauge.rs @@ -94,7 +94,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -112,15 +112,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) @@ -155,7 +154,5 @@ fn draw(t: &mut Terminal, app: &App) { .percent(app.progress4) .label(&format!("{}/100", app.progress2)) .render(&mut f, chunks[3]); - } - - t.draw().unwrap(); + }) } diff --git a/examples/layout.rs b/examples/layout.rs index 8da5508a..40670faa 100644 --- a/examples/layout.rs +++ b/examples/layout.rs @@ -61,7 +61,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -76,15 +76,14 @@ fn main() { break; }, } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .constraints( @@ -104,7 +103,5 @@ fn draw(t: &mut Terminal, app: &App) { .title("Block 2") .borders(Borders::ALL) .render(&mut f, chunks[2]); - } - - t.draw().unwrap(); + }) } diff --git a/examples/list.rs b/examples/list.rs index d1666c2f..c8e62847 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -117,7 +117,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -149,15 +149,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Horizontal) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) @@ -182,13 +181,12 @@ fn draw(t: &mut Terminal, app: &App) { "WARNING" => &app.warning_style, _ => &app.info_style, }, - ) + ) }); List::new(events) .block(Block::default().borders(Borders::ALL).title("List")) .start_corner(Corner::BottomLeft) .render(&mut f, chunks[1]); } - } - t.draw().unwrap(); + }) } diff --git a/examples/paragraph.rs b/examples/paragraph.rs index f104e4c9..320a2662 100644 --- a/examples/paragraph.rs +++ b/examples/paragraph.rs @@ -18,7 +18,7 @@ fn main() { terminal.hide_cursor().unwrap(); let mut term_size = terminal.size().unwrap(); - draw(&mut terminal, term_size); + draw(&mut terminal, term_size).unwrap(); for c in stdin.keys() { let size = terminal.size().unwrap(); @@ -27,7 +27,7 @@ fn main() { term_size = size; } - draw(&mut terminal, term_size); + draw(&mut terminal, term_size).unwrap(); let evt = c.unwrap(); if evt == event::Key::Char('q') { break; @@ -36,9 +36,8 @@ fn main() { terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, size: Rect) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, size: Rect) -> Result<(), io::Error> { + t.draw(|mut f| { Block::default() .style(Style::default().bg(Color::White)) .render(&mut f, size); @@ -80,6 +79,5 @@ fn draw(t: &mut Terminal, size: Rect) { .alignment(Alignment::Right) .wrap(true) .render(&mut f, chunks[2]); - } - t.draw().unwrap(); + }) } diff --git a/examples/sparkline.rs b/examples/sparkline.rs index b1756740..4f2f205c 100644 --- a/examples/sparkline.rs +++ b/examples/sparkline.rs @@ -94,7 +94,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -112,15 +112,14 @@ fn main() { app.advance(); } } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) @@ -161,6 +160,5 @@ fn draw(t: &mut Terminal, app: &App) { .data(&app.data3) .style(Style::default().fg(Color::Red)) .render(&mut f, chunks[2]); - } - t.draw().unwrap(); + }) } diff --git a/examples/table.rs b/examples/table.rs index 1d17b97c..fd3de1f8 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -84,8 +84,7 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { - { - let mut frame = t.get_frame(); + t.draw(|mut f| { let selected_style = Style::default().fg(Color::Yellow).modifier(Modifier::Bold); let normal_style = Style::default().fg(Color::White); let header = ["Header1", "Header2", "Header3"]; @@ -104,7 +103,6 @@ fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { Table::new(header.into_iter(), rows) .block(Block::default().borders(Borders::ALL).title("Table")) .widths(&[10, 10, 10]) - .render(&mut frame, rects[0]); - } - t.draw() + .render(&mut f, rects[0]); + }) } diff --git a/examples/tabs.rs b/examples/tabs.rs index bf69f9b7..db3a3d2a 100644 --- a/examples/tabs.rs +++ b/examples/tabs.rs @@ -37,7 +37,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &mut app); + draw(&mut terminal, &mut app).unwrap(); // Main loop let stdin = io::stdin(); @@ -57,15 +57,14 @@ fn main() { event::Key::Left => app.tabs.previous(), _ => {} } - draw(&mut terminal, &mut app); + draw(&mut terminal, &mut app).unwrap(); } terminal.show_cursor().unwrap(); } -fn draw(t: &mut Terminal, app: &mut App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(5) @@ -109,6 +108,5 @@ fn draw(t: &mut Terminal, app: &mut App) { } _ => {} } - } - t.draw().unwrap(); + }) } diff --git a/examples/user_input.rs b/examples/user_input.rs index cbf58b6b..ba50e1fa 100644 --- a/examples/user_input.rs +++ b/examples/user_input.rs @@ -73,7 +73,7 @@ fn main() { terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); app.size = terminal.size().unwrap(); - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); loop { let size = terminal.size().unwrap(); @@ -100,16 +100,15 @@ fn main() { _ => {} }, } - draw(&mut terminal, &app); + draw(&mut terminal, &app).unwrap(); } terminal.show_cursor().unwrap(); terminal.clear().unwrap(); } -fn draw(t: &mut Terminal, app: &App) { - { - let mut f = t.get_frame(); +fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { + t.draw(|mut f| { let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) @@ -126,7 +125,5 @@ fn draw(t: &mut Terminal, app: &App) { .map(|(i, m)| Item::Data(format!("{}: {}", i, m))), ).block(Block::default().borders(Borders::ALL).title("Messages")) .render(&mut f, chunks[1]); - } - - t.draw().unwrap(); + }) } diff --git a/src/lib.rs b/src/lib.rs index f218cf6b..50c01f67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,16 +84,12 @@ //! fn draw(t: &mut Terminal) -> Result<(), io::Error> { //! //! let size = t.size()?; -//! -//! { -//! let mut f = t.get_frame(); +//! t.draw(|mut f| { //! Block::default() //! .title("Block") //! .borders(Borders::ALL) //! .render(&mut f, size); -//! } -//! -//! t.draw() +//! }) //! } //! ``` //! @@ -126,31 +122,27 @@ //! fn draw(t: &mut Terminal) -> Result<(), io::Error> { //! //! let size = t.size()?; -//! -//! { -//! let mut f = t.get_frame(); -//! let chunks = Layout::default() -//! .direction(Direction::Vertical) -//! .margin(1) -//! .constraints( -//! [ -//! Constraint::Percentage(10), -//! Constraint::Percentage(80), -//! Constraint::Percentage(10) -//! ].as_ref() -//! ) -//! .split(size); -//! Block::default() -//! .title("Block") -//! .borders(Borders::ALL) -//! .render(&mut f, chunks[0]); -//! Block::default() -//! .title("Block 2") -//! .borders(Borders::ALL) -//! .render(&mut f, chunks[2]); -//! } -//! -//! t.draw() +//! t.draw(|mut f| { +//! let chunks = Layout::default() +//! .direction(Direction::Vertical) +//! .margin(1) +//! .constraints( +//! [ +//! Constraint::Percentage(10), +//! Constraint::Percentage(80), +//! Constraint::Percentage(10) +//! ].as_ref() +//! ) +//! .split(size); +//! Block::default() +//! .title("Block") +//! .borders(Borders::ALL) +//! .render(&mut f, chunks[0]); +//! Block::default() +//! .title("Block 2") +//! .borders(Borders::ALL) +//! .render(&mut f, chunks[2]); +//! }) //! } //! ``` //! diff --git a/src/terminal.rs b/src/terminal.rs index 49489f87..5984506e 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -102,7 +102,12 @@ where } /// Flushes the current internal state and prepares the interface for the next draw call - pub fn draw(&mut self) -> Result<(), io::Error> { + pub fn draw(&mut self, f: F) -> Result<(), io::Error> + where + F: FnOnce(Frame), + { + f(self.get_frame()); + // Draw to stdout self.flush()?; diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index aeed9a7b..28c67877 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -67,7 +67,7 @@ impl<'a> Default for BarChart<'a> { } impl<'a> BarChart<'a> { - pub fn data(&'a mut self, data: &'a [(&'a str, u64)]) -> &mut BarChart<'a> { + pub fn data(mut self, data: &'a [(&'a str, u64)]) -> BarChart<'a> { self.data = data; self.values = Vec::with_capacity(self.data.len()); for &(_, v) in self.data { @@ -76,32 +76,32 @@ impl<'a> BarChart<'a> { self } - pub fn block(&'a mut self, block: Block<'a>) -> &mut BarChart<'a> { + pub fn block(mut self, block: Block<'a>) -> BarChart<'a> { self.block = Some(block); self } - pub fn max(&'a mut self, max: u64) -> &mut BarChart<'a> { + pub fn max(mut self, max: u64) -> BarChart<'a> { self.max = Some(max); self } - pub fn bar_width(&'a mut self, width: u16) -> &mut BarChart<'a> { + pub fn bar_width(mut self, width: u16) -> BarChart<'a> { self.bar_width = width; self } - pub fn bar_gap(&'a mut self, gap: u16) -> &mut BarChart<'a> { + pub fn bar_gap(mut self, gap: u16) -> BarChart<'a> { self.bar_gap = gap; self } - pub fn value_style(&'a mut self, style: Style) -> &mut BarChart<'a> { + pub fn value_style(mut self, style: Style) -> BarChart<'a> { self.value_style = style; self } - pub fn label_style(&'a mut self, style: Style) -> &mut BarChart<'a> { + pub fn label_style(mut self, style: Style) -> BarChart<'a> { self.label_style = style; self } - pub fn style(&'a mut self, style: Style) -> &mut BarChart<'a> { + pub fn style(mut self, style: Style) -> BarChart<'a> { self.style = style; self } diff --git a/src/widgets/canvas/mod.rs b/src/widgets/canvas/mod.rs index 809c89f1..082ee0d0 100644 --- a/src/widgets/canvas/mod.rs +++ b/src/widgets/canvas/mod.rs @@ -194,26 +194,26 @@ impl<'a, F> Canvas<'a, F> where F: Fn(&mut Context), { - pub fn block(&mut self, block: Block<'a>) -> &mut Canvas<'a, F> { + pub fn block(mut self, block: Block<'a>) -> Canvas<'a, F> { self.block = Some(block); self } - pub fn x_bounds(&mut self, bounds: [f64; 2]) -> &mut Canvas<'a, F> { + pub fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { self.x_bounds = bounds; self } - pub fn y_bounds(&mut self, bounds: [f64; 2]) -> &mut Canvas<'a, F> { + pub fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { self.y_bounds = bounds; self } /// Store the closure that will be used to draw to the Canvas - pub fn paint(&mut self, f: F) -> &mut Canvas<'a, F> { + pub fn paint(mut self, f: F) -> Canvas<'a, F> { self.painter = Some(f); self } - pub fn background_color(&'a mut self, color: Color) -> &mut Canvas<'a, F> { + pub fn background_color(mut self, color: Color) -> Canvas<'a, F> { self.background_color = color; self } diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index 5248636a..b1ae09de 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -195,6 +195,7 @@ impl Default for ChartLayout { /// .style(Style::default().fg(Color::Magenta)) /// .data(&[(4.0, 5.0), (5.0, 8.0), (7.66, 13.5)])]); /// # } +/// ``` pub struct Chart<'a, LX, LY> where LX: AsRef + 'a, @@ -233,27 +234,27 @@ where LX: AsRef, LY: AsRef, { - pub fn block(&'a mut self, block: Block<'a>) -> &mut Chart<'a, LX, LY> { + pub fn block(mut self, block: Block<'a>) -> Chart<'a, LX, LY> { self.block = Some(block); self } - pub fn style(&mut self, style: Style) -> &mut Chart<'a, LX, LY> { + pub fn style(mut self, style: Style) -> Chart<'a, LX, LY> { self.style = style; self } - pub fn x_axis(&mut self, axis: Axis<'a, LX>) -> &mut Chart<'a, LX, LY> { + pub fn x_axis(mut self, axis: Axis<'a, LX>) -> Chart<'a, LX, LY> { self.x_axis = axis; self } - pub fn y_axis(&mut self, axis: Axis<'a, LY>) -> &mut Chart<'a, LX, LY> { + pub fn y_axis(mut self, axis: Axis<'a, LY>) -> Chart<'a, LX, LY> { self.y_axis = axis; self } - pub fn datasets(&mut self, datasets: &'a [Dataset<'a>]) -> &mut Chart<'a, LX, LY> { + pub fn datasets(mut self, datasets: &'a [Dataset<'a>]) -> Chart<'a, LX, LY> { self.datasets = datasets; self } diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index 75c859ad..503e7153 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -39,22 +39,22 @@ impl<'a> Default for Gauge<'a> { } impl<'a> Gauge<'a> { - pub fn block(&mut self, block: Block<'a>) -> &mut Gauge<'a> { + pub fn block(mut self, block: Block<'a>) -> Gauge<'a> { self.block = Some(block); self } - pub fn percent(&mut self, percent: u16) -> &mut Gauge<'a> { + pub fn percent(mut self, percent: u16) -> Gauge<'a> { self.percent = percent; self } - pub fn label(&mut self, string: &'a str) -> &mut Gauge<'a> { + pub fn label(mut self, string: &'a str) -> Gauge<'a> { self.label = Some(string); self } - pub fn style(&mut self, style: Style) -> &mut Gauge<'a> { + pub fn style(mut self, style: Style) -> Gauge<'a> { self.style = style; self } diff --git a/src/widgets/list.rs b/src/widgets/list.rs index 1df717cd..d8dbf49a 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -51,12 +51,12 @@ where } } - pub fn block(&'b mut self, block: Block<'b>) -> &mut List<'b, 'i, L, D> { + pub fn block(mut self, block: Block<'b>) -> List<'b, 'i, L, D> { self.block = Some(block); self } - pub fn items(&'b mut self, items: I) -> &mut List<'b, 'i, L, D> + pub fn items(mut self, items: I) -> List<'b, 'i, L, D> where I: IntoIterator, IntoIter = L>, { @@ -64,12 +64,12 @@ where self } - pub fn style(&'b mut self, style: Style) -> &mut List<'b, 'i, L, D> { + pub fn style(mut self, style: Style) -> List<'b, 'i, L, D> { self.style = style; self } - pub fn start_corner(&'b mut self, corner: Corner) -> &mut List<'b, 'i, L, D> { + pub fn start_corner(mut self, corner: Corner) -> List<'b, 'i, L, D> { self.start_corner = corner; self } @@ -171,12 +171,12 @@ impl<'b> Default for SelectableList<'b> { } impl<'b> SelectableList<'b> { - pub fn block(&'b mut self, block: Block<'b>) -> &mut SelectableList<'b> { + pub fn block(mut self, block: Block<'b>) -> SelectableList<'b> { self.block = Some(block); self } - pub fn items(&'b mut self, items: &'b [I]) -> &mut SelectableList<'b> + pub fn items(mut self, items: &'b [I]) -> SelectableList<'b> where I: AsRef + 'b, { @@ -184,22 +184,22 @@ impl<'b> SelectableList<'b> { self } - pub fn style(&'b mut self, style: Style) -> &mut SelectableList<'b> { + pub fn style(mut self, style: Style) -> SelectableList<'b> { self.style = style; self } - pub fn highlight_symbol(&'b mut self, highlight_symbol: &'b str) -> &mut SelectableList<'b> { + pub fn highlight_symbol(mut self, highlight_symbol: &'b str) -> SelectableList<'b> { self.highlight_symbol = Some(highlight_symbol); self } - pub fn highlight_style(&'b mut self, highlight_style: Style) -> &mut SelectableList<'b> { + pub fn highlight_style(mut self, highlight_style: Style) -> SelectableList<'b> { self.highlight_style = highlight_style; self } - pub fn select(&'b mut self, index: usize) -> &'b mut SelectableList<'b> { + pub fn select(mut self, index: usize) -> SelectableList<'b> { self.selected = Some(index); self } diff --git a/src/widgets/paragraph.rs b/src/widgets/paragraph.rs index f3153b51..2d8aff07 100644 --- a/src/widgets/paragraph.rs +++ b/src/widgets/paragraph.rs @@ -70,32 +70,32 @@ where } } - pub fn block(&'a mut self, block: Block<'a>) -> &mut Paragraph<'a, 't, T> { + pub fn block(mut self, block: Block<'a>) -> Paragraph<'a, 't, T> { self.block = Some(block); self } - pub fn style(&mut self, style: Style) -> &mut Paragraph<'a, 't, T> { + pub fn style(mut self, style: Style) -> Paragraph<'a, 't, T> { self.style = style; self } - pub fn wrap(&mut self, flag: bool) -> &mut Paragraph<'a, 't, T> { + pub fn wrap(mut self, flag: bool) -> Paragraph<'a, 't, T> { self.wrapping = flag; self } - pub fn raw(&mut self, flag: bool) -> &mut Paragraph<'a, 't, T> { + pub fn raw(mut self, flag: bool) -> Paragraph<'a, 't, T> { self.raw = flag; self } - pub fn scroll(&mut self, offset: u16) -> &mut Paragraph<'a, 't, T> { + pub fn scroll(mut self, offset: u16) -> Paragraph<'a, 't, T> { self.scroll = offset; self } - pub fn alignment(&mut self, alignment: Alignment) -> &mut Paragraph<'a, 't, T> { + pub fn alignment(mut self, alignment: Alignment) -> Paragraph<'a, 't, T> { self.alignment = alignment; self } diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index 22158257..1a0b9325 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -46,22 +46,22 @@ impl<'a> Default for Sparkline<'a> { } impl<'a> Sparkline<'a> { - pub fn block(&mut self, block: Block<'a>) -> &mut Sparkline<'a> { + pub fn block(mut self, block: Block<'a>) -> Sparkline<'a> { self.block = Some(block); self } - pub fn style(&mut self, style: Style) -> &mut Sparkline<'a> { + pub fn style(mut self, style: Style) -> Sparkline<'a> { self.style = style; self } - pub fn data(&mut self, data: &'a [u64]) -> &mut Sparkline<'a> { + pub fn data(mut self, data: &'a [u64]) -> Sparkline<'a> { self.data = data; self } - pub fn max(&mut self, max: u64) -> &mut Sparkline<'a> { + pub fn max(mut self, max: u64) -> Sparkline<'a> { self.max = Some(max); self } diff --git a/src/widgets/table.rs b/src/widgets/table.rs index 8438e1cc..af4e0a5a 100644 --- a/src/widgets/table.rs +++ b/src/widgets/table.rs @@ -106,12 +106,12 @@ where column_spacing: 1, } } - pub fn block(&'a mut self, block: Block<'a>) -> &mut Table<'a, 'i, T, H, I, D, R> { + pub fn block(mut self, block: Block<'a>) -> Table<'a, 'i, T, H, I, D, R> { self.block = Some(block); self } - pub fn header(&mut self, header: II) -> &mut Table<'a, 'i, T, H, I, D, R> + pub fn header(mut self, header: II) -> Table<'a, 'i, T, H, I, D, R> where II: IntoIterator, { @@ -119,17 +119,17 @@ where self } - pub fn header_style(&mut self, style: Style) -> &mut Table<'a, 'i, T, H, I, D, R> { + pub fn header_style(mut self, style: Style) -> Table<'a, 'i, T, H, I, D, R> { self.header_style = style; self } - pub fn widths(&mut self, widths: &'a [u16]) -> &mut Table<'a, 'i, T, H, I, D, R> { + pub fn widths(mut self, widths: &'a [u16]) -> Table<'a, 'i, T, H, I, D, R> { self.widths = widths; self } - pub fn rows(&mut self, rows: II) -> &mut Table<'a, 'i, T, H, I, D, R> + pub fn rows(mut self, rows: II) -> Table<'a, 'i, T, H, I, D, R> where II: IntoIterator, IntoIter = R>, { @@ -137,12 +137,12 @@ where self } - pub fn style(&mut self, style: Style) -> &mut Table<'a, 'i, T, H, I, D, R> { + pub fn style(mut self, style: Style) -> Table<'a, 'i, T, H, I, D, R> { self.style = style; self } - pub fn column_spacing(&mut self, spacing: u16) -> &mut Table<'a, 'i, T, H, I, D, R> { + pub fn column_spacing(mut self, spacing: u16) -> Table<'a, 'i, T, H, I, D, R> { self.column_spacing = spacing; self } diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index f95ecabd..4c1b086c 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -57,27 +57,27 @@ impl<'a, T> Tabs<'a, T> where T: AsRef, { - pub fn block(&mut self, block: Block<'a>) -> &mut Tabs<'a, T> { + pub fn block(mut self, block: Block<'a>) -> Tabs<'a, T> { self.block = Some(block); self } - pub fn titles(&mut self, titles: &'a [T]) -> &mut Tabs<'a, T> { + pub fn titles(mut self, titles: &'a [T]) -> Tabs<'a, T> { self.titles = titles; self } - pub fn select(&mut self, selected: usize) -> &mut Tabs<'a, T> { + pub fn select(mut self, selected: usize) -> Tabs<'a, T> { self.selected = selected; self } - pub fn style(&mut self, style: Style) -> &mut Tabs<'a, T> { + pub fn style(mut self, style: Style) -> Tabs<'a, T> { self.style = style; self } - pub fn highlight_style(&mut self, style: Style) -> &mut Tabs<'a, T> { + pub fn highlight_style(mut self, style: Style) -> Tabs<'a, T> { self.highlight_style = style; self }