From d45a61b960183808c9520223031be9a3b12af98a Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 22 May 2026 21:47:21 +0200 Subject: [PATCH 1/3] Begin console individual labels, colors & reuse --- src/engine/systems/console/console.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/engine/systems/console/console.go b/src/engine/systems/console/console.go index 95da4b5d5..3044738c6 100644 --- a/src/engine/systems/console/console.go +++ b/src/engine/systems/console/console.go @@ -164,7 +164,7 @@ func (c *Console) ExecCommand(key, arg string) (string, error) { func (c *Console) Write(message string) { lbl := c.outputLabel() - lbl.SetText(lbl.Text() + "\n" + message) + lbl.SetText(message) } func (c *Console) help(*engine.Host, string) string { @@ -187,7 +187,20 @@ func (c *Console) clear(*engine.Host, string) string { func (c *Console) outputLabel() *ui.Label { cc, _ := c.doc.GetElementById("consoleContent") - return ui.FirstOnEntity(cc.Children[0].UI.Entity()).ToLabel() + if l := len(cc.Children); l > 1000 { + var last *ui.Label + for i := 1; i < l; i++ { + lbl := ui.FirstOnEntity(cc.Children[i-1].UI.Entity()).ToLabel() + last = ui.FirstOnEntity(cc.Children[i].UI.Entity()).ToLabel() + lbl.SetText(last.Text()) + } + return last + } + new := cc.Children[len(cc.Children)-1] + cc.Children = append(cc.Children, new.Clone(cc)) + lbl := cc.Children[len(cc.Children)-1].UI.ToLabel() + lbl.SetColor(matrix.ColorAquamarine()) + return lbl } func (c *Console) submit(input *ui.Input) { @@ -214,9 +227,9 @@ func (c *Console) submit(input *ui.Input) { lblParent, _ := c.doc.GetElementById("consoleContent") lbl := c.outputLabel() if res != "" { - lbl.SetText(lbl.Text() + "\n" + cmdStr + "\n" + res) + lbl.SetText(cmdStr + "\n" + res) } else { - lbl.SetText(lbl.Text() + "\n" + cmdStr) + lbl.SetText(cmdStr) } lblParent.UIPanel.SetScrollY(matrix.FloatMax) } From 92c89b4a497b38697f9c12a38afb74bae6f00886 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 24 May 2026 12:38:15 +0200 Subject: [PATCH 2/3] Fix console text color --- src/engine/systems/console/console.go | 24 ++++++++++++++++++++---- src/engine/ui/label.go | 4 ++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/engine/systems/console/console.go b/src/engine/systems/console/console.go index 3044738c6..3ed8aee3b 100644 --- a/src/engine/systems/console/console.go +++ b/src/engine/systems/console/console.go @@ -167,6 +167,20 @@ func (c *Console) Write(message string) { lbl.SetText(message) } +func (c *Console) WriteColor(message string, color matrix.Color) { + lbl := c.outputLabel() + lbl.SetText(message) + lbl.EnforceFGColor(color) +} + +func (c *Console) WriteError(message string) { + c.WriteColor(message, matrix.ColorRed()) +} + +func (c *Console) WriteSuccess(message string) { + c.WriteColor(message, matrix.ColorGreen()) +} + func (c *Console) help(*engine.Host, string) string { sb := strings.Builder{} sb.WriteString("Available Commands:\n") @@ -192,14 +206,16 @@ func (c *Console) outputLabel() *ui.Label { for i := 1; i < l; i++ { lbl := ui.FirstOnEntity(cc.Children[i-1].UI.Entity()).ToLabel() last = ui.FirstOnEntity(cc.Children[i].UI.Entity()).ToLabel() + lbl.UnEnforceFGColor() + lbl.EnforceFGColor(last.GetColor()) lbl.SetText(last.Text()) } + last.UnEnforceFGColor() return last } - new := cc.Children[len(cc.Children)-1] - cc.Children = append(cc.Children, new.Clone(cc)) - lbl := cc.Children[len(cc.Children)-1].UI.ToLabel() - lbl.SetColor(matrix.ColorAquamarine()) + new := cc.Children[len(cc.Children)-1].Clone(cc) + cc.Children = append(cc.Children, new) + lbl := new.UI.ToLabel() return lbl } diff --git a/src/engine/ui/label.go b/src/engine/ui/label.go index 388f052b4..38abe7e61 100644 --- a/src/engine/ui/label.go +++ b/src/engine/ui/label.go @@ -314,6 +314,10 @@ func (label *Label) setLabelScissors() { } } +func (label *Label) GetColor() matrix.Color { + return label.LabelData().fgColor +} + func (label *Label) SetColor(newColor matrix.Color) { ld := label.LabelData() if ld.isForcedFGColor || ld.fgColor.Equals(newColor) { From cc2a011297316ebac4a1f9e0162f4fd3658a4de1 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 24 May 2026 14:28:37 +0200 Subject: [PATCH 3/3] Fix console clear --- src/engine/systems/console/console.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/engine/systems/console/console.go b/src/engine/systems/console/console.go index 3ed8aee3b..806faf175 100644 --- a/src/engine/systems/console/console.go +++ b/src/engine/systems/console/console.go @@ -195,7 +195,11 @@ func (c *Console) help(*engine.Host, string) string { } func (c *Console) clear(*engine.Host, string) string { - c.outputLabel().SetText("") + cc, _ := c.doc.GetElementById("consoleContent") + for _, c := range cc.Children { + c.UI.Entity().Deactivate() + } + cc.UIPanel.SetScrollY(0) return "" } @@ -214,7 +218,7 @@ func (c *Console) outputLabel() *ui.Label { return last } new := cc.Children[len(cc.Children)-1].Clone(cc) - cc.Children = append(cc.Children, new) + cc.UIPanel.AddChild(new.UI) lbl := new.UI.ToLabel() return lbl }