Improve command line interface
This commit is contained in:
parent
7b66a7afb9
commit
ae37115b37
@ -41,9 +41,11 @@ offset_right = -1.0
|
|||||||
offset_bottom = 292.0
|
offset_bottom = 292.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
|
|
||||||
[node name="TextField" type="Label" parent="CommandLinePanel/ScrollContainer" unique_id=2111638471]
|
[node name="TextField" type="RichTextLabel" parent="CommandLinePanel/ScrollContainer" unique_id=676603670]
|
||||||
custom_minimum_size = Vector2(1150, 0)
|
custom_minimum_size = Vector2(-1, -1)
|
||||||
custom_maximum_size = Vector2(1150, -1)
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
vertical_alignment = 2
|
bbcode_enabled = true
|
||||||
clip_text = true
|
fit_content = true
|
||||||
|
scroll_active = false
|
||||||
|
autowrap_mode = 0
|
||||||
|
shortcut_keys_enabled = false
|
||||||
|
|||||||
@ -1,20 +1,31 @@
|
|||||||
use godot::classes::ScrollContainer;
|
use godot::classes::{RichTextLabel, ScrollContainer};
|
||||||
use godot::prelude::*;
|
use godot::prelude::*;
|
||||||
|
|
||||||
use godot::{
|
use godot::{
|
||||||
classes::{IPanel, Label, Panel, TextEdit},
|
classes::{IPanel, Panel, TextEdit},
|
||||||
global::godot_print,
|
|
||||||
obj::Base,
|
obj::Base,
|
||||||
register::{GodotClass, godot_api},
|
register::{GodotClass, godot_api},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub enum CliColor {
|
||||||
|
Command,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CliColor {
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
CliColor::Command => "#a2a2a2",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Panel)]
|
#[class(base=Panel)]
|
||||||
struct CommandLinePanel {
|
struct CommandLinePanel {
|
||||||
#[export]
|
#[export]
|
||||||
pub input_field: Option<Gd<TextEdit>>,
|
pub input_field: Option<Gd<TextEdit>>,
|
||||||
#[export]
|
#[export]
|
||||||
pub text_field: Option<Gd<Label>>,
|
pub text_field: Option<Gd<RichTextLabel>>,
|
||||||
#[export]
|
#[export]
|
||||||
pub scroll_container: Option<Gd<ScrollContainer>>,
|
pub scroll_container: Option<Gd<ScrollContainer>>,
|
||||||
|
|
||||||
@ -48,7 +59,7 @@ impl IPanel for CommandLinePanel {
|
|||||||
if text.contains("\n") {
|
if text.contains("\n") {
|
||||||
let parts = text.split("\n");
|
let parts = text.split("\n");
|
||||||
let first = parts.get(0).unwrap();
|
let first = parts.get(0).unwrap();
|
||||||
self.publish_message(first.to_string());
|
self.publish_message(format!("> {}", first.to_string()), CliColor::Command);
|
||||||
self.input_field.as_mut().unwrap().clear();
|
self.input_field.as_mut().unwrap().clear();
|
||||||
self.scroll_next_update = true;
|
self.scroll_next_update = true;
|
||||||
}
|
}
|
||||||
@ -57,14 +68,14 @@ impl IPanel for CommandLinePanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommandLinePanel {
|
impl CommandLinePanel {
|
||||||
pub fn publish_message(&mut self, message: String) {
|
pub fn publish_message(&mut self, message: String, color: CliColor) {
|
||||||
if let Some(field) = &mut self.text_field {
|
if let Some(field) = &mut self.text_field {
|
||||||
let mut text = field.get_text().to_string();
|
if !field.get_parsed_text().is_empty() {
|
||||||
if !text.is_empty() {
|
field.append_text("\n");
|
||||||
text += "\n";
|
|
||||||
}
|
}
|
||||||
text += &message;
|
field.append_text(&format!("[color={}]", color.as_str()));
|
||||||
field.set_text(&text);
|
field.append_text(&message);
|
||||||
|
field.append_text("[/color]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1 +1 @@
|
|||||||
mod cmd;
|
mod cli;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user