Struct term_basics_linux::InputHistory [−][src]
pub struct InputHistory { /* fields omitted */ }
Expand description
A struct that holds information about a history of typed input’s but the user.
Implementations
Make a new InputHistory with a certain maximum capacity.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputHistory::new(10);
let x = tbl::input_field_scrollable(&mut his);
Adds an element to the history. It will delete items if it’s length would grow past the max length. the oldest items will be removed.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputHistory::new(2);
his.add(&"0".to_string());
his.add(&"1".to_string());
his.add(&"2".to_string());
//only "1" and "2" will remain, as 0 is removed.
let _ = tbl::input_field_scrollable(&mut his);
Returns the an Option of String, the element at the given index. The index wraps and you can query for negative indices as well as indices above the maximum length.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputHistory::new(3);
his.add(&"0".to_string());
his.add(&"1".to_string());
his.add(&"2".to_string());
println!("at -2: {:?}", his.get_index(-2)); // "1"
println!("at -1: {:?}", his.get_index(-1)); // "2"
println!("at 0: {:?}", his.get_index(0)); // "0"
println!("at 1: {:?}", his.get_index(1)); // "1"
println!("at 2: {:?}", his.get_index(2)); // "2"
println!("at 3: {:?}", his.get_index(3)); // "0"
println!("at 4: {:?}", his.get_index(4)); // "1"