1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

Add a Click() primitive to the integration test library

This commit is contained in:
Simon Whitaker
2023-08-06 14:55:14 +01:00
parent 579791e7bc
commit ed1547e0cb
16 changed files with 103 additions and 41 deletions

View File

@ -103,8 +103,9 @@ type GuiMutexes struct {
}
type replayedEvents struct {
Keys chan *TcellKeyEventWrapper
Resizes chan *TcellResizeEventWrapper
Keys chan *TcellKeyEventWrapper
Resizes chan *TcellResizeEventWrapper
MouseEvents chan *TcellMouseEventWrapper
}
type RecordingConfig struct {
@ -225,8 +226,9 @@ func NewGui(opts NewGuiOpts) (*Gui, error) {
if opts.PlayRecording {
g.ReplayedEvents = replayedEvents{
Keys: make(chan *TcellKeyEventWrapper),
Resizes: make(chan *TcellResizeEventWrapper),
Keys: make(chan *TcellKeyEventWrapper),
Resizes: make(chan *TcellResizeEventWrapper),
MouseEvents: make(chan *TcellMouseEventWrapper),
}
}

View File

@ -217,6 +217,29 @@ func (wrapper TcellKeyEventWrapper) toTcellEvent() tcell.Event {
return tcell.NewEventKey(wrapper.Key, wrapper.Ch, wrapper.Mod)
}
type TcellMouseEventWrapper struct {
Timestamp int64
X int
Y int
ButtonMask tcell.ButtonMask
ModMask tcell.ModMask
}
func NewTcellMouseEventWrapper(event *tcell.EventMouse, timestamp int64) *TcellMouseEventWrapper {
x, y := event.Position()
return &TcellMouseEventWrapper{
Timestamp: timestamp,
X: x,
Y: y,
ButtonMask: event.Buttons(),
ModMask: event.Modifiers(),
}
}
func (wrapper TcellMouseEventWrapper) toTcellEvent() tcell.Event {
return tcell.NewEventMouse(wrapper.X, wrapper.Y, wrapper.ButtonMask, wrapper.ModMask)
}
type TcellResizeEventWrapper struct {
Timestamp int64
Width int
@ -246,6 +269,8 @@ func (g *Gui) pollEvent() GocuiEvent {
tev = (ev).toTcellEvent()
case ev := <-g.ReplayedEvents.Resizes:
tev = (ev).toTcellEvent()
case ev := <-g.ReplayedEvents.MouseEvents:
tev = (ev).toTcellEvent()
}
} else {
tev = Screen.PollEvent()