From f5b22d94d939b0fc1aff433686e891e0a7507950 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 18 Aug 2020 22:02:35 +1000 Subject: WIP --- pkg/gui/main_panels.go | 111 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 9 deletions(-) (limited to 'pkg/gui/main_panels.go') diff --git a/pkg/gui/main_panels.go b/pkg/gui/main_panels.go index af6718c60..87072406a 100644 --- a/pkg/gui/main_panels.go +++ b/pkg/gui/main_panels.go @@ -4,7 +4,14 @@ import "os/exec" type viewUpdateOpts struct { title string - task func() error + + // awkwardly calling this noWrap because of how hard Go makes it to have + // a boolean option that defaults to true + noWrap bool + + highlight bool + + task updateTask } type refreshMainOpts struct { @@ -15,19 +22,100 @@ type refreshMainOpts struct { // constants for updateTask's kind field const ( RENDER_STRING = iota + RENDER_STRING_WITHOUT_SCROLL RUN_FUNCTION RUN_COMMAND + RUN_PTY ) -type updateTask struct { - kind int - str string - f func(chan struct{}) error - cmd *exec.Cmd +type updateTask interface { + GetKind() int +} + +type renderStringTask struct { + str string +} + +func (t *renderStringTask) GetKind() int { + return RENDER_STRING +} + +func (gui *Gui) createRenderStringTask(str string) *renderStringTask { + return &renderStringTask{str: str} +} + +type renderStringWithoutScrollTask struct { + str string +} + +func (t *renderStringWithoutScrollTask) GetKind() int { + return RENDER_STRING_WITHOUT_SCROLL +} + +func (gui *Gui) createRenderStringWithoutScrollTask(str string) *renderStringWithoutScrollTask { + return &renderStringWithoutScrollTask{str: str} +} + +type runCommandTask struct { + cmd *exec.Cmd +} + +func (t *runCommandTask) GetKind() int { + return RUN_COMMAND +} + +func (gui *Gui) createRunCommandTask(cmd *exec.Cmd) *runCommandTask { + return &runCommandTask{cmd: cmd} +} + +type runPtyTask struct { + cmd *exec.Cmd +} + +func (t *runPtyTask) GetKind() int { + return RUN_PTY +} + +func (gui *Gui) createRunPtyTask(cmd *exec.Cmd) *runPtyTask { + return &runPtyTask{cmd: cmd} +} + +type runFunctionTask struct { + f func(chan struct{}) error +} + +func (t *runFunctionTask) GetKind() int { + return RUN_FUNCTION +} + +func (gui *Gui) createRunFunctionTask(f func(chan struct{}) error) *runFunctionTask { + return &runFunctionTask{f: f} } -func (gui *Gui) createRenderStringTask(str string) { +func (gui *Gui) runTaskForView(viewName string, task updateTask) error { + switch task.GetKind() { + case RENDER_STRING: + specificTask := task.(*renderStringTask) + return gui.newStringTask(viewName, specificTask.str) + + case RENDER_STRING_WITHOUT_SCROLL: + specificTask := task.(*renderStringWithoutScrollTask) + return gui.newStringTaskWithoutScroll(viewName, specificTask.str) + + case RUN_FUNCTION: + specificTask := task.(*runFunctionTask) + return gui.newTask(viewName, specificTask.f) + case RUN_COMMAND: + specificTask := task.(*runCommandTask) + return gui.newCmdTask(viewName, specificTask.cmd) + + case RUN_PTY: + specificTask := task.(*runPtyTask) + return gui.newPtyTask(viewName, specificTask.cmd) + } + + return nil } func (gui *Gui) refreshMain(opts refreshMainOpts) error { @@ -36,7 +124,10 @@ func (gui *Gui) refreshMain(opts refreshMainOpts) error { if opts.main != nil { mainView.Title = opts.main.title - if err := opts.main.task(); err != nil { + mainView.Wrap = !opts.main.noWrap + mainView.Highlight = opts.main.highlight // TODO: see what the default should be + + if err := gui.runTaskForView("main", opts.main.task); err != nil { gui.Log.Error(err) return nil } @@ -46,7 +137,9 @@ func (gui *Gui) refreshMain(opts refreshMainOpts) error { if opts.secondary != nil { secondaryView.Title = opts.secondary.title - if err := opts.secondary.task(); err != nil { + secondaryView.Wrap = !opts.secondary.noWrap + mainView.Highlight = opts.main.highlight // TODO: see what the default should be + if err := gui.runTaskForView("secondary", opts.secondary.task); err != nil { gui.Log.Error(err) return nil } -- cgit v1.2.3