1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00

show snapshot of lazygit when test fails for easier investigation

This commit is contained in:
Jesse Duffield 2023-02-19 14:49:19 +11:00
parent b5e325b0a4
commit a51f64814c
5 changed files with 40 additions and 5 deletions

2
go.mod
View File

@ -18,7 +18,7 @@ require (
github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
github.com/jesseduffield/gocui v0.3.1-0.20230217232659-7a98151b05c3
github.com/jesseduffield/gocui v0.3.1-0.20230219034834-06a1f1e95da5
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e

4
go.sum
View File

@ -72,8 +72,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE=
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
github.com/jesseduffield/gocui v0.3.1-0.20230217232659-7a98151b05c3 h1:dNhaHQ5aK/j0zSUM7lqCxusQXVw84GyEpJ2xOm9LdUc=
github.com/jesseduffield/gocui v0.3.1-0.20230217232659-7a98151b05c3/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/gocui v0.3.1-0.20230219034834-06a1f1e95da5 h1:6mrOZa9I1bol14HhVK0tl4w9xvvGKLWPmShPRey1Lxg=
github.com/jesseduffield/gocui v0.3.1-0.20230219034834-06a1f1e95da5/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=

View File

@ -50,10 +50,18 @@ func (self *GuiDriver) CurrentContext() types.Context {
}
func (self *GuiDriver) Fail(message string) {
currentView := self.gui.g.CurrentView()
fullMessage := fmt.Sprintf(
"%s\nFinal Lazygit state:\n%s\nUpon failure, focused view was '%s'.\nLog:\n%s", message,
self.gui.g.Snapshot(),
currentView.Name(),
strings.Join(self.gui.CmdLog, "\n"),
)
self.gui.g.Close()
// need to give the gui time to close
time.Sleep(time.Millisecond * 100)
panic(fmt.Sprintf("%s\nLog:\n%s", message, strings.Join(self.gui.CmdLog, "\n")))
panic(fullMessage)
}
// logs to the normal place that you log to i.e. viewable with `lazygit --logs`

View File

@ -1555,3 +1555,30 @@ func (g *Gui) matchView(v *View, kb *keybinding) bool {
}
return true
}
// returns a string representation of the current state of the gui, character-for-character
func (g *Gui) Snapshot() string {
if g.screen == nil {
return "<no screen rendered>"
}
width, height := g.screen.Size()
builder := &strings.Builder{}
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
char, _, _, charWidth := g.screen.GetContent(x, y)
if charWidth == 0 {
continue
}
builder.WriteRune(char)
if charWidth > 1 {
x += charWidth - 1
}
}
builder.WriteRune('\n')
}
return builder.String()
}

2
vendor/modules.txt vendored
View File

@ -172,7 +172,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem
github.com/jesseduffield/go-git/v5/utils/merkletrie/index
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
# github.com/jesseduffield/gocui v0.3.1-0.20230217232659-7a98151b05c3
# github.com/jesseduffield/gocui v0.3.1-0.20230219034834-06a1f1e95da5
## explicit; go 1.12
github.com/jesseduffield/gocui
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10