Skip to content

Commit ef16867

Browse files
committed
Cleanup: add NewRunPtyTaskWithPrefix funxtion instead of setting Prefix manually
This is consistent with NewRunCommandTaskWithPrefix.
1 parent edcfce2 commit ef16867

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pkg/gui/controllers/files_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,14 @@ func (self *FilesController) GetOnRenderToMain() func() {
262262
}
263263
if node.File.ShortStatus == "DU" || node.File.ShortStatus == "UD" {
264264
cmdObj := self.c.Git().Diff.DiffCmdObj([]string{"--base", "--", node.GetPath()})
265-
task := types.NewRunPtyTask(cmdObj.GetCmd())
266-
task.Prefix = message + "\n\n"
265+
prefix := message + "\n\n"
267266
if node.File.ShortStatus == "DU" {
268-
task.Prefix += self.c.Tr.MergeConflictIncomingDiff
267+
prefix += self.c.Tr.MergeConflictIncomingDiff
269268
} else {
270-
task.Prefix += self.c.Tr.MergeConflictCurrentDiff
269+
prefix += self.c.Tr.MergeConflictCurrentDiff
271270
}
272-
task.Prefix += "\n\n"
273-
opts.Main.Task = task
271+
prefix += "\n\n"
272+
opts.Main.Task = types.NewRunPtyTaskWithPrefix(cmdObj.GetCmd(), prefix)
274273
} else {
275274
opts.Main.Task = types.NewRenderStringTask(message)
276275
}

pkg/gui/controllers/helpers/diff_helper.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ func (self *DiffHelper) GetUpdateTaskForRenderingCommitsDiff(commit *models.Comm
6161
args = append(args, path)
6262
}
6363
cmdObj := self.c.Git().Diff.DiffCmdObj(args)
64-
task := types.NewRunPtyTask(cmdObj.GetCmd())
65-
task.Prefix = style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName())
66-
return task
64+
prefix := style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName())
65+
return types.NewRunPtyTaskWithPrefix(cmdObj.GetCmd(), prefix)
6766
}
6867

6968
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.c.Modes().Filtering.GetPath())
@@ -79,12 +78,12 @@ func (self *DiffHelper) ExitDiffMode() error {
7978
func (self *DiffHelper) RenderDiff() {
8079
args := self.DiffArgs()
8180
cmdObj := self.c.Git().Diff.DiffCmdObj(args)
82-
task := types.NewRunPtyTask(cmdObj.GetCmd())
83-
task.Prefix = style.FgMagenta.Sprintf(
81+
prefix := style.FgMagenta.Sprintf(
8482
"%s %s\n\n",
8583
self.c.Tr.ShowingGitDiff,
8684
"git diff "+strings.Join(args, " "),
8785
)
86+
task := types.NewRunPtyTaskWithPrefix(cmdObj.GetCmd(), prefix)
8887

8988
self.c.RenderToMainViews(types.RefreshMainOpts{
9089
Pair: self.c.MainViewPairs().Normal,

pkg/gui/types/rendering.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ func (t *RunPtyTask) IsUpdateTask() {}
9494
func NewRunPtyTask(cmd *exec.Cmd) *RunPtyTask {
9595
return &RunPtyTask{Cmd: cmd}
9696
}
97+
98+
func NewRunPtyTaskWithPrefix(cmd *exec.Cmd, prefix string) *RunPtyTask {
99+
return &RunPtyTask{Cmd: cmd, Prefix: prefix}
100+
}

0 commit comments

Comments
 (0)