Skip to content

Commit

Permalink
fix: rename events to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Aug 13, 2024
1 parent 448eb82 commit cb37f88
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 40 deletions.
10 changes: 6 additions & 4 deletions clipboard.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package tea

// ClipboardEvent is a clipboard read event.
type ClipboardEvent string
// ClipboardMsg is a clipboard read message event.
// This message is emitted when a terminal receives an OSC52 clipboard read
// message event.
type ClipboardMsg string

// String returns the string representation of the clipboard event.
func (e ClipboardEvent) String() string {
// String returns the string representation of the clipboard message.
func (e ClipboardMsg) String() string {
return string(e)
}
29 changes: 17 additions & 12 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,32 @@ import (
"strings"
)

// ForegroundColorEvent represents a foreground color change event.
type ForegroundColorEvent struct{ color.Color }
// ForegroundColorMsg represents a foreground color message.
// This message is emitted when the program requests the terminal foreground
// color.
type ForegroundColorMsg struct{ color.Color }

// String implements fmt.Stringer.
func (e ForegroundColorEvent) String() string {
// String returns the hex representation of the color.
func (e ForegroundColorMsg) String() string {
return colorToHex(e)
}

// BackgroundColorEvent represents a background color change event.
type BackgroundColorEvent struct{ color.Color }
// BackgroundColorMsg represents a background color message.
// This message is emitted when the program requests the terminal background
// color.
type BackgroundColorMsg struct{ color.Color }

// String implements fmt.Stringer.
func (e BackgroundColorEvent) String() string {
// String returns the hex representation of the color.
func (e BackgroundColorMsg) String() string {
return colorToHex(e)
}

// CursorColorEvent represents a cursor color change event.
type CursorColorEvent struct{ color.Color }
// CursorColorMsg represents a cursor color change message.
// This message is emitted when the program requests the terminal cursor color.
type CursorColorMsg struct{ color.Color }

// String implements fmt.Stringer.
func (e CursorColorEvent) String() string {
// String returns the hex representation of the color.
func (e CursorColorMsg) String() string {
return colorToHex(e)
}

Expand Down
4 changes: 2 additions & 2 deletions cursor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tea

// CursorPositionEvent represents a cursor position event.
type CursorPositionEvent struct {
// CursorPositionMsg is a message that represents the terminal cursor position.
type CursorPositionMsg struct {
// Row is the row number.
Row int

Expand Down
3 changes: 2 additions & 1 deletion da1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package tea

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

// PrimaryDeviceAttributesMsg represents a primary device attributes message.
// PrimaryDeviceAttributesMsg is a message that represents the terminal primary
// device attributes.
type PrimaryDeviceAttributesMsg []uint

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

// ReportModeEvent represents a report mode event for sequence DECRPM.
// ReportModeMsg is a message that represents a mode report event (DECRPM).
//
// See: https://vt100.net/docs/vt510-rm/DECRPM.html
type ReportModeEvent struct {
type ReportModeMsg struct {
// Mode is the mode number.
Mode int

Expand Down
22 changes: 11 additions & 11 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func parseCsi(b []byte) (int, Msg) {
if paramsLen != 2 {
return i, UnknownMsg(b[:i])
}
return i, ReportModeEvent{Mode: csi.Param(0), Value: csi.Param(1)}
return i, ReportModeMsg{Mode: csi.Param(0), Value: csi.Param(1)}
}
case 'c':
// Primary Device Attributes
Expand All @@ -260,7 +260,7 @@ func parseCsi(b []byte) (int, Msg) {
// This report may return a third parameter representing the page
// number, but we don't really need it.
if paramsLen >= 2 {
return i, CursorPositionEvent{Row: csi.Param(0), Column: csi.Param(1)}
return i, CursorPositionMsg{Row: csi.Param(0), Column: csi.Param(1)}
}
}
return i, UnknownMsg(b[:i])
Expand All @@ -283,7 +283,7 @@ func parseCsi(b []byte) (int, Msg) {
return i, UnknownMsg(b[:i])
}

return i, ModifyOtherKeysEvent(csi.Param(1))
return i, ModifyOtherKeysMsg(csi.Param(1))
default:
return i, UnknownMsg(b[:i])
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func parseCsi(b []byte) (int, Msg) {
// For a non ambiguous cursor position report, use
// [ansi.RequestExtendedCursorPosition] (DECXCPR) instead.
if csi.Param(0) != 1 {
return i, CursorPositionEvent{Row: csi.Param(0), Column: csi.Param(1)}
return i, CursorPositionMsg{Row: csi.Param(0), Column: csi.Param(1)}
}

fallthrough
Expand Down Expand Up @@ -353,7 +353,7 @@ func parseCsi(b []byte) (int, Msg) {
if paramsLen != 2 {
return i, UnknownMsg(b[:i])
}
return i, ReportModeEvent{Mode: csi.Param(0), Value: csi.Param(1)}
return i, ReportModeMsg{Mode: csi.Param(0), Value: csi.Param(1)}
case 'u':
// Kitty keyboard protocol & CSI u (fixterms)
if paramsLen == 0 {
Expand Down Expand Up @@ -599,22 +599,22 @@ func parseOsc(b []byte) (int, Msg) {
data := string(b[start:end])
switch cmd {
case 10:
return i, ForegroundColorEvent{xParseColor(data)}
return i, ForegroundColorMsg{xParseColor(data)}
case 11:
return i, BackgroundColorEvent{xParseColor(data)}
return i, BackgroundColorMsg{xParseColor(data)}
case 12:
return i, CursorColorEvent{xParseColor(data)}
return i, CursorColorMsg{xParseColor(data)}
case 52:
parts := strings.Split(data, ";")
if len(parts) == 0 {
return i, ClipboardEvent("")
return i, ClipboardMsg("")
}
b64 := parts[len(parts)-1]
bts, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
return i, ClipboardEvent("")
return i, ClipboardMsg("")
}
return i, ClipboardEvent(bts)
return i, ClipboardMsg(bts)
default:
return i, UnknownMsg(b[:i])
}
Expand Down
4 changes: 2 additions & 2 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func TestParseSequence_Events(t *testing.T) {
KeyPressMsg{Runes: []rune{'s'}},
KeyPressMsg{Runes: []rune{'t'}},
KeyPressMsg{Runes: []rune{' '}, Sym: KeySpace, Mod: ModCtrl},
ForegroundColorEvent{color.RGBA{R: 0x12, G: 0x12, B: 0x12, A: 0xff}},
ForegroundColorMsg{color.RGBA{R: 0x12, G: 0x12, B: 0x12, A: 0xff}},
KeyPressMsg{Sym: KeyEscape, Mod: ModShift},
ReportModeEvent{Mode: 1049, Value: 2},
ReportModeMsg{Mode: 1049, Value: 2},
}
for i := 0; len(input) != 0; i++ {
if i >= len(want) {
Expand Down
8 changes: 4 additions & 4 deletions paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package tea
// using bracketed-paste.
type PasteMsg string

// PasteStartMsg is an message that is emitted when a terminal enters
// bracketed-paste mode.
// PasteStartMsg is an message that is emitted when the terminal starts the
// bracketed-paste text

Check failure on line 8 in paste.go

View workflow job for this annotation

GitHub Actions / lint-soft

Comment should end in a period (godot)
type PasteStartMsg struct{}

// PasteEvent is an message that is emitted when a terminal receives pasted
// text.
// PasteEndMsg is an message that is emitted when the terminal ends the
// bracketed-paste text.
type PasteEndMsg struct{}
6 changes: 4 additions & 2 deletions xterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ func parseXTermModifyOtherKeys(csi *ansi.CsiSequence) Msg {
}
}

// ModifyOtherKeysEvent represents a modifyOtherKeys event.
// ModifyOtherKeysMsg is a message that represents XTerm modifyOtherKeys
// report. Querying the terminal for the modifyOtherKeys mode will return a
// ModifyOtherKeysMsg message with the current mode set.
//
// 0: disable
// 1: enable mode 1
// 2: enable mode 2
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
// See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
type ModifyOtherKeysEvent uint8
type ModifyOtherKeysMsg uint8

0 comments on commit cb37f88

Please sign in to comment.