Last active
October 19, 2022 03:40
-
-
Save leiless/ff6887134f9a5950ae27083b5cbf151f to your computer and use it in GitHub Desktop.
tui-rs examples/user_input.rs inline viewport version (git diff)
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
diff --git a/examples/user_input.rs b/examples/user_input.rs | |
index 330d502..22d2739 100644 | |
--- a/examples/user_input.rs | |
+++ b/examples/user_input.rs | |
@@ -12,7 +12,7 @@ | |
use crossterm::{ | |
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode}, | |
execute, | |
- terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, | |
+ terminal::{disable_raw_mode, enable_raw_mode}, | |
}; | |
use std::{error::Error, io}; | |
use tui::{ | |
@@ -21,7 +21,7 @@ use tui::{ | |
style::{Color, Modifier, Style}, | |
text::{Span, Spans, Text}, | |
widgets::{Block, Borders, List, ListItem, Paragraph}, | |
- Frame, Terminal, | |
+ Frame, Terminal, TerminalOptions, ViewportVariant, | |
}; | |
use unicode_width::UnicodeWidthStr; | |
@@ -54,9 +54,14 @@ fn main() -> Result<(), Box<dyn Error>> { | |
// setup terminal | |
enable_raw_mode()?; | |
let mut stdout = io::stdout(); | |
- execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; | |
+ execute!(stdout, EnableMouseCapture)?; | |
let backend = CrosstermBackend::new(stdout); | |
- let mut terminal = Terminal::new(backend)?; | |
+ let mut terminal = Terminal::with_options( | |
+ backend, | |
+ TerminalOptions { | |
+ viewport: ViewportVariant::Inline(10), | |
+ }, | |
+ )?; | |
// create app and run it | |
let app = App::default(); | |
@@ -64,9 +69,9 @@ fn main() -> Result<(), Box<dyn Error>> { | |
// restore terminal | |
disable_raw_mode()?; | |
+ terminal.clear()?; | |
execute!( | |
terminal.backend_mut(), | |
- LeaveAlternateScreen, | |
DisableMouseCapture | |
)?; | |
terminal.show_cursor()?; | |
@@ -116,7 +121,6 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<( | |
fn ui<B: Backend>(f: &mut Frame<B>, app: &App) { | |
let chunks = Layout::default() | |
.direction(Direction::Vertical) | |
- .margin(2) | |
.constraints( | |
[ | |
Constraint::Length(1), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tui-rs/examples/user_input.rs
Full code (inline viewport version)