summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-28 22:31:18 +0100
committersalmonik <salmonik@tuta.io>2026-10-28 22:31:18 +0100
commit828470137cb4e806c31a26fa741d5d67c64f98c2 (patch)
tree45dbe92af0f61166559d73c21fabd7759eca4b11 /src/client
parentv0.2.3: add ClientCore and fix the game board rendering (diff)
downloadzagan-bet-828470137cb4e806c31a26fa741d5d67c64f98c2.tar.gz
zagan-bet-828470137cb4e806c31a26fa741d5d67c64f98c2.zip
v0.2.4: fix command UX, completion wrapping and auth prompt cancellation
Diffstat (limited to '')
-rw-r--r--src/client/core.rs7
-rw-r--r--src/client/ui.rs27
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 @@
1use crate::client::games::manager::GameManager; 1use crate::client::games::manager::GameManager;
2use crate::client::games::response::parse_spin_response; 2use crate::client::games::response::parse_spin_response;
3use crate::client::ui::{ 3use 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.
106pub 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.
106pub fn record_history(history: &mut Vec<String>, line: &str) { 133pub fn record_history(history: &mut Vec<String>, line: &str) {
107 let line = line.trim(); 134 let line = line.trim();