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 }
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user