refactor: change several message types to structs for extensibility
This commit is contained in:
parent
7a6e8fcb87
commit
b947ade70d
6 changed files with 35 additions and 10 deletions
|
|
@ -4,7 +4,9 @@ package tea
|
|||
type Position struct{ X, Y int }
|
||||
|
||||
// CursorPositionMsg is a message that represents the terminal cursor position.
|
||||
type CursorPositionMsg Position
|
||||
type CursorPositionMsg struct {
|
||||
X, Y int
|
||||
}
|
||||
|
||||
// CursorShape represents a terminal cursor shape.
|
||||
type CursorShape int
|
||||
|
|
|
|||
12
keyboard.go
12
keyboard.go
|
|
@ -6,24 +6,26 @@ import (
|
|||
|
||||
// KeyboardEnhancementsMsg is a message that gets sent when the terminal
|
||||
// supports keyboard enhancements.
|
||||
type KeyboardEnhancementsMsg uint8
|
||||
type KeyboardEnhancementsMsg struct {
|
||||
Flags int
|
||||
}
|
||||
|
||||
// SupportsKeyDisambiguation returns whether the terminal supports reporting
|
||||
// disambiguous keys as escape codes.
|
||||
func (k KeyboardEnhancementsMsg) SupportsKeyDisambiguation() bool {
|
||||
return k&ansi.KittyDisambiguateEscapeCodes != 0
|
||||
return k.Flags&ansi.KittyDisambiguateEscapeCodes != 0
|
||||
}
|
||||
|
||||
// SupportsKeyReleases returns whether the terminal supports key release
|
||||
// events.
|
||||
func (k KeyboardEnhancementsMsg) SupportsKeyReleases() bool {
|
||||
return k&ansi.KittyReportEventTypes != 0
|
||||
return k.Flags&ansi.KittyReportEventTypes != 0
|
||||
}
|
||||
|
||||
// SupportsUniformKeyLayout returns whether the terminal supports reporting key
|
||||
// events as though they were on a PC-101 layout.
|
||||
func (k KeyboardEnhancementsMsg) SupportsUniformKeyLayout() bool {
|
||||
return k.SupportsKeyDisambiguation() &&
|
||||
k&ansi.KittyReportAlternateKeys != 0 &&
|
||||
k&ansi.KittyReportAllKeysAsEscapeCodes != 0
|
||||
k.Flags&ansi.KittyReportAlternateKeys != 0 &&
|
||||
k.Flags&ansi.KittyReportAllKeysAsEscapeCodes != 0
|
||||
}
|
||||
|
|
|
|||
9
paste.go
9
paste.go
|
|
@ -2,7 +2,14 @@ package tea
|
|||
|
||||
// PasteMsg is an message that is emitted when a terminal receives pasted text
|
||||
// using bracketed-paste.
|
||||
type PasteMsg string
|
||||
type PasteMsg struct {
|
||||
Content string
|
||||
}
|
||||
|
||||
// String returns the pasted content as a string.
|
||||
func (p PasteMsg) String() string {
|
||||
return p.Content
|
||||
}
|
||||
|
||||
// PasteStartMsg is an message that is emitted when the terminal starts the
|
||||
// bracketed-paste text.
|
||||
|
|
|
|||
2
tea.go
2
tea.go
|
|
@ -692,7 +692,7 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
|||
}
|
||||
|
||||
case CapabilityMsg:
|
||||
switch msg {
|
||||
switch msg.Content {
|
||||
case "RGB", "Tc":
|
||||
if *p.profile != colorprofile.TrueColor {
|
||||
tc := colorprofile.TrueColor
|
||||
|
|
|
|||
|
|
@ -38,4 +38,11 @@ func RequestCapability(s string) Cmd {
|
|||
// (XTGETTCAP) requests.
|
||||
//
|
||||
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
||||
type CapabilityMsg string
|
||||
type CapabilityMsg struct {
|
||||
Content string
|
||||
}
|
||||
|
||||
// String returns the capability content as a string.
|
||||
func (c CapabilityMsg) String() string {
|
||||
return c.Content
|
||||
}
|
||||
|
|
|
|||
9
xterm.go
9
xterm.go
|
|
@ -1,7 +1,14 @@
|
|||
package tea
|
||||
|
||||
// TerminalVersionMsg is a message that represents the terminal version.
|
||||
type TerminalVersionMsg string
|
||||
type TerminalVersionMsg struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// String returns the terminal name as a string.
|
||||
func (t TerminalVersionMsg) String() string {
|
||||
return t.Name
|
||||
}
|
||||
|
||||
// terminalVersion is an internal message that queries the terminal for its
|
||||
// version using XTVERSION.
|
||||
|
|
|
|||
Loading…
Reference in a new issue