Skip to content

Commit

Permalink
hof/tui: bugfixes and some refactoring along the way, some style and …
Browse files Browse the repository at this point in the history
…help updates too (#325)
  • Loading branch information
verdverm authored Sep 10, 2023
1 parent b9d8214 commit 5d9e8ca
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 188 deletions.
2 changes: 1 addition & 1 deletion lib/tui/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Cmd(args []string, rflags flags.RootPflagpole) error {
// some latent locksups occur randomly
time.Sleep(time.Millisecond * 23)
tui.SendCustomEvent("/router/dispatch", context)
tui.SendCustomEvent("/status/message", "[blue::b]Welcome to [gold::bi]_[ivory]Hofstadter[-::-]")
tui.SendCustomEvent("/status/message", "[dodgerblue::b]Welcome to [gold::bi]_[ivory]Hofstadter[-::-]")
}()

// Start the Main (Blocking) Loop
Expand Down
58 changes: 58 additions & 0 deletions lib/tui/components/cue/playground/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,69 @@ import (

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"github.com/atotto/clipboard"

"github.com/hofstadter-io/hof/lib/tui"
"github.com/hofstadter-io/hof/lib/tui/components/cue/helpers"
)

func (C *Playground) HandleAction(action string, args []string, context map[string]any) (bool, error) {
tui.Log("warn", fmt.Sprintf("Playground.HandleAction: %v %v", action, args))
var err error
handled := true

// item actions
switch action {
case "push":
id, err := C.PushToPlayground()
// if ok...
if err == nil {
msg := fmt.Sprintf("snippet id: %s (link copied!)", id)

url := fmt.Sprintf("https://cuelang.org/play?id=%s", id)
clipboard.WriteAll(url)

tui.Tell("error", msg)
tui.Log("trace", msg)
}


case "write":
if len(args) != 1 {
err = fmt.Errorf("write requires a filename")
} else {
filename := args[0]
err = C.WriteEditToFile(filename)
// if ok...
if err == nil {
msg := fmt.Sprintf("editor text saved to %s", filename)
tui.Tell("error", msg)
tui.Log("trace", msg)
}
}

case "export":
if len(args) != 1 {
err = fmt.Errorf("export requires a filename")
} else {
filename := args[0]
err := C.ExportFinalToFile(filename)
// if ok...
if err == nil {
msg := fmt.Sprintf("value exported to %s", filename)
tui.Tell("error", msg)
tui.Log("trace", msg)
}
}


default:
err = fmt.Errorf("unknown command %q", action)
}

return handled, err
}

func (C *Playground) Rebuild(rebuildScope bool) error {
// tui.Log("info", fmt.Sprintf("Play.rebuildScope %v %v %v", rebuildScope, C.useScope, C.scope.config))
var (
Expand Down
9 changes: 0 additions & 9 deletions lib/tui/components/panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ func (P *Panel) Refresh(context map[string]any) error {
case "update":
P.updatePanelItem(context)

//case "set.scope", "set.scope.runtime", "set.scope.value":
// P.setItemScope(cid, action, args, context)

//case "set.value", "set.value.runtime", "set.value.value":
// P.setItemValue(cid, action, args, context)

//case "set.text":
// P.setItemText(cid, action, args, context)

case "set.panel.name":
if len(args) < 1 {
return fmt.Errorf("%s requires an argument", action)
Expand Down
16 changes: 6 additions & 10 deletions lib/tui/modules/eval/argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func enrichContext(context map[string]any) (map[string]any) {
case
"push",
"export",
"write",
"set.runtime",
"set.value.runtime",
"set.value.value",
Expand Down Expand Up @@ -113,12 +114,15 @@ func enrichContext(context map[string]any) (map[string]any) {
// default when nothing
case "help":
context["item"] = "help"
// context["action"] = "insert" // probably the default?
// dual-pane eval'r (default when doing eval things)
case "play":
context["item"] = "play"
context["action"] = "update" // probably the default?
// value viewer
case "view":
context["item"] = "view"
context["action"] = "update" // probably the default?

// should this be handled lower too?
// we might want a more general
Expand All @@ -131,9 +135,9 @@ func enrichContext(context map[string]any) (map[string]any) {
//

// cue item action targets
case "scope":
case "S", "scope":
context["target"] = "scope"
case "value":
case "V", "value":
context["target"] = "value"

// default, the current focused item
Expand Down Expand Up @@ -210,14 +214,6 @@ argsDone:
//args = args[1:]
}

// set action to first arg if available
if _, ok := context["action"]; !ok {
if len(args) > 0 {
context["action"] = args[0]
args = args[1:]
}
}

// make sure we update the context args
context["args"] = args

Expand Down
12 changes: 6 additions & 6 deletions lib/tui/modules/eval/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const EvalHelpText = `
[red]:q[-] (from the command box)
[dodgerblue::bu]Panel Management:[-::-]
[lime]A-J[-] new item before
[lime]A-K[-] new item after
[lime]A-J[-] create item before
[lime]A-K[-] create item after
[lime]A-H[-] move item before
[lime]A-L[-] move item after
[lime]A-T[-] split panel into two
[lime]A-T[-] split current item
[lime]A-D[-] delete current item
[lime]A-F[-] flip panel flex direction
[lime]A-P[-] show borders on panels
[lime]A-O[-] show borders on items
[lime]A-F[-] toggle flex direction
[lime]A-P[-] toggle panel borders
[lime]A-O[-] toggle item borders
[dodgerblue::bu]Navigation:[-::-]
(with mouse)
Expand Down
Loading

0 comments on commit 5d9e8ca

Please sign in to comment.