From fbb24ddd172d9a4445bdf235e6e23d7f4c9473bf Mon Sep 17 00:00:00 2001 From: Sofia Date: Wed, 15 Jul 2026 20:03:26 +0300 Subject: [PATCH] Add handle_command --- godot/scenes/main.tscn | 1 - rust/src/ui/cli.rs | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/godot/scenes/main.tscn b/godot/scenes/main.tscn index 503ce46..14bf1cf 100644 --- a/godot/scenes/main.tscn +++ b/godot/scenes/main.tscn @@ -29,7 +29,6 @@ anchor_right = 1.0 offset_top = 307.0 offset_bottom = 342.0 grow_horizontal = 2 -text = "Hello there!" [node name="ScrollContainer" type="ScrollContainer" parent="CommandLinePanel" unique_id=910897176] custom_minimum_size = Vector2(-1, 0) diff --git a/rust/src/ui/cli.rs b/rust/src/ui/cli.rs index a5b2391..595b283 100644 --- a/rust/src/ui/cli.rs +++ b/rust/src/ui/cli.rs @@ -9,12 +9,14 @@ use godot::{ pub enum CliColor { Command, + Regular, } impl CliColor { pub fn as_str(&self) -> &str { match self { CliColor::Command => "#a2a2a2", + CliColor::Regular => "#fff", } } } @@ -59,15 +61,22 @@ impl IPanel for CommandLinePanel { if text.contains("\n") { let parts = text.split("\n"); let first = parts.get(0).unwrap(); - self.publish_message(format!("> {}", first.to_string()), CliColor::Command); - self.input_field.as_mut().unwrap().clear(); - self.scroll_next_update = true; + self.handle_command(first.to_string()); } } } } impl CommandLinePanel { + pub fn handle_command(&mut self, command: String) { + self.publish_message(format!("> {}", command), CliColor::Command); + if let Some(input) = &mut self.input_field { + input.clear(); + } + self.publish_message("Command registered!".to_owned(), CliColor::Regular); + self.scroll_next_update = true; + } + pub fn publish_message(&mut self, message: String, color: CliColor) { if let Some(field) = &mut self.text_field { if !field.get_parsed_text().is_empty() {