package widgets import ( "fmt" "strings" t "git.bullercodeworks.com/brian/tcell-widgets" wh "git.bullercodeworks.com/brian/tcell-widgets/helpers" "github.com/gdamore/tcell" ) /* StatusBlock is not a widget type, they're meant to be used within a StatusBar */ type StatusBlock struct { id string style tcell.Style x, y int tp int parts []string text string separator string } const ( SBTypeText = iota SBTypePath ) func NewStatusBlock(id string, s tcell.Style) *StatusBlock { b := StatusBlock{ id: id, style: s, separator: "  ", } return &b } func (b *StatusBlock) SetPos(p t.Coord) { b.x, b.y = p.X, p.Y } func (b *StatusBlock) Width() int { switch b.tp { case SBTypePath: return len(strings.Join(b.parts, b.separator)) default: return len(b.text) } } func (b *StatusBlock) SetType(tp int) { switch tp { case SBTypeText: b.tp = tp default: b.tp = SBTypeText } } func (b *StatusBlock) SetParts(pts []string) { b.parts = pts } func (b *StatusBlock) AddPart(p string) { b.parts = append(b.parts, p) } func (b *StatusBlock) SetText(t string) { b.text = t } func (b *StatusBlock) Draw(screen tcell.Screen) { //wh.DrawText(b.x, b.y, fmt.Sprintf("%d,%d: Text: %s; Path: %s", b.x, b.y, b.text, strings.Join(b.parts, b.separator)), b.style, screen) switch b.tp { case SBTypeText: b.DrawText(screen) case SBTypePath: b.DrawPath(screen) } } func (b *StatusBlock) DrawText(screen tcell.Screen) { wh.DrawText(b.x, b.y, b.text, b.style, screen) } func (b *StatusBlock) DrawPath(screen tcell.Screen) { wh.DrawText(b.x, b.y, fmt.Sprintf("%s %s", strings.Join(b.parts, b.separator), b.separator), b.style, screen) }