diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/core.rs | 7 | ||||
| -rw-r--r-- | src/client/ui.rs | 27 |
2 files changed, 30 insertions, 4 deletions
diff --git a/src/client/core.rs b/src/client/core.rs index 0e54fba..a910a68 100644 --- a/src/client/core.rs +++ b/src/client/core.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | use crate::client::games::manager::GameManager; | 1 | use crate::client::games::manager::GameManager; |
| 2 | use crate::client::games::response::parse_spin_response; | 2 | use crate::client::games::response::parse_spin_response; |
| 3 | use crate::client::ui::{ | 3 | use crate::client::ui::{ |
| 4 | command_names, help_lines, input_cursor_column, parse_bet_arg, record_history, | 4 | command_names, completion_lines, help_lines, input_cursor_column, parse_bet_arg, |
| 5 | record_history, | ||
| 5 | }; | 6 | }; |
| 6 | 7 | ||
| 7 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 8 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -439,9 +440,7 @@ impl ClientCore { | |||
| 439 | if matches.len() == 1 { | 440 | if matches.len() == 1 { |
| 440 | self.input = matches[0].to_string(); | 441 | self.input = matches[0].to_string(); |
| 441 | } else if matches.len() > 1 { | 442 | } else if matches.len() > 1 { |
| 442 | let mut lines = vec!["Possible completions:".to_string()]; | 443 | effects.push(Effect::Print(completion_lines(&matches, 76))); |
| 443 | lines.push(matches.join(" ")); | ||
| 444 | effects.push(Effect::Print(lines)); | ||
| 445 | } | 444 | } |
| 446 | if let Some(prompt) = self.prompt_effect() { | 445 | if let Some(prompt) = self.prompt_effect() { |
| 447 | effects.push(prompt); | 446 | effects.push(prompt); |
diff --git a/src/client/ui.rs b/src/client/ui.rs index 036c36a..6fc2f62 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs | |||
| @@ -102,6 +102,33 @@ pub fn help_lines() -> Vec<String> { | |||
| 102 | lines | 102 | lines |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | /// Wrap a completion list to `width` columns, one space between names. | ||
| 106 | pub fn completion_lines(commands: &[&str], width: usize) -> Vec<String> { | ||
| 107 | let mut lines = vec!["Possible completions:".to_string()]; | ||
| 108 | let mut current = String::new(); | ||
| 109 | |||
| 110 | for command in commands { | ||
| 111 | let needed = if current.is_empty() { | ||
| 112 | command.len() | ||
| 113 | } else { | ||
| 114 | current.len() + 1 + command.len() | ||
| 115 | }; | ||
| 116 | if !current.is_empty() && needed > width { | ||
| 117 | lines.push(current.clone()); | ||
| 118 | current.clear(); | ||
| 119 | } | ||
| 120 | if !current.is_empty() { | ||
| 121 | current.push(' '); | ||
| 122 | } | ||
| 123 | current.push_str(command); | ||
| 124 | } | ||
| 125 | |||
| 126 | if !current.is_empty() { | ||
| 127 | lines.push(current); | ||
| 128 | } | ||
| 129 | lines | ||
| 130 | } | ||
| 131 | |||
| 105 | /// Add a command to the history, skipping blanks and consecutive duplicates. | 132 | /// Add a command to the history, skipping blanks and consecutive duplicates. |
| 106 | pub fn record_history(history: &mut Vec<String>, line: &str) { | 133 | pub fn record_history(history: &mut Vec<String>, line: &str) { |
| 107 | let line = line.trim(); | 134 | let line = line.trim(); |
