Skip to content

Commit

Permalink
chore(input): update godoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 9, 2024
1 parent 88394e1 commit af8254c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
33 changes: 9 additions & 24 deletions input/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"math"
)

// ForegroundColorEvent represents a foreground color message. This message is
// emitted when the program requests the terminal foreground color with the
// [RequestForegroundColor] Cmd.
// ForegroundColorEvent represents a foreground color event. This event is
// emitted when the terminal requests the terminal foreground color using
// [ansi.RequestForegroundColor].
type ForegroundColorEvent struct{ color.Color }

// String returns the hex representation of the color.
Expand All @@ -21,25 +21,9 @@ func (e ForegroundColorEvent) IsDark() bool {
return isDarkColor(e.Color)
}

// BackgroundColorEvent represents a background color message. This message is
// emitted when the program requests the terminal background color with the
// [RequestBackgroundColor] Cmd.
//
// This is commonly used in [Update.Init] to get the terminal background color
// for style definitions. For that you'll want to call
// [BackgroundColorEvent.IsDark] to determine if the color is dark or light. For
// example:
//
// func (m Model) Init() (Model, Cmd) {
// return m, RequestBackgroundColor()
// }
//
// func (m Model) Update(Event Event) (Model, Cmd) {
// switch Event := Event.(type) {
// case BackgroundColorEvent:
// m.styles = newStyles(Event.IsDark())
// }
// }
// BackgroundColorEvent represents a background color event. This event is
// emitted when the terminal requests the terminal background color using
// [ansi.RequestBackgroundColor].
type BackgroundColorEvent struct{ color.Color }

// String returns the hex representation of the color.
Expand All @@ -52,8 +36,9 @@ func (e BackgroundColorEvent) IsDark() bool {
return isDarkColor(e.Color)
}

// CursorColorEvent represents a cursor color change message. This message is
// emitted when the program requests the terminal cursor color.
// CursorColorEvent represents a cursor color change event. This event is
// emitted when the program requests the terminal cursor color using
// [ansi.RequestCursorColor].
type CursorColorEvent struct{ color.Color }

// String returns the hex representation of the color.
Expand Down
4 changes: 2 additions & 2 deletions input/da1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package input

import "github.com/charmbracelet/x/ansi"

// PrimaryDeviceAttributesEvent is a message that represents the terminal primary
// device attributes.
// PrimaryDeviceAttributesEvent is an event that represents the terminal
// primary device attributes.
type PrimaryDeviceAttributesEvent []int

func parsePrimaryDevAttrs(csi *ansi.CsiSequence) Event {
Expand Down
4 changes: 2 additions & 2 deletions input/focus.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package input

// FocusEvent represents a terminal focus message.
// FocusEvent represents a terminal focus event.
// This occurs when the terminal gains focus.
type FocusEvent struct{}

// BlurEvent represents a terminal blur message.
// BlurEvent represents a terminal blur event.
// This occurs when the terminal loses focus.
type BlurEvent struct{}
12 changes: 6 additions & 6 deletions input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
// Event represents a terminal event.
type Event interface{}

// UnknownEvent represents an unknown message.
// UnknownEvent represents an unknown event.
type UnknownEvent string

// String returns a string representation of the unknown message.
// String returns a string representation of the unknown event.
func (e UnknownEvent) String() string {
return fmt.Sprintf("%q", string(e))
}
Expand All @@ -28,10 +28,10 @@ func (e MultiEvent) String() string {
return sb.String()
}

// WindowSizeEvent is used to report the terminal size. It's sent to Update once
// initially and then on every terminal resize. Note that Windows does not
// have support for reporting when resizes occur as it does not support the
// SIGWINCH signal.
// WindowSizeEvent is used to report the terminal size. Note that Windows does
// not have support for reporting resizes via SIGWINCH signals and relies on
// the Windows Console API to report window size changes. See [newCancelreader]
// and [conInputReader] for more information.
type WindowSizeEvent struct {
Width int
Height int
Expand Down
12 changes: 6 additions & 6 deletions input/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const (
KeySpace = rune(ansi.SP)
)

// KeyPressEvent represents a key press message.
// KeyPressEvent represents a key press event.
type KeyPressEvent Key

// String implements [fmt.Stringer] and is quite useful for matching key
Expand All @@ -204,7 +204,7 @@ func (k KeyPressEvent) Key() Key {
return Key(k)
}

// KeyReleaseEvent represents a key release message.
// KeyReleaseEvent represents a key release event.
type KeyReleaseEvent Key

// String implements [fmt.Stringer] and is quite useful for matching key
Expand Down Expand Up @@ -235,9 +235,9 @@ type KeyEvent interface {
// or releases:
//
// // Switch on the string representation of the key (shorter)
// switch Event := Event.(type) {
// switch ev := ev.(type) {
// case KeyPressEvent:
// switch Event.String() {
// switch ev.String() {
// case "enter":
// fmt.Println("you pressed enter!")
// case "a":
Expand All @@ -246,10 +246,10 @@ type KeyEvent interface {
// }
//
// // Switch on the key type (more foolproof)
// switch Event := Event.(type) {
// switch ev := ev.(type) {
// case KeyEvent:
// // catch both KeyPressEvent and KeyReleaseEvent
// switch key := Event.Key(); key.Code {
// switch key := ev.Key(); key.Code {
// case KeyEnter:
// fmt.Println("you pressed enter!")
// default:
Expand Down
14 changes: 7 additions & 7 deletions input/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (m Mouse) String() (s string) {
return s
}

// MouseClickEvent represents a mouse button click message.
// MouseClickEvent represents a mouse button click event.
type MouseClickEvent Mouse

// String returns a string representation of the mouse click message.
// String returns a string representation of the mouse click event.
func (e MouseClickEvent) String() string {
return Mouse(e).String()
}
Expand All @@ -131,10 +131,10 @@ func (e MouseClickEvent) Mouse() Mouse {
return Mouse(e)
}

// MouseReleaseEvent represents a mouse button release message.
// MouseReleaseEvent represents a mouse button release event.
type MouseReleaseEvent Mouse

// String returns a string representation of the mouse release message.
// String returns a string representation of the mouse release event.
func (e MouseReleaseEvent) String() string {
return Mouse(e).String()
}
Expand All @@ -149,7 +149,7 @@ func (e MouseReleaseEvent) Mouse() Mouse {
// MouseWheelEvent represents a mouse wheel message event.
type MouseWheelEvent Mouse

// String returns a string representation of the mouse wheel message.
// String returns a string representation of the mouse wheel event.
func (e MouseWheelEvent) String() string {
return Mouse(e).String()
}
Expand All @@ -161,10 +161,10 @@ func (e MouseWheelEvent) Mouse() Mouse {
return Mouse(e)
}

// MouseMotionEvent represents a mouse motion message.
// MouseMotionEvent represents a mouse motion event.
type MouseMotionEvent Mouse

// String returns a string representation of the mouse motion message.
// String returns a string representation of the mouse motion event.
func (e MouseMotionEvent) String() string {
m := Mouse(e)
if m.Button != 0 {
Expand Down

0 comments on commit af8254c

Please sign in to comment.