1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +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

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()
}