Skip to content

Commit

Permalink
refactor: windows: clean up and remove redundent code
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 15, 2024
1 parent aceb3d8 commit 6428f6c
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 637 deletions.
25 changes: 16 additions & 9 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import (
"github.com/muesli/cancelreader"
)

// win32InputState is a state machine for parsing key events from the Windows
// Console API into escape sequences and utf8 runes, and keeps track of the last
// control key state to determine modifier key changes. It also keeps track of
// the last mouse button state and window size changes to determine which mouse
// buttons were released and to prevent multiple size events from firing.
type win32InputState struct {
ansiBuf [256]byte

Check failure on line 17 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `ansiBuf` is unused (unused)

Check failure on line 17 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `ansiBuf` is unused (unused)
ansiIdx int

Check failure on line 18 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `ansiIdx` is unused (unused)

Check failure on line 18 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `ansiIdx` is unused (unused)
utf16Buf [2]rune

Check failure on line 19 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `utf16Buf` is unused (unused)

Check failure on line 19 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `utf16Buf` is unused (unused)
utf16Half bool

Check failure on line 20 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `utf16Half` is unused (unused)

Check failure on line 20 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `utf16Half` is unused (unused)
lastCks uint32 // the last control key state for the previous event

Check failure on line 21 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastCks` is unused (unused)

Check failure on line 21 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastCks` is unused (unused)
lastMouseBtns uint32 // the last mouse button state for the previous event

Check failure on line 22 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastMouseBtns` is unused (unused)

Check failure on line 22 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastMouseBtns` is unused (unused)
lastWinsizeX, lastWinsizeY int16 // the last window size for the previous event to prevent multiple size events from firing

Check failure on line 23 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastWinsizeX` is unused (unused)

Check failure on line 23 in driver.go

View workflow job for this annotation

GitHub Actions / lint

field `lastWinsizeX` is unused (unused)
}

// driver represents an ANSI terminal input driver.
// It reads input events and parses ANSI sequences from the terminal input
// buffer.
Expand All @@ -23,17 +38,9 @@ type driver struct {

buf [256]byte // do we need a larger buffer?

// prevMouseState keeps track of the previous mouse state to determine mouse
// up button events.
prevMouseState uint32 // nolint: unused

// lastWinsizeEvent keeps track of the last window size event to prevent
// multiple size events from firing.
lastWinsizeEventX, lastWinsizeEventY int16 // nolint: unused

// keyState keeps track of the current Windows Console API key events state.
// It is used to decode ANSI escape sequences and utf16 sequences.
keyState win32KeyState //nolint:unused
keyState win32InputState //nolint:unused

flags int // control the behavior of the driver.
}
Expand Down
28 changes: 17 additions & 11 deletions driver_other.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
//go:build !windows
// +build !windows

package tea

// ReadEvents reads input events from the terminal.
//
// It reads the events available in the input buffer and returns them.
func (d *driver) ReadEvents() ([]Msg, error) {
return d.readEvents()
}
//go:build !windows
// +build !windows

package tea

// ReadEvents reads input events from the terminal.
//
// It reads the events available in the input buffer and returns them.
func (d *driver) ReadEvents() ([]Msg, error) {
return d.readEvents()
}

// parseWin32InputKeyEvent parses a Win32 input key events. This function is
// only available on Windows.
func parseWin32InputKeyEvent(*win32InputState, uint16, uint16, rune, bool, uint32, uint16) Msg {
return nil
}
Loading

0 comments on commit 6428f6c

Please sign in to comment.