bug fix but still a new one :(
This commit is contained in:
@@ -44,7 +44,7 @@ func (d *DivComponent) Render() string {
|
||||
osui.RenderOnFrame(c, &frame)
|
||||
}
|
||||
for i, f := range frame {
|
||||
frame[i] = colors.Combine(d.Style.Foreground, d.Style.Background) + f + d.Data.DefaultColor
|
||||
frame[i] = colors.Reset + d.Data.DefaultColor + colors.Combine(d.Style.Foreground, d.Style.Background) + f + colors.Reset + d.Data.DefaultColor
|
||||
}
|
||||
return strings.Join(frame, "\n")
|
||||
}
|
||||
@@ -73,17 +73,22 @@ func (d *DivComponent) Update(key string) bool {
|
||||
if len(d.Components) > 0 {
|
||||
d.Components[d.ActiveComponent].GetComponentData().IsActive = d.Data.IsActive
|
||||
if d.Components[d.ActiveComponent].Update(key) {
|
||||
if d.ActiveComponent < len(d.Components)-1 {
|
||||
d.updateActive(d.ActiveComponent + 1)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
// if d.ActiveComponent < len(d.Components)-1 {
|
||||
// d.updateActive(d.ActiveComponent + 1)
|
||||
// } else {
|
||||
// return true
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *DivComponent) SetStyle(c interface{}) {
|
||||
d.Style = osui.SetDefaults(c.(*DivStyle)).(*DivStyle)
|
||||
}
|
||||
|
||||
func (d *DivComponent) updateActive(newIndex int) {
|
||||
if newIndex >= 0 && newIndex < len(d.Components) && len(d.Components) > 0 {
|
||||
d.ActiveComponent = newIndex
|
||||
|
||||
+11
-4
@@ -39,11 +39,14 @@ func (s InputBoxComponent) Render() string {
|
||||
s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
" %s\n|%s\n %s",
|
||||
strings.Repeat("_", int(s.max_size)),
|
||||
s.InputData+osui.LogicValue(s.Data.IsActive, "█", "|"),
|
||||
strings.Repeat("‾", int(s.max_size)),
|
||||
" %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.Reset+s.Data.DefaultColor,
|
||||
colors.Reset+s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,6 +85,10 @@ func (s *InputBoxComponent) Update(key string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *InputBoxComponent) SetStyle(c interface{}) {
|
||||
d.Style = osui.SetDefaults(c.(*InputBoxStyle)).(*InputBoxStyle)
|
||||
}
|
||||
|
||||
func InputBox(max_size uint) *InputBoxComponent {
|
||||
return &InputBoxComponent{max_size: max_size, Style: osui.SetDefaults(&InputBoxStyle{}).(*InputBoxStyle)}
|
||||
}
|
||||
|
||||
+25
-12
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type PaginatorStyle struct {
|
||||
Active string `default:"\033[32m"`
|
||||
Active string `default:"\033[32m"`
|
||||
Inactive string `default:""`
|
||||
}
|
||||
|
||||
type PaginatorComponent struct {
|
||||
@@ -23,25 +24,33 @@ func (p *PaginatorComponent) GetComponentData() *osui.ComponentData {
|
||||
return &p.Data
|
||||
}
|
||||
|
||||
func (p PaginatorComponent) Render() string {
|
||||
pgs := strings.Repeat(" ", p.Data.Width/2)
|
||||
for page, c := range p.Components {
|
||||
func (p *PaginatorComponent) Render() string {
|
||||
width, _ := osui.GetTerminalSize()
|
||||
pgs := strings.Repeat(" ", (width-len(p.Components))/2)
|
||||
osui.UseStyle(p.Style)
|
||||
frame := osui.NewFrame(p.Data.Width, p.Data.Height)
|
||||
for i, c := range p.Components {
|
||||
data := c.GetComponentData()
|
||||
if page == p.ActiveComponent {
|
||||
data.IsActive = true
|
||||
if i == p.ActiveComponent {
|
||||
pgs += p.Style.Active + "•" + colors.Reset
|
||||
data.IsActive = true
|
||||
} else {
|
||||
pgs += colors.Reset + "•"
|
||||
pgs += colors.Reset + p.Style.Inactive + "•"
|
||||
data.IsActive = false
|
||||
}
|
||||
if data.Screen == nil {
|
||||
data.Screen = p.Data.Screen
|
||||
if data.Width == 0 {
|
||||
data.Width = p.Data.Width
|
||||
}
|
||||
data.Height = p.Data.Height - 1
|
||||
data.Width = p.Data.Width
|
||||
if data.Height == 0 {
|
||||
data.Height = p.Data.Height
|
||||
}
|
||||
data.DefaultColor = p.Data.DefaultColor
|
||||
data.Screen = p.Data.Screen
|
||||
}
|
||||
frame := osui.NewFrame(p.Data.Width, p.Data.Height-3)
|
||||
osui.RenderOnFrame(p.Components[p.ActiveComponent], &frame)
|
||||
for i, f := range frame {
|
||||
frame[i] = colors.Reset + p.Data.DefaultColor + f + colors.Reset
|
||||
}
|
||||
return fmt.Sprintf("%s\n%s", pgs, colors.Reset+strings.Join(frame, "\n"))
|
||||
}
|
||||
|
||||
@@ -83,6 +92,10 @@ func (p *PaginatorComponent) updateActive(newIndex int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PaginatorComponent) SetStyle(c interface{}) {
|
||||
p.Style = osui.SetDefaults(c.(*PaginatorStyle)).(*PaginatorStyle)
|
||||
}
|
||||
|
||||
func Paginator(pages ...osui.Component) *PaginatorComponent {
|
||||
return &PaginatorComponent{
|
||||
Components: pages,
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@ package ui
|
||||
|
||||
import (
|
||||
"github.com/orus-dev/osui"
|
||||
"github.com/orus-dev/osui/colors"
|
||||
)
|
||||
|
||||
type TextComponent struct {
|
||||
@@ -18,9 +19,11 @@ func (t *TextComponent) GetComponentData() *osui.ComponentData {
|
||||
}
|
||||
|
||||
func (t TextComponent) Render() string {
|
||||
return t.Text
|
||||
return colors.Reset + t.Data.DefaultColor + t.Text
|
||||
}
|
||||
|
||||
func (t *TextComponent) SetStyle(interface{}) {}
|
||||
|
||||
func Text(text string) *TextComponent {
|
||||
return &TextComponent{Text: text}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user