bug fix (There is a small bug on inputBox again)

This commit is contained in:
2024-09-27 14:38:39 +02:00
parent 3b2ff24c1f
commit cf93b3383f
7 changed files with 83 additions and 89 deletions
+11 -13
View File
@@ -5,6 +5,7 @@ import (
"github.com/orus-dev/osui"
"github.com/orus-dev/osui/colors"
"github.com/orus-dev/osui/isKey"
)
type DivStyle struct {
@@ -39,12 +40,12 @@ func (d *DivComponent) Render() string {
if data.Height == 0 {
data.Height = d.Data.Height
}
data.DefaultColor = colors.Combine(d.Style.Foreground, d.Style.Background)
data.DefaultColor = colors.Combine(d.Style.Background, d.Style.Foreground)
data.Screen = d.Data.Screen
osui.RenderOnFrame(c, &frame)
}
for i, f := range frame {
frame[i] = colors.Reset + d.Data.DefaultColor + colors.Combine(d.Style.Foreground, d.Style.Background) + f + colors.Reset + d.Data.DefaultColor
frame[i] = colors.Combine(d.Style.Foreground, d.Style.Background) + f + colors.Reset
}
return strings.Join(frame, "\n")
}
@@ -63,22 +64,19 @@ func (d *DivComponent) Run() {
}
func (d *DivComponent) Update(key string) bool {
switch key {
case osui.Key.Up:
if isKey.Up(key) {
d.updateActive(d.ActiveComponent - 1)
case osui.Key.Down:
} else if isKey.Down(key) {
d.updateActive(d.ActiveComponent + 1)
default:
} else {
if len(d.Components) > 0 {
d.Components[d.ActiveComponent].GetComponentData().IsActive = d.Data.IsActive
if d.Components[d.ActiveComponent].Update(key) {
return true
// if d.ActiveComponent < len(d.Components)-1 {
// d.updateActive(d.ActiveComponent + 1)
// } else {
// return true
// }
if d.ActiveComponent < len(d.Components)-1 {
d.updateActive(d.ActiveComponent + 1)
} else {
return true
}
}
}
}
+16 -8
View File
@@ -6,6 +6,7 @@ import (
"github.com/orus-dev/osui"
"github.com/orus-dev/osui/colors"
"github.com/orus-dev/osui/isKey"
)
type InputBoxStyle struct {
@@ -19,6 +20,7 @@ type InputBoxComponent struct {
Data osui.ComponentData
Style *InputBoxStyle
max_size uint
cursor uint
InputData string
}
@@ -30,7 +32,7 @@ func (s InputBoxComponent) Render() string {
osui.UseStyle(s.Style)
if s.max_size > uint(len(s.InputData)) {
return fmt.Sprintf(
" %s\n%s|%s%s|%s\n %s",
" %s\n%s│%s%s│%s\n %s",
colors.Reset+s.Style.Outline+strings.Repeat("_", int(s.max_size))+colors.Reset,
colors.Reset+s.Style.Outline,
colors.Combine(s.Style.Foreground, s.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Style.Cursor+"█"+colors.Combine(s.Style.Foreground, s.Style.Background), ""),
@@ -41,10 +43,10 @@ func (s InputBoxComponent) Render() string {
}
return fmt.Sprintf(
" %s\n%s|%s%s\n %s",
" %s\n%s│%s%s\n %s",
colors.Reset+s.Style.Outline+strings.Repeat("_", int(s.max_size))+colors.Reset,
colors.Reset+s.Style.Outline,
colors.Combine(s.Style.Foreground, s.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Style.Cursor+"█", "")+colors.Reset+colors.Reset,
colors.Combine(s.Style.Foreground, s.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Style.Cursor+"█"+colors.Reset+colors.Reset, colors.Reset+s.Style.Outline+"|"+colors.Reset),
colors.Reset+s.Data.DefaultColor,
colors.Reset+s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
)
@@ -67,15 +69,21 @@ func (s *InputBoxComponent) Read() error {
}
func (s *InputBoxComponent) Update(key string) bool {
switch key {
case osui.Key.Enter:
if isKey.Enter(key) {
return true
case osui.Key.Backspace:
} else if isKey.Backspace(key) {
if len(s.InputData) > 0 {
s.InputData = s.InputData[:len(s.InputData)-1]
}
default:
} else if isKey.Left(key) {
if s.cursor > 0 {
s.cursor--
}
} else if isKey.Right(key) {
if s.cursor < s.max_size {
s.cursor++
}
} else {
if len(key) == 1 {
if int(s.max_size) > len(s.InputData) {
s.InputData += key
+5 -5
View File
@@ -6,6 +6,7 @@ import (
"github.com/orus-dev/osui"
"github.com/orus-dev/osui/colors"
"github.com/orus-dev/osui/isKey"
)
type PaginatorStyle struct {
@@ -55,23 +56,22 @@ func (p *PaginatorComponent) Render() string {
}
func (p *PaginatorComponent) Update(key string) bool {
switch key {
case "\x1b[Z":
if key == "\x1b[Z" {
if p.ActiveComponent > 0 {
p.updateActive(p.ActiveComponent - 1)
} else {
p.updateActive(len(p.Components) - 1)
}
case osui.Key.Tab:
} else if isKey.Tab(key) {
if p.ActiveComponent < len(p.Components)-1 {
p.updateActive(p.ActiveComponent + 1)
} else {
p.updateActive(0)
}
case osui.Key.Escape:
} else if isKey.Escape(key) {
fmt.Print("\n\n")
return true
default:
} else {
if len(p.Components) > 0 {
p.Components[p.ActiveComponent].GetComponentData().IsActive = p.Data.IsActive
if p.Components[p.ActiveComponent].Update(key) {
+1 -2
View File
@@ -2,7 +2,6 @@ package ui
import (
"github.com/orus-dev/osui"
"github.com/orus-dev/osui/colors"
)
type TextComponent struct {
@@ -19,7 +18,7 @@ func (t *TextComponent) GetComponentData() *osui.ComponentData {
}
func (t TextComponent) Render() string {
return colors.Reset + t.Data.DefaultColor + t.Text
return t.Text
}
func (t *TextComponent) SetStyle(interface{}) {}