1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-10-17 20:31:19 +03:00
Files
lazygit/pkg/integration/components/popup.go
Stefan Haller 5a630aeda1 Refactor: add a separate Prompt view
So far, confirmations and prompts were handled by the same view, context, and
controller, with a bunch of conditional code based on whether the view is
editable. This was more or less ok so far, since it does save a little bit of
code duplication; however, now we need separate views, because we don't have
dynamic keybindings, but we want to map "confirm" to different keys in
confirmations (the "universal.confirm" user config) and prompts (hard-coded to
enter, because it doesn't make sense to customize it there).

It also allows us to get rid of the conditional code, which is a nice benefit;
and the code duplication is actually not *that* bad.
2025-09-05 10:42:03 +02:00

89 lines
2.3 KiB
Go

package components
type Popup struct {
t *TestDriver
}
func (self *Popup) Confirmation() *ConfirmationDriver {
self.inConfirm()
return &ConfirmationDriver{t: self.t}
}
func (self *Popup) inConfirm() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation", "Expected confirmation popup to be focused"
})
}
func (self *Popup) Prompt() *PromptDriver {
self.inPrompt()
return &PromptDriver{t: self.t}
}
func (self *Popup) inPrompt() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "prompt", "Expected prompt popup to be focused"
})
}
func (self *Popup) Alert() *AlertDriver {
self.inAlert()
return &AlertDriver{t: self.t}
}
func (self *AlertDriver) Tap(f func()) *AlertDriver {
self.getViewDriver().Tap(f)
return self
}
func (self *Popup) inAlert() {
// basically the same thing as a confirmation popup with the current implementation
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation", "Expected alert popup to be focused"
})
}
func (self *Popup) Menu() *MenuDriver {
self.inMenu()
return &MenuDriver{t: self.t}
}
func (self *Popup) inMenu() {
self.t.assertWithRetries(func() (bool, string) {
return self.t.gui.CurrentContext().GetView().Name() == "menu", "Expected popup menu to be focused"
})
}
func (self *Popup) CommitMessagePanel() *CommitMessagePanelDriver {
self.inCommitMessagePanel()
return &CommitMessagePanelDriver{t: self.t}
}
func (self *Popup) CommitDescriptionPanel() *CommitMessagePanelDriver {
self.inCommitDescriptionPanel()
return &CommitMessagePanelDriver{t: self.t}
}
func (self *Popup) inCommitMessagePanel() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "commitMessage", "Expected commit message panel to be focused"
})
}
func (self *Popup) inCommitDescriptionPanel() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "commitDescription", "Expected commit description panel to be focused"
})
}