This change separates the viw from the main model by introducing new interfaces `ViewModel` and `CursorModel`. The `ViewModel` interface provides a view method that returns the string to render, while the `CursorModel` interface provides a view method that returns the string to render and the cursor position. If a program does not implement a view interface, the program won't render anything. This removes the need for the `WithoutRenderer` option.
26 lines
689 B
Go
26 lines
689 B
Go
package tea
|
|
|
|
// Position represents a position in the terminal.
|
|
type Position struct{ X, Y int }
|
|
|
|
// CursorPositionMsg is a message that represents the terminal cursor position.
|
|
type CursorPositionMsg Position
|
|
|
|
// CursorShape represents a terminal cursor shape.
|
|
type CursorShape int
|
|
|
|
// Cursor shapes.
|
|
const (
|
|
CursorBlock CursorShape = iota
|
|
CursorUnderline
|
|
CursorBar
|
|
)
|
|
|
|
// requestCursorPosMsg is a message that requests the cursor position.
|
|
type requestCursorPosMsg struct{}
|
|
|
|
// RequestCursorPosition is a command that requests the cursor position.
|
|
// The cursor position will be sent as a [CursorPositionMsg] message.
|
|
func RequestCursorPosition() Msg {
|
|
return requestCursorPosMsg{}
|
|
}
|