Doing some work
This commit is contained in:
@@ -22,6 +22,8 @@ THE SOFTWARE.
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
wd "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
@@ -31,18 +33,19 @@ import (
|
||||
|
||||
// TODO: Format contents as json. For now this is a duplice of the Text widget
|
||||
type JsonContent struct {
|
||||
id string
|
||||
text string
|
||||
contents []string
|
||||
style tcell.Style
|
||||
x, y int
|
||||
w, h int
|
||||
visible bool
|
||||
active bool
|
||||
focusable bool
|
||||
keyMap *wd.KeyMap
|
||||
id string
|
||||
|
||||
flags wd.LayoutFlag
|
||||
valueString string
|
||||
contents []string
|
||||
style tcell.Style
|
||||
x, y int
|
||||
w, h int
|
||||
visible bool
|
||||
active bool
|
||||
focusable bool
|
||||
keyMap *wd.KeyMap
|
||||
|
||||
value any
|
||||
}
|
||||
|
||||
var _ wd.Widget = (*JsonContent)(nil)
|
||||
@@ -102,17 +105,28 @@ func (w *JsonContent) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *JsonContent) MinW() int { return wh.Longest(w.contents) }
|
||||
func (w *JsonContent) MinH() int { return len(w.contents) }
|
||||
|
||||
func (w *JsonContent) SetJsonContent(txt string) {
|
||||
w.text = txt
|
||||
if strings.Contains(w.text, "\n") {
|
||||
w.contents = strings.Split(w.text, "\n")
|
||||
} else {
|
||||
w.contents = []string{w.text}
|
||||
func (w *JsonContent) SetValue(v any) error {
|
||||
w.value = v
|
||||
// Go ahead and try to build the json for v
|
||||
bts, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshalling value: %w", err)
|
||||
}
|
||||
w.valueString = string(bts)
|
||||
w.contents = strings.Split(w.valueString, "\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *JsonContent) GetJsonContent() string { return w.text }
|
||||
func (w *JsonContent) GetContents() []string { return w.contents }
|
||||
/*
|
||||
func (w *JsonContent) SetJsonContent(txt string) {
|
||||
w.text = txt
|
||||
if strings.Contains(w.text, "\n") {
|
||||
w.contents = strings.Split(w.text, "\n")
|
||||
} else {
|
||||
w.contents = []string{w.text}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *JsonContent) AddFlag(f wd.LayoutFlag) { w.flags.Add(f) }
|
||||
func (w *JsonContent) RemoveFlag(f wd.LayoutFlag) { w.flags.Remove(f) }
|
||||
func (w *JsonContent) GetJsonContent() string { return w.text }
|
||||
func (w *JsonContent) GetContents() []string { return w.contents }
|
||||
*/
|
||||
|
||||
95
widgets/status_bar.go
Normal file
95
widgets/status_bar.go
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright © Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package widgets
|
||||
|
||||
import (
|
||||
t "git.bullercodeworks.com/brian/tcell-widgets"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
type StatusBar struct {
|
||||
id string
|
||||
style tcell.Style
|
||||
x, y int
|
||||
w, h int
|
||||
visible bool
|
||||
keyMap *t.KeyMap
|
||||
|
||||
logger func(string, ...any)
|
||||
}
|
||||
|
||||
func NewStatusBar(id string, s tcell.Style) *StatusBar {
|
||||
ret := &StatusBar{}
|
||||
ret.Init(id, s)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (w *StatusBar) Init(id string, s tcell.Style) {
|
||||
w.id = id
|
||||
w.style = s
|
||||
w.visible = true
|
||||
}
|
||||
|
||||
func (w *StatusBar) Id() string { return w.id }
|
||||
func (w *StatusBar) HandleResize(ev *tcell.EventResize) {
|
||||
w.w, w.h = ev.Size()
|
||||
}
|
||||
|
||||
func (w *StatusBar) GetKeyMap() *t.KeyMap { return w.keyMap }
|
||||
func (w *StatusBar) SetKeyMap(km *t.KeyMap) { w.keyMap = km }
|
||||
|
||||
func (w *StatusBar) HandleKey(ev *tcell.EventKey) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (w *StatusBar) HandleTime(ev *tcell.EventTime) {}
|
||||
|
||||
func (w *StatusBar) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (w *StatusBar) Active() bool { return false }
|
||||
func (w *StatusBar) SetActive(a bool) {}
|
||||
func (w *StatusBar) Visible() bool { return w.visible }
|
||||
func (w *StatusBar) SetVisible(a bool) { w.visible = a }
|
||||
func (w *StatusBar) Focusable() bool { return false }
|
||||
func (w *StatusBar) SetFocusable(b bool) {}
|
||||
func (w *StatusBar) SetX(x int) { w.x = x }
|
||||
func (w *StatusBar) SetY(y int) { w.y = y }
|
||||
func (w *StatusBar) GetX() int { return w.x }
|
||||
func (w *StatusBar) GetY() int { return w.y }
|
||||
func (w *StatusBar) GetPos() t.Coord { return t.Coord{X: w.x, Y: w.y} }
|
||||
func (w *StatusBar) SetPos(c t.Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *StatusBar) GetW() int { return w.w }
|
||||
func (w *StatusBar) GetH() int { return w.h }
|
||||
func (w *StatusBar) SetW(wd int) { w.w = wd }
|
||||
func (w *StatusBar) SetH(h int) { w.h = h }
|
||||
func (w *StatusBar) SetSize(c t.Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *StatusBar) WantW() int { return w.w }
|
||||
func (w *StatusBar) WantH() int { return w.h }
|
||||
func (w *StatusBar) MinW() int { return w.w }
|
||||
func (w *StatusBar) MinH() int { return 1 }
|
||||
|
||||
func (w *StatusBar) SetLogger(l func(string, ...any)) { w.logger = l }
|
||||
func (w *StatusBar) Log(txt string, args ...any) { w.logger(txt, args...) }
|
||||
Reference in New Issue
Block a user