mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
use type switch instead of type key
This commit is contained in:
parent
a2318d75b5
commit
cb0d3a480a
@ -23,27 +23,15 @@ type refreshMainOpts struct {
|
|||||||
secondary *viewUpdateOpts
|
secondary *viewUpdateOpts
|
||||||
}
|
}
|
||||||
|
|
||||||
// constants for updateTask's kind field
|
|
||||||
type TaskKind int
|
|
||||||
|
|
||||||
const (
|
|
||||||
RENDER_STRING TaskKind = iota
|
|
||||||
RENDER_STRING_WITHOUT_SCROLL
|
|
||||||
RUN_COMMAND
|
|
||||||
RUN_PTY
|
|
||||||
)
|
|
||||||
|
|
||||||
type updateTask interface {
|
type updateTask interface {
|
||||||
GetKind() TaskKind
|
IsUpdateTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
type renderStringTask struct {
|
type renderStringTask struct {
|
||||||
str string
|
str string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *renderStringTask) GetKind() TaskKind {
|
func (t *renderStringTask) IsUpdateTask() {}
|
||||||
return RENDER_STRING
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRenderStringTask(str string) *renderStringTask {
|
func NewRenderStringTask(str string) *renderStringTask {
|
||||||
return &renderStringTask{str: str}
|
return &renderStringTask{str: str}
|
||||||
@ -53,9 +41,7 @@ type renderStringWithoutScrollTask struct {
|
|||||||
str string
|
str string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *renderStringWithoutScrollTask) GetKind() TaskKind {
|
func (t *renderStringWithoutScrollTask) IsUpdateTask() {}
|
||||||
return RENDER_STRING_WITHOUT_SCROLL
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRenderStringWithoutScrollTask(str string) *renderStringWithoutScrollTask {
|
func NewRenderStringWithoutScrollTask(str string) *renderStringWithoutScrollTask {
|
||||||
return &renderStringWithoutScrollTask{str: str}
|
return &renderStringWithoutScrollTask{str: str}
|
||||||
@ -66,9 +52,7 @@ type runCommandTask struct {
|
|||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *runCommandTask) GetKind() TaskKind {
|
func (t *runCommandTask) IsUpdateTask() {}
|
||||||
return RUN_COMMAND
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRunCommandTask(cmd *exec.Cmd) *runCommandTask {
|
func NewRunCommandTask(cmd *exec.Cmd) *runCommandTask {
|
||||||
return &runCommandTask{cmd: cmd}
|
return &runCommandTask{cmd: cmd}
|
||||||
@ -83,9 +67,7 @@ type runPtyTask struct {
|
|||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *runPtyTask) GetKind() TaskKind {
|
func (t *runPtyTask) IsUpdateTask() {}
|
||||||
return RUN_PTY
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask {
|
func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask {
|
||||||
return &runPtyTask{cmd: cmd}
|
return &runPtyTask{cmd: cmd}
|
||||||
@ -97,22 +79,18 @@ func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
||||||
switch task.GetKind() {
|
switch v := task.(type) {
|
||||||
case RENDER_STRING:
|
case *renderStringTask:
|
||||||
specificTask := task.(*renderStringTask)
|
return gui.newStringTask(view, v.str)
|
||||||
return gui.newStringTask(view, specificTask.str)
|
|
||||||
|
|
||||||
case RENDER_STRING_WITHOUT_SCROLL:
|
case *renderStringWithoutScrollTask:
|
||||||
specificTask := task.(*renderStringWithoutScrollTask)
|
return gui.newStringTaskWithoutScroll(view, v.str)
|
||||||
return gui.newStringTaskWithoutScroll(view, specificTask.str)
|
|
||||||
|
|
||||||
case RUN_COMMAND:
|
case *runCommandTask:
|
||||||
specificTask := task.(*runCommandTask)
|
return gui.newCmdTask(view, v.cmd, v.prefix)
|
||||||
return gui.newCmdTask(view, specificTask.cmd, specificTask.prefix)
|
|
||||||
|
|
||||||
case RUN_PTY:
|
case *runPtyTask:
|
||||||
specificTask := task.(*runPtyTask)
|
return gui.newPtyTask(view, v.cmd, v.prefix)
|
||||||
return gui.newPtyTask(view, specificTask.cmd, specificTask.prefix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user