mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
start moving commit panel handlers into controller
more and more move rebase commit refreshing into existing abstraction and more and more WIP and more handling clicks properly fix merge conflicts update cheatsheet lots more preparation to start moving things into controllers WIP better typing expand on remotes controller moving more code into controllers
This commit is contained in:
@ -54,7 +54,7 @@ func (gui *Gui) resolveTemplate(templateStr string, promptResponses []string) (s
|
||||
SelectedCommitFile: gui.getSelectedCommitFile(),
|
||||
SelectedCommitFilePath: gui.getSelectedCommitFilePath(),
|
||||
SelectedSubCommit: gui.getSelectedSubCommit(),
|
||||
CheckedOutBranch: gui.currentBranch(),
|
||||
CheckedOutBranch: gui.getCheckedOutBranch(),
|
||||
PromptResponses: promptResponses,
|
||||
}
|
||||
|
||||
@ -64,15 +64,15 @@ func (gui *Gui) resolveTemplate(templateStr string, promptResponses []string) (s
|
||||
func (gui *Gui) inputPrompt(prompt config.CustomCommandPrompt, promptResponses []string, responseIdx int, wrappedF func() error) error {
|
||||
title, err := gui.resolveTemplate(prompt.Title, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
initialValue, err := gui.resolveTemplate(prompt.InitialValue, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
return gui.PopupHandler.Prompt(popup.PromptOpts{
|
||||
return gui.c.Prompt(popup.PromptOpts{
|
||||
Title: title,
|
||||
InitialContent: initialValue,
|
||||
HandleConfirm: func(str string) error {
|
||||
@ -95,17 +95,17 @@ func (gui *Gui) menuPrompt(prompt config.CustomCommandPrompt, promptResponses []
|
||||
}
|
||||
name, err := gui.resolveTemplate(nameTemplate, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
description, err := gui.resolveTemplate(option.Description, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
value, err := gui.resolveTemplate(option.Value, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
menuItems[i] = &popup.MenuItem{
|
||||
@ -119,30 +119,30 @@ func (gui *Gui) menuPrompt(prompt config.CustomCommandPrompt, promptResponses []
|
||||
|
||||
title, err := gui.resolveTemplate(prompt.Title, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
return gui.PopupHandler.Menu(popup.CreateMenuOptions{Title: title, Items: menuItems})
|
||||
return gui.c.Menu(popup.CreateMenuOptions{Title: title, Items: menuItems})
|
||||
}
|
||||
|
||||
func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, labelFormat string) ([]commandMenuEntry, error) {
|
||||
reg, err := regexp.Compile(filter)
|
||||
if err != nil {
|
||||
return nil, gui.PopupHandler.Error(errors.New("unable to parse filter regex, error: " + err.Error()))
|
||||
return nil, gui.c.Error(errors.New("unable to parse filter regex, error: " + err.Error()))
|
||||
}
|
||||
|
||||
buff := bytes.NewBuffer(nil)
|
||||
|
||||
valueTemp, err := template.New("format").Parse(valueFormat)
|
||||
if err != nil {
|
||||
return nil, gui.PopupHandler.Error(errors.New("unable to parse value format, error: " + err.Error()))
|
||||
return nil, gui.c.Error(errors.New("unable to parse value format, error: " + err.Error()))
|
||||
}
|
||||
|
||||
colorFuncMap := style.TemplateFuncMapAddColors(template.FuncMap{})
|
||||
|
||||
descTemp, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat)
|
||||
if err != nil {
|
||||
return nil, gui.PopupHandler.Error(errors.New("unable to parse label format, error: " + err.Error()))
|
||||
return nil, gui.c.Error(errors.New("unable to parse label format, error: " + err.Error()))
|
||||
}
|
||||
|
||||
candidates := []commandMenuEntry{}
|
||||
@ -167,7 +167,7 @@ func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, label
|
||||
|
||||
err = valueTemp.Execute(buff, tmplData)
|
||||
if err != nil {
|
||||
return candidates, gui.PopupHandler.Error(err)
|
||||
return candidates, gui.c.Error(err)
|
||||
}
|
||||
entry := commandMenuEntry{
|
||||
value: strings.TrimSpace(buff.String()),
|
||||
@ -177,7 +177,7 @@ func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, label
|
||||
buff.Reset()
|
||||
err = descTemp.Execute(buff, tmplData)
|
||||
if err != nil {
|
||||
return candidates, gui.PopupHandler.Error(err)
|
||||
return candidates, gui.c.Error(err)
|
||||
}
|
||||
entry.label = strings.TrimSpace(buff.String())
|
||||
} else {
|
||||
@ -195,25 +195,25 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR
|
||||
// Collect cmd to run from config
|
||||
cmdStr, err := gui.resolveTemplate(prompt.Command, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
// Collect Filter regexp
|
||||
filter, err := gui.resolveTemplate(prompt.Filter, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
// Run and save output
|
||||
message, err := gui.Git.Custom.RunWithOutput(cmdStr)
|
||||
message, err := gui.git.Custom.RunWithOutput(cmdStr)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
// Need to make a menu out of what the cmd has displayed
|
||||
candidates, err := gui.GenerateMenuCandidates(message, filter, prompt.ValueFormat, prompt.LabelFormat)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
menuItems := make([]*popup.MenuItem, len(candidates))
|
||||
@ -230,10 +230,10 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR
|
||||
|
||||
title, err := gui.resolveTemplate(prompt.Title, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
return gui.PopupHandler.Menu(popup.CreateMenuOptions{Title: title, Items: menuItems})
|
||||
return gui.c.Menu(popup.CreateMenuOptions{Title: title, Items: menuItems})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand) func() error {
|
||||
@ -243,7 +243,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||
f := func() error {
|
||||
cmdStr, err := gui.resolveTemplate(customCommand.Command, promptResponses)
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
if customCommand.Subprocess {
|
||||
@ -252,19 +252,19 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||
|
||||
loadingText := customCommand.LoadingText
|
||||
if loadingText == "" {
|
||||
loadingText = gui.Tr.LcRunningCustomCommandStatus
|
||||
loadingText = gui.c.Tr.LcRunningCustomCommandStatus
|
||||
}
|
||||
return gui.PopupHandler.WithWaitingStatus(loadingText, func() error {
|
||||
gui.logAction(gui.Tr.Actions.CustomCommand)
|
||||
return gui.c.WithWaitingStatus(loadingText, func() error {
|
||||
gui.c.LogAction(gui.c.Tr.Actions.CustomCommand)
|
||||
cmdObj := gui.OSCommand.Cmd.NewShell(cmdStr)
|
||||
if customCommand.Stream {
|
||||
cmdObj.StreamOutput()
|
||||
}
|
||||
err := cmdObj.Run()
|
||||
if err != nil {
|
||||
return gui.PopupHandler.Error(err)
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
return gui.refreshSidePanels(types.RefreshOptions{})
|
||||
return gui.c.Refresh(types.RefreshOptions{})
|
||||
})
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||
return gui.menuPromptFromCommand(prompt, promptResponses, idx, wrappedF)
|
||||
}
|
||||
default:
|
||||
return gui.PopupHandler.ErrorMsg("custom command prompt must have a type of 'input', 'menu' or 'menuFromCommand'")
|
||||
return gui.c.ErrorMsg("custom command prompt must have a type of 'input', 'menu' or 'menuFromCommand'")
|
||||
}
|
||||
|
||||
}
|
||||
@ -304,7 +304,7 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||
|
||||
func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
|
||||
bindings := []*types.Binding{}
|
||||
customCommands := gui.UserConfig.CustomCommands
|
||||
customCommands := gui.c.UserConfig.CustomCommands
|
||||
|
||||
for _, customCommand := range customCommands {
|
||||
var viewName string
|
||||
@ -315,11 +315,11 @@ func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
|
||||
case "":
|
||||
log.Fatalf("Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s", customCommand.Key, customCommand.Command)
|
||||
default:
|
||||
context, ok := gui.contextForContextKey(ContextKey(customCommand.Context))
|
||||
context, ok := gui.contextForContextKey(types.ContextKey(customCommand.Context))
|
||||
// stupid golang making me build an array of strings for this.
|
||||
allContextKeyStrings := make([]string, len(allContextKeys))
|
||||
for i := range allContextKeys {
|
||||
allContextKeyStrings[i] = string(allContextKeys[i])
|
||||
allContextKeyStrings := make([]string, len(AllContextKeys))
|
||||
for i := range AllContextKeys {
|
||||
allContextKeyStrings[i] = string(AllContextKeys[i])
|
||||
}
|
||||
if !ok {
|
||||
log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeyStrings, ", "))
|
||||
|
Reference in New Issue
Block a user