mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
support navigating remotes view
This commit is contained in:
@ -355,24 +355,6 @@ func (gui *Gui) onBranchesTabClick(tabIndex int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// gui.refreshStatus is called at the end of this because that's when we can
|
|
||||||
// be sure there is a state.Branches array to pick the current branch from
|
|
||||||
func (gui *Gui) refreshRemotes() error {
|
|
||||||
remotes, err := gui.GitCommand.GetRemotes()
|
|
||||||
if err != nil {
|
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.State.Remotes = remotes
|
|
||||||
|
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
|
||||||
gui.refreshSelectedLine(&gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes))
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleNextBranchesTab(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleNextBranchesTab(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.onBranchesTabClick(
|
return gui.onBranchesTabClick(
|
||||||
utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)),
|
utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)),
|
||||||
|
@ -190,7 +190,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
|
|||||||
Panels: &panelStates{
|
Panels: &panelStates{
|
||||||
Files: &filePanelState{SelectedLine: -1},
|
Files: &filePanelState{SelectedLine: -1},
|
||||||
Branches: &branchPanelState{SelectedLine: 0},
|
Branches: &branchPanelState{SelectedLine: 0},
|
||||||
Remotes: &remotePanelState{SelectedLine: -1},
|
Remotes: &remotePanelState{SelectedLine: 0},
|
||||||
Commits: &commitPanelState{SelectedLine: -1},
|
Commits: &commitPanelState{SelectedLine: -1},
|
||||||
CommitFiles: &commitFilesPanelState{SelectedLine: -1},
|
CommitFiles: &commitFilesPanelState{SelectedLine: -1},
|
||||||
Stash: &stashPanelState{SelectedLine: -1},
|
Stash: &stashPanelState{SelectedLine: -1},
|
||||||
@ -598,22 +598,29 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
type listViewState struct {
|
type listViewState struct {
|
||||||
selectedLine int
|
selectedLine int
|
||||||
lineCount int
|
lineCount int
|
||||||
|
view *gocui.View
|
||||||
|
context string
|
||||||
}
|
}
|
||||||
|
|
||||||
listViews := map[*gocui.View]listViewState{
|
listViews := []listViewState{
|
||||||
filesView: {selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files)},
|
{view: filesView, context: "", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files)},
|
||||||
branchesView: {selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches)},
|
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches)},
|
||||||
commitsView: {selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
|
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
|
||||||
stashView: {selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
|
{view: commitsView, context: "", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
|
||||||
|
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
|
||||||
}
|
}
|
||||||
|
|
||||||
// menu view might not exist so we check to be safe
|
// menu view might not exist so we check to be safe
|
||||||
if menuView, err := gui.g.View("menu"); err == nil {
|
if menuView, err := gui.g.View("menu"); err == nil {
|
||||||
listViews[menuView] = listViewState{selectedLine: gui.State.Panels.Menu.SelectedLine, lineCount: gui.State.MenuItemCount}
|
listViews = append(listViews, listViewState{view: menuView, context: "", selectedLine: gui.State.Panels.Menu.SelectedLine, lineCount: gui.State.MenuItemCount})
|
||||||
}
|
}
|
||||||
for view, state := range listViews {
|
for _, listView := range listViews {
|
||||||
|
// ignore views where the context doesn't match up with the selected line we're trying to focus
|
||||||
|
if listView.context != "" && (listView.view.Context != listView.context) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// check if the selected line is now out of view and if so refocus it
|
// check if the selected line is now out of view and if so refocus it
|
||||||
if err := gui.focusPoint(0, state.selectedLine, state.lineCount, view); err != nil {
|
if err := gui.focusPoint(0, listView.selectedLine, listView.lineCount, listView.view); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,6 +1019,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleBranchesClick,
|
Handler: gui.handleBranchesClick,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ViewName: "branches",
|
||||||
|
Contexts: []string{"remotes"},
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleRemotesClick,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
|
@ -66,6 +66,15 @@ func (gui *Gui) getListViews() []*listView {
|
|||||||
gui: gui,
|
gui: gui,
|
||||||
rendersToMainView: true,
|
rendersToMainView: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
viewName: "branches",
|
||||||
|
context: "remotes",
|
||||||
|
getItemsLength: func() int { return len(gui.State.Remotes) },
|
||||||
|
getSelectedLine: func() *int { return &gui.State.Panels.Remotes.SelectedLine },
|
||||||
|
handleItemSelect: gui.handleRemoteSelect,
|
||||||
|
gui: gui,
|
||||||
|
rendersToMainView: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
viewName: "commits",
|
viewName: "commits",
|
||||||
getItemsLength: func() int { return len(gui.State.Commits) },
|
getItemsLength: func() int { return len(gui.State.Commits) },
|
||||||
|
70
pkg/gui/remotes_panel.go
Normal file
70
pkg/gui/remotes_panel.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// list panel functions
|
||||||
|
|
||||||
|
func (gui *Gui) getSelectedRemote() *commands.Remote {
|
||||||
|
selectedLine := gui.State.Panels.Remotes.SelectedLine
|
||||||
|
if selectedLine == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.State.Remotes[selectedLine]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleRemotesClick(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
itemCount := len(gui.State.Remotes)
|
||||||
|
handleSelect := gui.handleRemoteSelect
|
||||||
|
selectedLine := &gui.State.Panels.Remotes.SelectedLine
|
||||||
|
|
||||||
|
return gui.handleClick(v, itemCount, selectedLine, handleSelect)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleRemoteSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
if gui.popupPanelFocused() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.SplitMainPanel = false
|
||||||
|
|
||||||
|
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.getMainView().Title = "Remote"
|
||||||
|
|
||||||
|
remote := gui.getSelectedRemote()
|
||||||
|
gui.focusPoint(0, gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v)
|
||||||
|
if err := gui.focusPoint(0, gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes), v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.renderString(g, "main", fmt.Sprintf("%s\nUrls:\n%s", utils.ColoredString(remote.Name, color.FgGreen), strings.Join(remote.Urls, "\n")))
|
||||||
|
}
|
||||||
|
|
||||||
|
// gui.refreshStatus is called at the end of this because that's when we can
|
||||||
|
// be sure there is a state.Remotes array to pick the current remote from
|
||||||
|
func (gui *Gui) refreshRemotes() error {
|
||||||
|
remotes, err := gui.GitCommand.GetRemotes()
|
||||||
|
if err != nil {
|
||||||
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Remotes = remotes
|
||||||
|
|
||||||
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
|
gui.refreshSelectedLine(&gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/spkg/bom"
|
"github.com/spkg/bom"
|
||||||
@ -103,7 +104,15 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||||||
case "files":
|
case "files":
|
||||||
return gui.handleFileSelect(g, v)
|
return gui.handleFileSelect(g, v)
|
||||||
case "branches":
|
case "branches":
|
||||||
return gui.handleBranchSelect(g, v)
|
branchesView := gui.getBranchesView()
|
||||||
|
switch branchesView.Context {
|
||||||
|
case "local-branches":
|
||||||
|
return gui.handleBranchSelect(g, v)
|
||||||
|
case "remotes":
|
||||||
|
return gui.handleRemoteSelect(g, v)
|
||||||
|
default:
|
||||||
|
return errors.New("unknown branches panel context: " + branchesView.Context)
|
||||||
|
}
|
||||||
case "commits":
|
case "commits":
|
||||||
return gui.handleCommitSelect(g, v)
|
return gui.handleCommitSelect(g, v)
|
||||||
case "commitFiles":
|
case "commitFiles":
|
||||||
|
Reference in New Issue
Block a user