mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
lots of changes
This commit is contained in:
@ -1,10 +1,7 @@
|
||||
package custom_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
@ -19,14 +16,11 @@ type Client struct {
|
||||
|
||||
func NewClient(
|
||||
c *helpers.HelperCommon,
|
||||
os *oscommands.OSCommand,
|
||||
git *commands.GitCommand,
|
||||
contexts *context.ContextTree,
|
||||
helpers *helpers.Helpers,
|
||||
) *Client {
|
||||
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
|
||||
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
|
||||
keybindingCreator := NewKeybindingCreator(contexts)
|
||||
sessionStateLoader := NewSessionStateLoader(c, helpers.Refs)
|
||||
handlerCreator := NewHandlerCreator(c, sessionStateLoader)
|
||||
keybindingCreator := NewKeybindingCreator(c)
|
||||
customCommands := c.UserConfig.CustomCommands
|
||||
|
||||
return &Client{
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/jesseduffield/generics/slices"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
@ -17,8 +15,6 @@ import (
|
||||
// takes a custom command and returns a function that will be called when the corresponding user-defined keybinding is pressed
|
||||
type HandlerCreator struct {
|
||||
c *helpers.HelperCommon
|
||||
os *oscommands.OSCommand
|
||||
git *commands.GitCommand
|
||||
sessionStateLoader *SessionStateLoader
|
||||
resolver *Resolver
|
||||
menuGenerator *MenuGenerator
|
||||
@ -26,8 +22,6 @@ type HandlerCreator struct {
|
||||
|
||||
func NewHandlerCreator(
|
||||
c *helpers.HelperCommon,
|
||||
os *oscommands.OSCommand,
|
||||
git *commands.GitCommand,
|
||||
sessionStateLoader *SessionStateLoader,
|
||||
) *HandlerCreator {
|
||||
resolver := NewResolver(c.Common)
|
||||
@ -35,8 +29,6 @@ func NewHandlerCreator(
|
||||
|
||||
return &HandlerCreator{
|
||||
c: c,
|
||||
os: os,
|
||||
git: git,
|
||||
sessionStateLoader: sessionStateLoader,
|
||||
resolver: resolver,
|
||||
menuGenerator: menuGenerator,
|
||||
@ -144,7 +136,7 @@ func (self *HandlerCreator) confirmPrompt(prompt *config.CustomCommandPrompt, ha
|
||||
|
||||
func (self *HandlerCreator) menuPromptFromCommand(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
|
||||
// Run and save output
|
||||
message, err := self.git.Custom.RunWithOutput(prompt.Command)
|
||||
message, err := self.c.Git().Custom.RunWithOutput(prompt.Command)
|
||||
if err != nil {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
@ -181,7 +173,7 @@ func (self *HandlerCreator) getResolveTemplateFn(form map[string]string, promptR
|
||||
}
|
||||
|
||||
funcs := template.FuncMap{
|
||||
"quote": self.os.Quote,
|
||||
"quote": self.c.OS().Quote,
|
||||
}
|
||||
|
||||
return func(templateStr string) (string, error) { return utils.ResolveTemplate(templateStr, objects, funcs) }
|
||||
@ -194,7 +186,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
|
||||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
cmdObj := self.os.Cmd.NewShell(cmdStr)
|
||||
cmdObj := self.c.OS().Cmd.NewShell(cmdStr)
|
||||
|
||||
if customCommand.Subprocess {
|
||||
return self.c.RunSubprocessAndRefresh(cmdObj)
|
||||
|
@ -8,18 +8,19 @@ import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
|
||||
type KeybindingCreator struct {
|
||||
contexts *context.ContextTree
|
||||
c *helpers.HelperCommon
|
||||
}
|
||||
|
||||
func NewKeybindingCreator(contexts *context.ContextTree) *KeybindingCreator {
|
||||
func NewKeybindingCreator(c *helpers.HelperCommon) *KeybindingCreator {
|
||||
return &KeybindingCreator{
|
||||
contexts: contexts,
|
||||
c: c,
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ func (self *KeybindingCreator) getViewNameAndContexts(customCommand config.Custo
|
||||
}
|
||||
|
||||
func (self *KeybindingCreator) contextForContextKey(contextKey types.ContextKey) (types.Context, bool) {
|
||||
for _, context := range self.contexts.Flatten() {
|
||||
for _, context := range self.c.Contexts().Flatten() {
|
||||
if context.GetKey() == contextKey {
|
||||
return context, true
|
||||
}
|
||||
|
@ -2,21 +2,21 @@ package custom_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
)
|
||||
|
||||
// loads the session state at the time that a custom command is invoked, for use
|
||||
// in the custom command's template strings
|
||||
type SessionStateLoader struct {
|
||||
contexts *context.ContextTree
|
||||
helpers *helpers.Helpers
|
||||
c *helpers.HelperCommon
|
||||
helpers *helpers.Helpers
|
||||
refsHelper *helpers.RefsHelper
|
||||
}
|
||||
|
||||
func NewSessionStateLoader(contexts *context.ContextTree, helpers *helpers.Helpers) *SessionStateLoader {
|
||||
func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelper) *SessionStateLoader {
|
||||
return &SessionStateLoader{
|
||||
contexts: contexts,
|
||||
helpers: helpers,
|
||||
c: c,
|
||||
refsHelper: refsHelper,
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,18 +39,18 @@ type SessionState struct {
|
||||
|
||||
func (self *SessionStateLoader) call() *SessionState {
|
||||
return &SessionState{
|
||||
SelectedFile: self.contexts.Files.GetSelectedFile(),
|
||||
SelectedPath: self.contexts.Files.GetSelectedPath(),
|
||||
SelectedLocalCommit: self.contexts.LocalCommits.GetSelected(),
|
||||
SelectedReflogCommit: self.contexts.ReflogCommits.GetSelected(),
|
||||
SelectedLocalBranch: self.contexts.Branches.GetSelected(),
|
||||
SelectedRemoteBranch: self.contexts.RemoteBranches.GetSelected(),
|
||||
SelectedRemote: self.contexts.Remotes.GetSelected(),
|
||||
SelectedTag: self.contexts.Tags.GetSelected(),
|
||||
SelectedStashEntry: self.contexts.Stash.GetSelected(),
|
||||
SelectedCommitFile: self.contexts.CommitFiles.GetSelectedFile(),
|
||||
SelectedCommitFilePath: self.contexts.CommitFiles.GetSelectedPath(),
|
||||
SelectedSubCommit: self.contexts.SubCommits.GetSelected(),
|
||||
CheckedOutBranch: self.helpers.Refs.GetCheckedOutRef(),
|
||||
SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
|
||||
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
|
||||
SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(),
|
||||
SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(),
|
||||
SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
|
||||
SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
|
||||
SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
|
||||
SelectedTag: self.c.Contexts().Tags.GetSelected(),
|
||||
SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
|
||||
SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
|
||||
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
|
||||
SelectedSubCommit: self.c.Contexts().SubCommits.GetSelected(),
|
||||
CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user