aboutsummaryrefslogtreecommitdiff
path: root/vendor/dialoguer/examples/history.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/dialoguer/examples/history.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/dialoguer/examples/history.rs')
-rw-r--r--vendor/dialoguer/examples/history.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/vendor/dialoguer/examples/history.rs b/vendor/dialoguer/examples/history.rs
deleted file mode 100644
index 0d69b27..0000000
--- a/vendor/dialoguer/examples/history.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-use dialoguer::{theme::ColorfulTheme, History, Input};
-use std::{collections::VecDeque, process};
-
-fn main() {
- println!("Use 'exit' to quit the prompt");
- println!("In this example, history is limited to 4 entries");
- println!("Use the Up/Down arrows to scroll through history");
- println!();
-
- let mut history = MyHistory::default();
-
- loop {
- if let Ok(cmd) = Input::<String>::with_theme(&ColorfulTheme::default())
- .with_prompt("dialoguer")
- .history_with(&mut history)
- .interact_text()
- {
- if cmd == "exit" {
- process::exit(0);
- }
- println!("Entered {}", cmd);
- }
- }
-}
-
-struct MyHistory {
- max: usize,
- history: VecDeque<String>,
-}
-
-impl Default for MyHistory {
- fn default() -> Self {
- MyHistory {
- max: 4,
- history: VecDeque::new(),
- }
- }
-}
-
-impl<T: ToString> History<T> for MyHistory {
- fn read(&self, pos: usize) -> Option<String> {
- self.history.get(pos).cloned()
- }
-
- fn write(&mut self, val: &T) {
- if self.history.len() == self.max {
- self.history.pop_back();
- }
- self.history.push_front(val.to_string());
- }
-}