-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from pm100/ghost
placeholder feature
- Loading branch information
Showing
6 changed files
with
175 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crossterm::event::{DisableMouseCapture, EnableMouseCapture}; | ||
use crossterm::terminal::{ | ||
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, | ||
}; | ||
use std::io; | ||
use tui::backend::CrosstermBackend; | ||
use tui::layout::Rect; | ||
use tui::style::{Color, Style}; | ||
use tui::widgets::{Block, Borders}; | ||
use tui::Terminal; | ||
use tui_textarea::{Input, Key, TextArea}; | ||
|
||
fn main() -> io::Result<()> { | ||
let stdout = io::stdout(); | ||
let mut stdout = stdout.lock(); | ||
|
||
enable_raw_mode()?; | ||
crossterm::execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; | ||
let backend = CrosstermBackend::new(stdout); | ||
let mut term = Terminal::new(backend)?; | ||
|
||
let mut textarea = TextArea::default(); | ||
textarea.set_block( | ||
Block::default() | ||
.borders(Borders::ALL) | ||
.border_style(Style::default().fg(Color::LightBlue)) | ||
.title("Crossterm Popup Example"), | ||
); | ||
|
||
let area = Rect { | ||
width: 40, | ||
height: 5, | ||
x: 5, | ||
y: 5, | ||
}; | ||
textarea.set_style(Style::default().fg(Color::Yellow)); | ||
|
||
// set placeholder | ||
|
||
textarea.set_placeholder_style(Style::default()); | ||
textarea.set_placeholder("prompt message".to_string()); | ||
loop { | ||
term.draw(|f| { | ||
f.render_widget(textarea.widget(), area); | ||
})?; | ||
match crossterm::event::read()?.into() { | ||
Input { key: Key::Esc, .. } => break, | ||
input => { | ||
textarea.input(input); | ||
} | ||
} | ||
} | ||
|
||
disable_raw_mode()?; | ||
crossterm::execute!( | ||
term.backend_mut(), | ||
LeaveAlternateScreen, | ||
DisableMouseCapture | ||
)?; | ||
term.show_cursor()?; | ||
|
||
println!("Lines: {:?}", textarea.lines()); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crossterm::event::{DisableMouseCapture, EnableMouseCapture}; | ||
use crossterm::terminal::{ | ||
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, | ||
}; | ||
use crossterm_026 as crossterm; | ||
use ratatui::backend::CrosstermBackend; | ||
use ratatui::layout::Rect; | ||
use ratatui::style::{Color, Style}; | ||
use ratatui::widgets::{Block, Borders}; | ||
use ratatui::Terminal; | ||
use std::io; | ||
use tui_textarea::{Input, Key, TextArea}; | ||
|
||
fn main() -> io::Result<()> { | ||
let stdout = io::stdout(); | ||
let mut stdout = stdout.lock(); | ||
|
||
enable_raw_mode()?; | ||
crossterm::execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; | ||
let backend = CrosstermBackend::new(stdout); | ||
let mut term = Terminal::new(backend)?; | ||
|
||
let mut textarea = TextArea::default(); | ||
textarea.set_block( | ||
Block::default() | ||
.borders(Borders::ALL) | ||
.border_style(Style::default().fg(Color::LightBlue)) | ||
.title("Crossterm Popup Example"), | ||
); | ||
|
||
let area = Rect { | ||
width: 40, | ||
height: 5, | ||
x: 5, | ||
y: 5, | ||
}; | ||
textarea.set_style(Style::default().fg(Color::Yellow)); | ||
textarea.set_placeholder_style(Style::default()); | ||
textarea.set_placeholder("prompt message".to_string()); | ||
loop { | ||
term.draw(|f| { | ||
f.render_widget(textarea.widget(), area); | ||
})?; | ||
match crossterm::event::read()?.into() { | ||
Input { key: Key::Esc, .. } => break, | ||
input => { | ||
textarea.input(input); | ||
} | ||
} | ||
} | ||
|
||
disable_raw_mode()?; | ||
crossterm::execute!( | ||
term.backend_mut(), | ||
LeaveAlternateScreen, | ||
DisableMouseCapture | ||
)?; | ||
term.show_cursor()?; | ||
|
||
println!("Lines: {:?}", textarea.lines()); | ||
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