summaryrefslogtreecommitdiffstats
path: root/pkg/gui/main_panels.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-18 09:03:52 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commit3c87ff4eff46449d5e697e954b3bdf01d2c76f19 (patch)
treec1c8c67ba187d1d145e803a99957093682e3145b /pkg/gui/main_panels.go
parent0f7b2c45d773989229cb84a0147232962c6ae0e0 (diff)
WIP: standardising how we render to main
Diffstat (limited to 'pkg/gui/main_panels.go')
-rw-r--r--pkg/gui/main_panels.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/pkg/gui/main_panels.go b/pkg/gui/main_panels.go
new file mode 100644
index 000000000..af6718c60
--- /dev/null
+++ b/pkg/gui/main_panels.go
@@ -0,0 +1,69 @@
+package gui
+
+import "os/exec"
+
+type viewUpdateOpts struct {
+ title string
+ task func() error
+}
+
+type refreshMainOpts struct {
+ main *viewUpdateOpts
+ secondary *viewUpdateOpts
+}
+
+// constants for updateTask's kind field
+const (
+ RENDER_STRING = iota
+ RUN_FUNCTION
+ RUN_COMMAND
+)
+
+type updateTask struct {
+ kind int
+ str string
+ f func(chan struct{}) error
+ cmd *exec.Cmd
+}
+
+func (gui *Gui) createRenderStringTask(str string) {
+
+}
+
+func (gui *Gui) refreshMain(opts refreshMainOpts) error {
+ mainView := gui.getMainView()
+ secondaryView := gui.getSecondaryView()
+
+ if opts.main != nil {
+ mainView.Title = opts.main.title
+ if err := opts.main.task(); err != nil {
+ gui.Log.Error(err)
+ return nil
+ }
+ }
+
+ gui.splitMainPanel(opts.secondary != nil)
+
+ if opts.secondary != nil {
+ secondaryView.Title = opts.secondary.title
+ if err := opts.secondary.task(); err != nil {
+ gui.Log.Error(err)
+ return nil
+ }
+ }
+
+ return nil
+}
+
+func (gui *Gui) splitMainPanel(splitMainPanel bool) {
+ gui.State.SplitMainPanel = splitMainPanel
+
+ // no need to set view on bottom when splitMainPanel is false: it will have zero size anyway thanks to our view arrangement code.
+ if splitMainPanel {
+ _, _ = gui.g.SetViewOnTop("secondary")
+ }
+}
+
+func (gui *Gui) isMainPanelSplit() bool {
+ return gui.State.SplitMainPanel
+}