mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
First good success
This commit is contained in:
@ -92,8 +92,7 @@ func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string)
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
toWrite := output(re.ReplaceAllString(scanner.Text(), ""))
|
toWrite := output(re.ReplaceAllString(scanner.Text(), ""))
|
||||||
if len(toWrite) > 0 {
|
if len(toWrite) > 0 {
|
||||||
_, err := tty.Write([]byte(toWrite + "\n"))
|
_, _ = tty.Write([]byte(toWrite + "\n"))
|
||||||
logrus.Error(err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -3,6 +3,7 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
@ -51,6 +52,71 @@ func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.renderString(g, "options", message)
|
return gui.renderString(g, "options", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var unamePassMessage = ""
|
||||||
|
var waitForGroup sync.WaitGroup
|
||||||
|
var waitForGroupActie = false
|
||||||
|
|
||||||
|
// waitForPassUname wait for a username or password input from the pushPassUname popup
|
||||||
|
func (gui *Gui) waitForPassUname(g *gocui.Gui, currentView *gocui.View, passOrUname string) string {
|
||||||
|
pushPassUnameView := gui.getPushPassUnameView(g)
|
||||||
|
if passOrUname == "username" {
|
||||||
|
pushPassUnameView.Title = gui.Tr.SLocalize("PushUsername")
|
||||||
|
// pushPassUnameView.Mask = 1
|
||||||
|
} else {
|
||||||
|
pushPassUnameView.Title = gui.Tr.SLocalize("PushPassword")
|
||||||
|
pushPassUnameView.Mask = '*'
|
||||||
|
}
|
||||||
|
g.Update(func(g *gocui.Gui) error {
|
||||||
|
g.SetViewOnTop("pushPassUname")
|
||||||
|
gui.switchFocus(g, currentView, pushPassUnameView)
|
||||||
|
gui.RenderCommitLength()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
waitForGroupActie = true
|
||||||
|
waitForGroup.Add(1)
|
||||||
|
waitForGroup.Wait()
|
||||||
|
|
||||||
|
return unamePassMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handlePushConfirm(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
message := gui.trimmedContent(v)
|
||||||
|
unamePassMessage = message
|
||||||
|
if waitForGroupActie {
|
||||||
|
defer waitForGroup.Done()
|
||||||
|
}
|
||||||
|
gui.refreshFiles(g)
|
||||||
|
v.Clear()
|
||||||
|
v.SetCursor(0, 0)
|
||||||
|
g.SetViewOnBottom("pushPassUname")
|
||||||
|
gui.switchFocus(g, v, gui.getFilesView(g))
|
||||||
|
return gui.refreshCommits(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handlePushClose(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
g.SetViewOnBottom("pushPassUname")
|
||||||
|
unamePassMessage = ""
|
||||||
|
if waitForGroupActie {
|
||||||
|
defer waitForGroup.Done()
|
||||||
|
}
|
||||||
|
return gui.switchFocus(g, v, gui.getFilesView(g))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handlePushFocused(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
if _, err := g.SetViewOnTop("pushPassUname"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
message := gui.Tr.TemplateLocalize(
|
||||||
|
"CloseConfirm",
|
||||||
|
Teml{
|
||||||
|
"keyBindClose": "esc",
|
||||||
|
"keyBindConfirm": "enter",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return gui.renderString(g, "options", message)
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
|
func (gui *Gui) simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
|
||||||
switch {
|
switch {
|
||||||
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
|
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
|
||||||
|
@ -85,6 +85,7 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt
|
|||||||
|
|
||||||
func (gui *Gui) onNewPopupPanel() {
|
func (gui *Gui) onNewPopupPanel() {
|
||||||
gui.g.SetViewOnBottom("commitMessage")
|
gui.g.SetViewOnBottom("commitMessage")
|
||||||
|
gui.g.SetViewOnBottom("pushPassUname")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
|
func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
|
||||||
|
@ -355,22 +355,21 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error {
|
func (gui *Gui) pushWithForceFlag(g *gocui.Gui, currentView *gocui.View, force bool) error {
|
||||||
if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil {
|
if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
branchName := gui.State.Branches[0].Name
|
branchName := gui.State.Branches[0].Name
|
||||||
err := gui.GitCommand.Push(branchName, force, func(passOrUname string) string {
|
err := gui.GitCommand.Push(branchName, force, func(passOrUname string) string {
|
||||||
if passOrUname == "password" {
|
return gui.waitForPassUname(g, currentView, passOrUname)
|
||||||
// TODO: ask for password
|
|
||||||
return "some password"
|
|
||||||
}
|
|
||||||
// TODO: ask for username
|
|
||||||
return "some username"
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = gui.createErrorPanel(gui.g, err.Error())
|
errMessage := err.Error()
|
||||||
|
if errMessage == "exit status 128" {
|
||||||
|
errMessage = gui.Tr.SLocalize("PassUnameWrong")
|
||||||
|
}
|
||||||
|
_ = gui.createErrorPanel(gui.g, errMessage)
|
||||||
} else {
|
} else {
|
||||||
_ = gui.closeConfirmationPrompt(gui.g)
|
_ = gui.closeConfirmationPrompt(gui.g)
|
||||||
_ = gui.refreshCommits(gui.g)
|
_ = gui.refreshCommits(gui.g)
|
||||||
@ -384,10 +383,10 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
|
|||||||
// if we have pullables we'll ask if the user wants to force push
|
// if we have pullables we'll ask if the user wants to force push
|
||||||
_, pullables := gui.GitCommand.UpstreamDifferenceCount()
|
_, pullables := gui.GitCommand.UpstreamDifferenceCount()
|
||||||
if pullables == "?" || pullables == "0" {
|
if pullables == "?" || pullables == "0" {
|
||||||
return gui.pushWithForceFlag(v, false)
|
return gui.pushWithForceFlag(g, v, false)
|
||||||
}
|
}
|
||||||
err := gui.createConfirmationPanel(g, nil, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
err := gui.createConfirmationPanel(g, nil, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
return gui.pushWithForceFlag(v, true)
|
return gui.pushWithForceFlag(g, v, true)
|
||||||
}, nil)
|
}, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,20 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gui.getPushPassUnameView(g) == nil {
|
||||||
|
// doesn't matter where this view starts because it will be hidden
|
||||||
|
if pushPassUnameView, err := g.SetView("pushPassUname", 0, 0, width/2, height/2, 0); err != nil {
|
||||||
|
if err != gocui.ErrUnknownView {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g.SetViewOnBottom("pushPassUname")
|
||||||
|
pushPassUnameView.Title = gui.Tr.SLocalize("PushUsername")
|
||||||
|
pushPassUnameView.FgColor = gocui.ColorWhite
|
||||||
|
pushPassUnameView.Editable = true
|
||||||
|
pushPassUnameView.Editor = gocui.EditorFunc(gui.simpleEditor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil {
|
if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if err != gocui.ErrUnknownView {
|
||||||
return err
|
return err
|
||||||
|
@ -372,6 +372,16 @@ func (gui *Gui) GetKeybindings() []*Binding {
|
|||||||
Key: gocui.KeyEsc,
|
Key: gocui.KeyEsc,
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitClose,
|
Handler: gui.handleCommitClose,
|
||||||
|
}, {
|
||||||
|
ViewName: "pushPassUname",
|
||||||
|
Key: gocui.KeyEnter,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handlePushConfirm,
|
||||||
|
}, {
|
||||||
|
ViewName: "pushPassUname",
|
||||||
|
Key: gocui.KeyEsc,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handlePushClose,
|
||||||
}, {
|
}, {
|
||||||
ViewName: "menu",
|
ViewName: "menu",
|
||||||
Key: gocui.KeyEsc,
|
Key: gocui.KeyEsc,
|
||||||
|
@ -94,6 +94,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
case "commitMessage":
|
case "commitMessage":
|
||||||
return gui.handleCommitFocused(g, v)
|
return gui.handleCommitFocused(g, v)
|
||||||
|
case "pushPassUname":
|
||||||
|
return gui.handlePushFocused(g, v)
|
||||||
case "main":
|
case "main":
|
||||||
// TODO: pull this out into a 'view focused' function
|
// TODO: pull this out into a 'view focused' function
|
||||||
gui.refreshMergePanel(g)
|
gui.refreshMergePanel(g)
|
||||||
@ -288,6 +290,11 @@ func (gui *Gui) getCommitMessageView(g *gocui.Gui) *gocui.View {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) getPushPassUnameView(g *gocui.Gui) *gocui.View {
|
||||||
|
v, _ := g.View("pushPassUname")
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) getBranchesView(g *gocui.Gui) *gocui.View {
|
func (gui *Gui) getBranchesView(g *gocui.Gui) *gocui.View {
|
||||||
v, _ := g.View("branches")
|
v, _ := g.View("branches")
|
||||||
return v
|
return v
|
||||||
@ -304,7 +311,7 @@ func (gui *Gui) currentViewName(g *gocui.Gui) string {
|
|||||||
|
|
||||||
func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error {
|
func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error {
|
||||||
v := g.CurrentView()
|
v := g.CurrentView()
|
||||||
if v.Name() == "commitMessage" || v.Name() == "confirmation" {
|
if v.Name() == "commitMessage" || v.Name() == "pushPassUname" || v.Name() == "confirmation" {
|
||||||
return gui.resizePopupPanel(g, v)
|
return gui.resizePopupPanel(g, v)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user