mirror of
https://github.com/ratatui/ratatui.git
synced 2025-10-02 07:21:24 +00:00
feat(examples): use generic backend in draw functions
This commit is contained in:
parent
32947669d5
commit
f6d2f8f929
@ -11,9 +11,9 @@ use std::io;
|
|||||||
|
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
use termion::input::MouseTerminal;
|
use termion::input::MouseTerminal;
|
||||||
use termion::raw::{IntoRawMode, RawTerminal};
|
use termion::raw::{IntoRawMode};
|
||||||
use termion::screen::AlternateScreen;
|
use termion::screen::AlternateScreen;
|
||||||
use tui::backend::TermionBackend;
|
use tui::backend::{Backend, TermionBackend};
|
||||||
use tui::layout::{Constraint, Direction, Layout, Rect};
|
use tui::layout::{Constraint, Direction, Layout, Rect};
|
||||||
use tui::style::{Color, Modifier, Style};
|
use tui::style::{Color, Modifier, Style};
|
||||||
use tui::widgets::canvas::{Canvas, Line, Map, MapResolution};
|
use tui::widgets::canvas::{Canvas, Line, Map, MapResolution};
|
||||||
@ -26,8 +26,6 @@ use tui::{Frame, Terminal};
|
|||||||
use util::event::{Event, Events};
|
use util::event::{Event, Events};
|
||||||
use util::{RandomSignal, SinSignal, TabsState};
|
use util::{RandomSignal, SinSignal, TabsState};
|
||||||
|
|
||||||
type Backend = TermionBackend<AlternateScreen<MouseTerminal<RawTerminal<io::Stdout>>>>;
|
|
||||||
|
|
||||||
struct Server<'a> {
|
struct Server<'a> {
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
location: &'a str,
|
location: &'a str,
|
||||||
@ -252,7 +250,10 @@ fn main() -> Result<(), failure::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_first_tab(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
fn draw_first_tab<B>(f: &mut Frame<B>, app: &App, area: Rect)
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
@ -267,7 +268,10 @@ fn draw_first_tab(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
|||||||
draw_text(f, chunks[2]);
|
draw_text(f, chunks[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_gauges(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
fn draw_gauges<B>(f: &mut Frame<B>, app: &App, area: Rect)
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.constraints([Constraint::Length(2), Constraint::Length(3)].as_ref())
|
.constraints([Constraint::Length(2), Constraint::Length(3)].as_ref())
|
||||||
.margin(1)
|
.margin(1)
|
||||||
@ -293,7 +297,10 @@ fn draw_gauges(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
|||||||
.render(f, chunks[1]);
|
.render(f, chunks[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_charts(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
fn draw_charts<B>(f: &mut Frame<B>, app: &App, area: Rect)
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
let constraints = if app.show_chart {
|
let constraints = if app.show_chart {
|
||||||
vec![Constraint::Percentage(50), Constraint::Percentage(50)]
|
vec![Constraint::Percentage(50), Constraint::Percentage(50)]
|
||||||
} else {
|
} else {
|
||||||
@ -392,7 +399,10 @@ fn draw_charts(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_text(f: &mut Frame<Backend>, area: Rect) {
|
fn draw_text<B>(f: &mut Frame<B>, area: Rect)
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
let text = [
|
let text = [
|
||||||
Text::raw("This is a paragraph with several lines. You can change style your text the way you want.\n\nFox example: "),
|
Text::raw("This is a paragraph with several lines. You can change style your text the way you want.\n\nFox example: "),
|
||||||
Text::styled("under", Style::default().fg(Color::Red)),
|
Text::styled("under", Style::default().fg(Color::Red)),
|
||||||
@ -420,7 +430,10 @@ fn draw_text(f: &mut Frame<Backend>, area: Rect) {
|
|||||||
.render(f, area);
|
.render(f, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_second_tab(f: &mut Frame<Backend>, app: &App, area: Rect) {
|
fn draw_second_tab<B>(f: &mut Frame<B>, app: &App, area: Rect)
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)].as_ref())
|
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)].as_ref())
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user