Skip to content

Commit

Permalink
refactor(input): rename types and consts
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jun 24, 2024
1 parent cf2cca7 commit ba77b10
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 483 deletions.
4 changes: 2 additions & 2 deletions input/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *Driver) readEvents() (e []Event, err error) {
// Lookup table first
if bytes.HasPrefix(buf, []byte{'\x1b'}) {
if k, ok := d.table[string(buf)]; ok {
e = append(e, KeyDownEvent(k))
e = append(e, KeyPressEvent(k))
return
}
}
Expand All @@ -96,7 +96,7 @@ func (d *Driver) readEvents() (e []Event, err error) {
case UnknownCsiEvent, UnknownSs3Event, UnknownEvent:
// If the sequence is not recognized by the parser, try looking it up.
if k, ok := d.table[string(buf[i:i+nb])]; ok {
ev = KeyDownEvent(k)
ev = KeyPressEvent(k)
}
case PasteStartEvent:
d.paste = []byte{}
Expand Down
34 changes: 17 additions & 17 deletions input/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *Driver) detectConInputQuerySequences(events []Event) []Event {
loop:
for i, e := range events {
switch e := e.(type) {
case KeyDownEvent:
case KeyPressEvent:
switch e.Rune {
case ansi.ESC, ansi.CSI, ansi.OSC, ansi.DCS, ansi.APC:
// start of a sequence
Expand All @@ -85,7 +85,7 @@ loop:
var seq []byte
for i := start; i <= end; i++ {
switch e := events[i].(type) {
case KeyDownEvent:
case KeyPressEvent:
seq = append(seq, byte(e.Rune))
}
}
Expand Down Expand Up @@ -115,9 +115,9 @@ func parseConInputEvent(event coninput.InputRecord, ps *coninput.ButtonState, ws

var key Key
switch event := event.(type) {
case KeyDownEvent:
case KeyPressEvent:
key = Key(event)
case KeyUpEvent:
case KeyReleaseEvent:
key = Key(event)
default:
return nil
Expand Down Expand Up @@ -165,10 +165,10 @@ func parseConInputEvent(event coninput.InputRecord, ps *coninput.ButtonState, ws

key.baseRune = runes[0]
if e.KeyDown {
return KeyDownEvent(key)
return KeyPressEvent(key)
}

return KeyUpEvent(key)
return KeyReleaseEvent(key)

case coninput.WindowBufferSizeEventRecord:
if e != *ws {
Expand Down Expand Up @@ -210,16 +210,16 @@ func mouseEventButton(p, s coninput.ButtonState) (button MouseButton, isRelease
return
}

switch {
case btn == coninput.FROM_LEFT_1ST_BUTTON_PRESSED: // left button
switch btn {
case coninput.FROM_LEFT_1ST_BUTTON_PRESSED: // left button
button = MouseLeft
case btn == coninput.RIGHTMOST_BUTTON_PRESSED: // right button
case coninput.RIGHTMOST_BUTTON_PRESSED: // right button
button = MouseRight
case btn == coninput.FROM_LEFT_2ND_BUTTON_PRESSED: // middle button
case coninput.FROM_LEFT_2ND_BUTTON_PRESSED: // middle button
button = MouseMiddle
case btn == coninput.FROM_LEFT_3RD_BUTTON_PRESSED: // unknown (possibly mouse backward)
case coninput.FROM_LEFT_3RD_BUTTON_PRESSED: // unknown (possibly mouse backward)
button = MouseBackward
case btn == coninput.FROM_LEFT_4TH_BUTTON_PRESSED: // unknown (possibly mouse forward)
case coninput.FROM_LEFT_4TH_BUTTON_PRESSED: // unknown (possibly mouse forward)
button = MouseForward
}

Expand All @@ -230,13 +230,13 @@ func mouseEvent(p coninput.ButtonState, e coninput.MouseEventRecord) (ev Event)
var mod KeyMod
var isRelease bool
if e.ControlKeyState.Contains(coninput.LEFT_ALT_PRESSED | coninput.RIGHT_ALT_PRESSED) {
mod |= Alt
mod |= ModAlt
}
if e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED | coninput.RIGHT_CTRL_PRESSED) {
mod |= Ctrl
mod |= ModCtrl
}
if e.ControlKeyState.Contains(coninput.SHIFT_PRESSED) {
mod |= Shift
mod |= ModShift
}
m := Mouse{
X: int(e.MousePositon.X),
Expand Down Expand Up @@ -266,8 +266,8 @@ func mouseEvent(p coninput.ButtonState, e coninput.MouseEventRecord) (ev Event)
if isWheel(m.Button) {
return MouseWheelEvent(m)
} else if isRelease {
return MouseUpEvent(m)
return MouseReleaseEvent(m)
}

return MouseDownEvent(m)
return MouseClickEvent(m)
}
18 changes: 9 additions & 9 deletions input/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ type Key struct {
// Sym is a special key, like enter, tab, backspace, and so on.
Sym KeySym

// Mod is a modifier key, like ctrl, alt, and so on.
Mod KeyMod

// Rune is the actual character received. If the user presses shift+a, the
// Rune will be 'A'.
Rune rune
Expand All @@ -211,6 +208,9 @@ type Key struct {
// Console API.
baseRune rune

// Mod is a modifier key, like ctrl, alt, and so on.
Mod KeyMod

// IsRepeat indicates whether the key is being held down and sending events
// repeatedly.
//
Expand All @@ -219,21 +219,21 @@ type Key struct {
IsRepeat bool
}

// KeyDownEvent represents a key down event.
type KeyDownEvent Key
// KeyPressEvent represents a key press event.
type KeyPressEvent Key

// String implements fmt.Stringer and is quite useful for matching key
// events. For details, on what this returns see [Key.String].
func (k KeyDownEvent) String() string {
func (k KeyPressEvent) String() string {
return Key(k).String()
}

// KeyUpEvent represents a key up event.
type KeyUpEvent Key
// KeyReleaseEvent represents a key release event.
type KeyReleaseEvent Key

// String implements fmt.Stringer and is quite useful for matching complex key
// events. For details, on what this returns see [Key.String].
func (k KeyUpEvent) String() string {
func (k KeyReleaseEvent) String() string {
return Key(k).String()
}

Expand Down
Loading

0 comments on commit ba77b10

Please sign in to comment.