diff options
Diffstat (limited to 'src/client/ui.rs')
| -rw-r--r-- | src/client/ui.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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(); |
