1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/popup/fake_popup_handler.go
Jesse Duffield 6b9390409e Use an interface for tasks instead of a concrete struct
By using an interface for tasks we can use a fake implementation in tests with extra methods
2023-07-10 17:12:21 +10:00

55 lines
1.3 KiB
Go

package popup
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type FakePopupHandler struct {
OnErrorMsg func(message string) error
OnConfirm func(opts types.ConfirmOpts) error
OnPrompt func(opts types.PromptOpts) error
}
var _ types.IPopupHandler = &FakePopupHandler{}
func (self *FakePopupHandler) Error(err error) error {
return self.ErrorMsg(err.Error())
}
func (self *FakePopupHandler) ErrorMsg(message string) error {
return self.OnErrorMsg(message)
}
func (self *FakePopupHandler) Alert(title string, message string) error {
panic("not yet implemented")
}
func (self *FakePopupHandler) Confirm(opts types.ConfirmOpts) error {
return self.OnConfirm(opts)
}
func (self *FakePopupHandler) Prompt(opts types.PromptOpts) error {
return self.OnPrompt(opts)
}
func (self *FakePopupHandler) WithLoaderPanel(message string, f func(gocui.Task) error) error {
return f(gocui.NewFakeTask())
}
func (self *FakePopupHandler) WithWaitingStatus(message string, f func(gocui.Task) error) error {
return f(gocui.NewFakeTask())
}
func (self *FakePopupHandler) Menu(opts types.CreateMenuOptions) error {
panic("not yet implemented")
}
func (self *FakePopupHandler) Toast(message string) {
panic("not yet implemented")
}
func (self *FakePopupHandler) GetPromptInput() string {
panic("not yet implemented")
}