mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
stop resetting scroll all the time
This commit is contained in:
parent
e7c27b6f4a
commit
d672b7342f
@ -57,13 +57,6 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !alreadySelected {
|
if !alreadySelected {
|
||||||
// TODO: pull into update task interface
|
|
||||||
if err := gui.resetOrigin(gui.Views.Main); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := gui.resetOrigin(gui.Views.Secondary); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
gui.takeOverMergeConflictScrolling()
|
gui.takeOverMergeConflictScrolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ type ListContext struct {
|
|||||||
GetPanelState func() IListPanelState
|
GetPanelState func() IListPanelState
|
||||||
|
|
||||||
Gui *Gui
|
Gui *Gui
|
||||||
ResetMainViewOriginOnFocus bool
|
|
||||||
|
|
||||||
*BasicContext
|
*BasicContext
|
||||||
}
|
}
|
||||||
@ -79,15 +78,6 @@ func (lc *ListContext) HandleFocus() error {
|
|||||||
|
|
||||||
view.FocusPoint(0, lc.GetPanelState().GetSelectedLineIdx())
|
view.FocusPoint(0, lc.GetPanelState().GetSelectedLineIdx())
|
||||||
|
|
||||||
if lc.ResetMainViewOriginOnFocus {
|
|
||||||
if err := lc.Gui.resetOrigin(lc.Gui.Views.Main); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := lc.Gui.resetOrigin(lc.Gui.Views.Secondary); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if lc.Gui.State.Modes.Diffing.Active() {
|
if lc.Gui.State.Modes.Diffing.Active() {
|
||||||
return lc.Gui.renderDiff()
|
return lc.Gui.renderDiff()
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ func (gui *Gui) menuListContext() *ListContext {
|
|||||||
OnFocus: gui.handleMenuSelect,
|
OnFocus: gui.handleMenuSelect,
|
||||||
OnClickSelectedItem: gui.onMenuPress,
|
OnClickSelectedItem: gui.onMenuPress,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: false,
|
|
||||||
|
|
||||||
// no GetDisplayStrings field because we do a custom render on menu creation
|
// no GetDisplayStrings field because we do a custom render on menu creation
|
||||||
}
|
}
|
||||||
@ -38,7 +37,6 @@ func (gui *Gui) filesListContext() *ListContext {
|
|||||||
OnFocus: gui.focusAndSelectFile,
|
OnFocus: gui.focusAndSelectFile,
|
||||||
OnClickSelectedItem: gui.handleFilePress,
|
OnClickSelectedItem: gui.handleFilePress,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: false,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
lines := gui.State.FileManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules)
|
lines := gui.State.FileManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules)
|
||||||
mappedLines := make([][]string, len(lines))
|
mappedLines := make([][]string, len(lines))
|
||||||
@ -67,7 +65,6 @@ func (gui *Gui) branchesListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Branches },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Branches },
|
||||||
OnFocus: gui.handleBranchSelect,
|
OnFocus: gui.handleBranchSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref)
|
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref)
|
||||||
},
|
},
|
||||||
@ -91,7 +88,6 @@ func (gui *Gui) remotesListContext() *ListContext {
|
|||||||
OnFocus: gui.handleRemoteSelect,
|
OnFocus: gui.handleRemoteSelect,
|
||||||
OnClickSelectedItem: gui.handleRemoteEnter,
|
OnClickSelectedItem: gui.handleRemoteEnter,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Modes.Diffing.Ref)
|
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Modes.Diffing.Ref)
|
||||||
},
|
},
|
||||||
@ -114,7 +110,6 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.RemoteBranches },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.RemoteBranches },
|
||||||
OnFocus: gui.handleRemoteBranchSelect,
|
OnFocus: gui.handleRemoteBranchSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Modes.Diffing.Ref)
|
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Modes.Diffing.Ref)
|
||||||
},
|
},
|
||||||
@ -137,7 +132,6 @@ func (gui *Gui) tagsListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Tags },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Tags },
|
||||||
OnFocus: gui.handleTagSelect,
|
OnFocus: gui.handleTagSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Modes.Diffing.Ref)
|
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Modes.Diffing.Ref)
|
||||||
},
|
},
|
||||||
@ -162,7 +156,6 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
|||||||
OnFocus: gui.handleCommitSelect,
|
OnFocus: gui.handleCommitSelect,
|
||||||
OnClickSelectedItem: gui.handleViewCommitFiles,
|
OnClickSelectedItem: gui.handleViewCommitFiles,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetCommitListDisplayStrings(
|
return presentation.GetCommitListDisplayStrings(
|
||||||
gui.State.Commits,
|
gui.State.Commits,
|
||||||
@ -192,7 +185,6 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.ReflogCommits },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.ReflogCommits },
|
||||||
OnFocus: gui.handleReflogCommitSelect,
|
OnFocus: gui.handleReflogCommitSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetReflogCommitListDisplayStrings(
|
return presentation.GetReflogCommitListDisplayStrings(
|
||||||
gui.State.FilteredReflogCommits,
|
gui.State.FilteredReflogCommits,
|
||||||
@ -222,7 +214,6 @@ func (gui *Gui) subCommitsListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.SubCommits },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.SubCommits },
|
||||||
OnFocus: gui.handleSubCommitSelect,
|
OnFocus: gui.handleSubCommitSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetCommitListDisplayStrings(
|
return presentation.GetCommitListDisplayStrings(
|
||||||
gui.State.SubCommits,
|
gui.State.SubCommits,
|
||||||
@ -251,7 +242,6 @@ func (gui *Gui) stashListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Stash },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Stash },
|
||||||
OnFocus: gui.handleStashEntrySelect,
|
OnFocus: gui.handleStashEntrySelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Modes.Diffing.Ref)
|
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Modes.Diffing.Ref)
|
||||||
},
|
},
|
||||||
@ -274,7 +264,6 @@ func (gui *Gui) commitFilesListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.CommitFiles },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.CommitFiles },
|
||||||
OnFocus: gui.handleCommitFileSelect,
|
OnFocus: gui.handleCommitFileSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
if gui.State.CommitFileManager.GetItemsLength() == 0 {
|
if gui.State.CommitFileManager.GetItemsLength() == 0 {
|
||||||
return [][]string{{style.FgRed.Sprint("(none)")}}
|
return [][]string{{style.FgRed.Sprint("(none)")}}
|
||||||
@ -307,7 +296,6 @@ func (gui *Gui) submodulesListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Submodules },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Submodules },
|
||||||
OnFocus: gui.handleSubmoduleSelect,
|
OnFocus: gui.handleSubmoduleSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: true,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetSubmoduleListDisplayStrings(gui.State.Submodules)
|
return presentation.GetSubmoduleListDisplayStrings(gui.State.Submodules)
|
||||||
},
|
},
|
||||||
@ -330,7 +318,6 @@ func (gui *Gui) suggestionsListContext() *ListContext {
|
|||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Suggestions },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Suggestions },
|
||||||
OnFocus: func() error { return nil },
|
OnFocus: func() error { return nil },
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
ResetMainViewOriginOnFocus: false,
|
|
||||||
GetDisplayStrings: func() [][]string {
|
GetDisplayStrings: func() [][]string {
|
||||||
return presentation.GetSuggestionListDisplayStrings(gui.State.Suggestions)
|
return presentation.GetSuggestionListDisplayStrings(gui.State.Suggestions)
|
||||||
},
|
},
|
||||||
|
@ -29,7 +29,6 @@ type TaskKind int
|
|||||||
const (
|
const (
|
||||||
RENDER_STRING TaskKind = iota
|
RENDER_STRING TaskKind = iota
|
||||||
RENDER_STRING_WITHOUT_SCROLL
|
RENDER_STRING_WITHOUT_SCROLL
|
||||||
RUN_FUNCTION
|
|
||||||
RUN_COMMAND
|
RUN_COMMAND
|
||||||
RUN_PTY
|
RUN_PTY
|
||||||
)
|
)
|
||||||
@ -97,19 +96,6 @@ func NewRunPtyTask(cmd *exec.Cmd) *runPtyTask {
|
|||||||
// return &runPtyTask{cmd: cmd, prefix: prefix}
|
// return &runPtyTask{cmd: cmd, prefix: prefix}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
type runFunctionTask struct {
|
|
||||||
f func(chan struct{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *runFunctionTask) GetKind() TaskKind {
|
|
||||||
return RUN_FUNCTION
|
|
||||||
}
|
|
||||||
|
|
||||||
// currently unused
|
|
||||||
// func (gui *Gui) createRunFunctionTask(f func(chan struct{}) error) *runFunctionTask {
|
|
||||||
// return &runFunctionTask{f: f}
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
||||||
switch task.GetKind() {
|
switch task.GetKind() {
|
||||||
case RENDER_STRING:
|
case RENDER_STRING:
|
||||||
@ -120,10 +106,6 @@ func (gui *Gui) runTaskForView(view *gocui.View, task updateTask) error {
|
|||||||
specificTask := task.(*renderStringWithoutScrollTask)
|
specificTask := task.(*renderStringWithoutScrollTask)
|
||||||
return gui.newStringTaskWithoutScroll(view, specificTask.str)
|
return gui.newStringTaskWithoutScroll(view, specificTask.str)
|
||||||
|
|
||||||
case RUN_FUNCTION:
|
|
||||||
specificTask := task.(*runFunctionTask)
|
|
||||||
return gui.newTask(view, specificTask.f)
|
|
||||||
|
|
||||||
case RUN_COMMAND:
|
case RUN_COMMAND:
|
||||||
specificTask := task.(*runCommandTask)
|
specificTask := task.(*runCommandTask)
|
||||||
return gui.newCmdTask(view, specificTask.cmd, specificTask.prefix)
|
return gui.newCmdTask(view, specificTask.cmd, specificTask.prefix)
|
||||||
|
@ -5,6 +5,7 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
@ -40,6 +41,8 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
|
|||||||
return gui.newCmdTask(view, cmd, prefix)
|
return gui.newCmdTask(view, cmd, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmdStr := strings.Join(cmd.Args, " ")
|
||||||
|
|
||||||
cmd.Env = append(cmd.Env, "GIT_PAGER="+pager)
|
cmd.Env = append(cmd.Env, "GIT_PAGER="+pager)
|
||||||
|
|
||||||
_, height := view.Size()
|
_, height := view.Size()
|
||||||
@ -62,7 +65,7 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := manager.NewTask(manager.NewCmdTask(ptmx, cmd, prefix, height+oy+10, onClose)); err != nil {
|
if err := manager.NewTask(manager.NewCmdTask(ptmx, cmd, prefix, height+oy+10, onClose), cmdStr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
|
func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
|
||||||
|
cmdStr := strings.Join(cmd.Args, " ")
|
||||||
gui.Log.WithField(
|
gui.Log.WithField(
|
||||||
"command",
|
"command",
|
||||||
strings.Join(cmd.Args, " "),
|
cmdStr,
|
||||||
).Debug("RunCommand")
|
).Debug("RunCommand")
|
||||||
|
|
||||||
_, height := view.Size()
|
_, height := view.Size()
|
||||||
@ -29,17 +30,7 @@ func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := manager.NewTask(manager.NewCmdTask(r, cmd, prefix, height+oy+10, nil)); err != nil {
|
if err := manager.NewTask(manager.NewCmdTask(r, cmd, prefix, height+oy+10, nil), cmdStr); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) newTask(view *gocui.View, f func(chan struct{}) error) error {
|
|
||||||
manager := gui.getManager(view)
|
|
||||||
|
|
||||||
if err := manager.NewTask(f); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +38,16 @@ func (gui *Gui) newTask(view *gocui.View, f func(chan struct{}) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) newStringTask(view *gocui.View, str string) error {
|
func (gui *Gui) newStringTask(view *gocui.View, str string) error {
|
||||||
|
// using str so that if rendering the exact same thing we don't reset the origin
|
||||||
|
return gui.newStringTaskWithKey(view, str, str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) newStringTaskWithoutScroll(view *gocui.View, str string) error {
|
||||||
|
// using empty key so that on subsequent calls we won't reset the view's origin
|
||||||
|
return gui.newStringTaskWithKey(view, str, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) error {
|
||||||
manager := gui.getManager(view)
|
manager := gui.getManager(view)
|
||||||
|
|
||||||
f := func(stop chan struct{}) error {
|
f := func(stop chan struct{}) error {
|
||||||
@ -54,22 +55,7 @@ func (gui *Gui) newStringTask(view *gocui.View, str string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := manager.NewTask(f); err != nil {
|
if err := manager.NewTask(f, key); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) newStringTaskWithoutScroll(view *gocui.View, str string) error {
|
|
||||||
manager := gui.getManager(view)
|
|
||||||
|
|
||||||
f := func(stop chan struct{}) error {
|
|
||||||
gui.setViewContent(view, str)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := manager.NewTask(f); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,8 +83,29 @@ func (gui *Gui) getManager(view *gocui.View) *tasks.ViewBufferManager {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
func() {
|
func() {
|
||||||
|
// Need to check if the content of the view is well past the origin.
|
||||||
|
// It would be better to use .ViewLinesHeight here (given it considers
|
||||||
|
// wrapping) but when this function is called they haven't been written to yet.
|
||||||
|
linesHeight := view.LinesHeight()
|
||||||
|
_, height := view.Size()
|
||||||
|
_, originY := view.Origin()
|
||||||
|
if linesHeight < originY {
|
||||||
|
newOriginY := linesHeight - height
|
||||||
|
if newOriginY < 0 {
|
||||||
|
newOriginY = 0
|
||||||
|
}
|
||||||
|
err := view.SetOrigin(0, newOriginY)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
view.FlushStaleCells()
|
view.FlushStaleCells()
|
||||||
},
|
},
|
||||||
|
func() {
|
||||||
|
_ = view.SetOrigin(0, 0)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
gui.viewBufferManagerMap[view.Name()] = manager
|
gui.viewBufferManagerMap[view.Name()] = manager
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,36 @@ type ViewBufferManager struct {
|
|||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
newTaskId int
|
newTaskId int
|
||||||
readLines chan int
|
readLines chan int
|
||||||
|
taskKey string
|
||||||
|
onNewKey func()
|
||||||
|
|
||||||
// beforeStart is the function that is called before starting a new task
|
// beforeStart is the function that is called before starting a new task
|
||||||
beforeStart func()
|
beforeStart func()
|
||||||
refreshView func()
|
refreshView func()
|
||||||
flushStaleCells func()
|
onEndOfInput func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewViewBufferManager(log *logrus.Entry, writer io.Writer, beforeStart func(), refreshView func(), flushStaleCells func()) *ViewBufferManager {
|
func (m *ViewBufferManager) GetTaskKey() string {
|
||||||
return &ViewBufferManager{Log: log, writer: writer, beforeStart: beforeStart, refreshView: refreshView, flushStaleCells: flushStaleCells, readLines: make(chan int, 1024)}
|
return m.taskKey
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewViewBufferManager(
|
||||||
|
log *logrus.Entry,
|
||||||
|
writer io.Writer,
|
||||||
|
beforeStart func(),
|
||||||
|
refreshView func(),
|
||||||
|
onEndOfInput func(),
|
||||||
|
onNewKey func(),
|
||||||
|
) *ViewBufferManager {
|
||||||
|
return &ViewBufferManager{
|
||||||
|
Log: log,
|
||||||
|
writer: writer,
|
||||||
|
beforeStart: beforeStart,
|
||||||
|
refreshView: refreshView,
|
||||||
|
onEndOfInput: onEndOfInput,
|
||||||
|
readLines: make(chan int, 1024),
|
||||||
|
onNewKey: onNewKey,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ViewBufferManager) ReadLines(n int) {
|
func (m *ViewBufferManager) ReadLines(n int) {
|
||||||
@ -117,11 +138,11 @@ func (m *ViewBufferManager) NewCmdTask(r io.Reader, cmd *exec.Cmd, prefix string
|
|||||||
if !ok {
|
if !ok {
|
||||||
// if we're here then there's nothing left to scan from the source
|
// if we're here then there's nothing left to scan from the source
|
||||||
// so we're at the EOF and can flush the stale content
|
// so we're at the EOF and can flush the stale content
|
||||||
m.flushStaleCells()
|
m.onEndOfInput()
|
||||||
m.refreshView()
|
m.refreshView()
|
||||||
break outer
|
break outer
|
||||||
}
|
}
|
||||||
_, _ = m.writer.Write(append(scanner.Bytes(), []byte("\n")...))
|
_, _ = m.writer.Write(append(scanner.Bytes(), '\n'))
|
||||||
}
|
}
|
||||||
m.refreshView()
|
m.refreshView()
|
||||||
case <-stop:
|
case <-stop:
|
||||||
@ -179,11 +200,17 @@ func (t *ViewBufferManager) Close() {
|
|||||||
// 1) command based, where the manager can be asked to read more lines, but the command can be killed
|
// 1) command based, where the manager can be asked to read more lines, but the command can be killed
|
||||||
// 2) string based, where the manager can also be asked to read more lines
|
// 2) string based, where the manager can also be asked to read more lines
|
||||||
|
|
||||||
func (m *ViewBufferManager) NewTask(f func(stop chan struct{}) error) error {
|
func (m *ViewBufferManager) NewTask(f func(stop chan struct{}) error, key string) error {
|
||||||
go utils.Safe(func() {
|
go utils.Safe(func() {
|
||||||
m.taskIDMutex.Lock()
|
m.taskIDMutex.Lock()
|
||||||
m.newTaskId++
|
m.newTaskId++
|
||||||
taskID := m.newTaskId
|
taskID := m.newTaskId
|
||||||
|
|
||||||
|
if m.GetTaskKey() != key && m.onNewKey != nil {
|
||||||
|
m.onNewKey()
|
||||||
|
}
|
||||||
|
m.taskKey = key
|
||||||
|
|
||||||
m.taskIDMutex.Unlock()
|
m.taskIDMutex.Unlock()
|
||||||
|
|
||||||
m.waitingMutex.Lock()
|
m.waitingMutex.Lock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user