diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/client_core.rs | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs index 722cf0d..49abca2 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs | |||
| @@ -6,8 +6,10 @@ | |||
| 6 | 6 | ||
| 7 | use std::time::Duration; | 7 | use std::time::Duration; |
| 8 | use zagan_bet::blackjack::BlackjackState; | 8 | use zagan_bet::blackjack::BlackjackState; |
| 9 | use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand}; | 9 | use zagan_bet::client::core::{ClientCore, Effect}; |
| 10 | use zagan_bet::client::input::{game_input, Editor, GameInput, Input, Key}; | 10 | use zagan_bet::client::input::{game_input, Editor, GameInput, Input, Key}; |
| 11 | use zagan_bet::client::shell::{self, Shell}; | ||
| 12 | use zagan_bet::client::ui::help_lines; | ||
| 11 | use zagan_bet::client::games::response::{ | 13 | use zagan_bet::client::games::response::{ |
| 12 | parse_blackjack_response, parse_crash_response, parse_spin_response, | 14 | parse_blackjack_response, parse_crash_response, parse_spin_response, |
| 13 | }; | 15 | }; |
| @@ -31,12 +33,7 @@ struct Screen { | |||
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | impl Screen { | 35 | impl Screen { |
| 34 | fn apply( | 36 | fn apply(&mut self, effects: &[Effect], sent: &mut Vec<String>) { |
| 35 | &mut self, | ||
| 36 | effects: &[Effect], | ||
| 37 | sent: &mut Vec<String>, | ||
| 38 | interactive: &mut Vec<InteractiveCommand>, | ||
| 39 | ) { | ||
| 40 | for effect in effects { | 37 | for effect in effects { |
| 41 | match effect { | 38 | match effect { |
| 42 | Effect::Print(lines) => self.lines.extend(lines.iter().cloned()), | 39 | Effect::Print(lines) => self.lines.extend(lines.iter().cloned()), |
| @@ -57,19 +54,8 @@ impl Screen { | |||
| 57 | self.region_start = None; | 54 | self.region_start = None; |
| 58 | self.region_len = 0; | 55 | self.region_len = 0; |
| 59 | } | 56 | } |
| 60 | Effect::AnimateRoulette { view, .. } => { | ||
| 61 | let lines = zagan_bet::client::tui::render_view(view); | ||
| 62 | if let Some(start) = self.region_start { | ||
| 63 | self.lines.truncate(start); | ||
| 64 | } else { | ||
| 65 | self.region_start = Some(self.lines.len()); | ||
| 66 | } | ||
| 67 | self.lines.extend(lines.iter().cloned()); | ||
| 68 | self.region_len = lines.len(); | ||
| 69 | } | ||
| 70 | Effect::SendLine(line) => sent.push(line.clone()), | 57 | Effect::SendLine(line) => sent.push(line.clone()), |
| 71 | Effect::Interactive(command) => interactive.push(command.clone()), | 58 | Effect::Quit | Effect::Disconnect => {} |
| 72 | Effect::Quit | Effect::Disconnect | Effect::ListHosts | Effect::ForgetHost(_) => {} | ||
| 73 | } | 59 | } |
| 74 | } | 60 | } |
| 75 | } | 61 | } |
| @@ -87,7 +73,6 @@ struct Harness { | |||
| 87 | editor: Editor, | 73 | editor: Editor, |
| 88 | screen: Screen, | 74 | screen: Screen, |
| 89 | sent: Vec<String>, | 75 | sent: Vec<String>, |
| 90 | interactive: Vec<InteractiveCommand>, | ||
| 91 | } | 76 | } |
| 92 | 77 | ||
| 93 | impl Harness { | 78 | impl Harness { |
| @@ -100,13 +85,11 @@ impl Harness { | |||
| 100 | editor: Editor::new(), | 85 | editor: Editor::new(), |
| 101 | screen: Screen::default(), | 86 | screen: Screen::default(), |
| 102 | sent: Vec::new(), | 87 | sent: Vec::new(), |
| 103 | interactive: Vec::new(), | ||
| 104 | } | 88 | } |
| 105 | } | 89 | } |
| 106 | 90 | ||
| 107 | fn apply(&mut self, effects: Vec<Effect>) { | 91 | fn apply(&mut self, effects: Vec<Effect>) { |
| 108 | self.screen | 92 | self.screen.apply(&effects, &mut self.sent); |
| 109 | .apply(&effects, &mut self.sent, &mut self.interactive); | ||
| 110 | } | 93 | } |
| 111 | 94 | ||
| 112 | fn key(&mut self, key: Key) { | 95 | fn key(&mut self, key: Key) { |
| @@ -119,7 +102,7 @@ impl Harness { | |||
| 119 | } else { | 102 | } else { |
| 120 | match self.editor.handle(key) { | 103 | match self.editor.handle(key) { |
| 121 | Input::Quit => vec![Effect::Quit], | 104 | Input::Quit => vec![Effect::Quit], |
| 122 | Input::Submit(line) => self.core.submit_line(&line), | 105 | Input::Submit(line) => self.dispatch(&line), |
| 123 | Input::Print(lines) => vec![Effect::Print(lines)], | 106 | Input::Print(lines) => vec![Effect::Print(lines)], |
| 124 | Input::Prompt | Input::None => Vec::new(), | 107 | Input::Prompt | Input::None => Vec::new(), |
| 125 | } | 108 | } |
| @@ -128,6 +111,26 @@ impl Harness { | |||
| 128 | self.apply_prompt(); | 111 | self.apply_prompt(); |
| 129 | } | 112 | } |
| 130 | 113 | ||
| 114 | /// Route a submitted line the way the terminal adapter does. | ||
| 115 | fn dispatch(&mut self, line: &str) -> Vec<Effect> { | ||
| 116 | match shell::parse(line) { | ||
| 117 | Shell::Run(command) => self.core.command(command), | ||
| 118 | Shell::Disconnect => { | ||
| 119 | self.core.reset_after_disconnect(); | ||
| 120 | vec![ | ||
| 121 | Effect::ClearRegion, | ||
| 122 | Effect::Print(vec!["Disconnected".to_string()]), | ||
| 123 | ] | ||
| 124 | } | ||
| 125 | Shell::Help => vec![Effect::Print(help_lines())], | ||
| 126 | Shell::Quit => vec![Effect::Quit], | ||
| 127 | Shell::Empty => Vec::new(), | ||
| 128 | Shell::Usage(message) => vec![Effect::Print(vec![message])], | ||
| 129 | // Connect/login prompts are adapter flows, not core state. | ||
| 130 | _ => Vec::new(), | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 131 | fn apply_prompt(&mut self) { | 134 | fn apply_prompt(&mut self) { |
| 132 | if self.core.is_in_game() { | 135 | if self.core.is_in_game() { |
| 133 | return; | 136 | return; |
