1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/extras_panel.go
Jesse Duffield 1dd7307fde 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
2022-03-17 19:13:40 +11:00

85 lines
2.3 KiB
Go

package gui
import (
"io"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
func (gui *Gui) handleCreateExtrasMenuPanel() error {
return gui.c.Menu(popup.CreateMenuOptions{
Title: gui.c.Tr.CommandLog,
Items: []*popup.MenuItem{
{
DisplayString: gui.c.Tr.ToggleShowCommandLog,
OnPress: func() error {
currentContext := gui.currentStaticContext()
if gui.ShowExtrasWindow && currentContext.GetKey() == COMMAND_LOG_CONTEXT_KEY {
if err := gui.returnFromContext(); err != nil {
return err
}
}
show := !gui.ShowExtrasWindow
gui.ShowExtrasWindow = show
gui.c.GetAppState().HideCommandLog = !show
_ = gui.c.SaveAppState()
return nil
},
},
{
DisplayString: gui.c.Tr.FocusCommandLog,
OnPress: gui.handleFocusCommandLog,
},
},
})
}
func (gui *Gui) handleFocusCommandLog() error {
gui.ShowExtrasWindow = true
// TODO: is this necessary? Can't I just call 'return from context'?
gui.State.Contexts.CommandLog.SetParentContext(gui.currentSideContext())
return gui.c.PushContext(gui.State.Contexts.CommandLog)
}
func (gui *Gui) scrollUpExtra() error {
gui.Views.Extras.Autoscroll = false
return gui.scrollUpView(gui.Views.Extras)
}
func (gui *Gui) scrollDownExtra() error {
gui.Views.Extras.Autoscroll = false
if err := gui.scrollDownView(gui.Views.Extras); err != nil {
return err
}
return nil
}
func (gui *Gui) getCmdWriter() io.Writer {
return &prefixWriter{writer: gui.Views.Extras, prefix: style.FgMagenta.Sprintf("\n\n%s\n", gui.c.Tr.GitOutput)}
}
// Ensures that the first write is preceded by writing a prefix.
// This allows us to say 'Git output:' before writing the actual git output.
// We could just write directly to the view in this package before running the command but we already have code in the commands package that writes to the same view beforehand (with the command it's about to run) so things would be out of order.
type prefixWriter struct {
prefix string
prefixWritten bool
writer io.Writer
}
func (self *prefixWriter) Write(p []byte) (n int, err error) {
if !self.prefixWritten {
self.prefixWritten = true
// assuming we can write this prefix in one go
_, err = self.writer.Write([]byte(self.prefix))
if err != nil {
return
}
}
return self.writer.Write(p)
}