pub struct CoolInput<H: CustomInputHandler> {
pub text_data: TextInputData,
pub scroll_x: usize,
pub scroll_y: usize,
pub listening: bool,
pub custom_input: H,
}
Expand description
The main input type. Uses a custom input handler (a struct which implements CustomInputHandler)
Fields§
§text_data: TextInputData
§scroll_x: usize
§scroll_y: usize
§listening: bool
§custom_input: H
Implementations§
Source§impl<H: CustomInputHandler> CoolInput<H>
impl<H: CustomInputHandler> CoolInput<H>
Sourcepub fn new(handler: H, tab_width: usize) -> Self
pub fn new(handler: H, tab_width: usize) -> Self
Examples found in repository?
More examples
examples/fileeditor.rs (lines 111-114)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
fn main() -> Result<(), std::io::Error> {
let args: Vec<_> = env::args().collect();
if args.len() != 2 {
println!("please specify a filename!");
return Ok(());
}
let filename = &args[1];
let mut text = String::new();
let mut is_new = true;
if path_exists(filename) {
text = fs::read_to_string(filename).expect("Unable to read file contents.");
is_new = false;
}
let mut cool_input = CoolInput::new(
FileEditorInput::open_filename(filename.to_string(), text.to_owned(), is_new),
0,
);
cool_input.text_data.text = text;
cool_input.listen()?;
Ok(())
}
Sourcepub fn get_terminal_size(&mut self) -> Result<(u16, u16), Error>
pub fn get_terminal_size(&mut self) -> Result<(u16, u16), Error>
Get the size of the terminal running the program
pub fn get_input_transform(&mut self) -> Result<InputTransform, Error>
Sourcepub fn listen_quiet(&mut self) -> Result<(), Error>
pub fn listen_quiet(&mut self) -> Result<(), Error>
Start listening for key presses without preparing the terminal
Sourcepub fn pre_listen(&mut self) -> Result<(), Error>
pub fn pre_listen(&mut self) -> Result<(), Error>
Prepare the terminal for input
Sourcepub fn post_listen(&mut self) -> Result<(), Error>
pub fn post_listen(&mut self) -> Result<(), Error>
Restore the terminal after input is finished.
Sourcepub fn listen(&mut self) -> Result<(), Error>
pub fn listen(&mut self) -> Result<(), Error>
Prepare terminal and start to listen for key presses until finished.
Examples found in repository?
More examples
examples/fileeditor.rs (line 116)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
fn main() -> Result<(), std::io::Error> {
let args: Vec<_> = env::args().collect();
if args.len() != 2 {
println!("please specify a filename!");
return Ok(());
}
let filename = &args[1];
let mut text = String::new();
let mut is_new = true;
if path_exists(filename) {
text = fs::read_to_string(filename).expect("Unable to read file contents.");
is_new = false;
}
let mut cool_input = CoolInput::new(
FileEditorInput::open_filename(filename.to_string(), text.to_owned(), is_new),
0,
);
cool_input.text_data.text = text;
cool_input.listen()?;
Ok(())
}
Auto Trait Implementations§
impl<H> Freeze for CoolInput<H>where
H: Freeze,
impl<H> RefUnwindSafe for CoolInput<H>where
H: RefUnwindSafe,
impl<H> Send for CoolInput<H>where
H: Send,
impl<H> Sync for CoolInput<H>where
H: Sync,
impl<H> Unpin for CoolInput<H>where
H: Unpin,
impl<H> UnwindSafe for CoolInput<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more