From dc8824674d765057e4f1d63ceaa439c81aad6acb Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 7 Jul 2022 10:39:49 -0400 Subject: [PATCH] chore: Add Deprecated Fields to avoid breaking changes --- cursor/cursor.go | 36 ++++++++++++++++++------------------ textinput/textinput.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/cursor/cursor.go b/cursor/cursor.go index 9ad445e5..7b688dd2 100644 --- a/cursor/cursor.go +++ b/cursor/cursor.go @@ -70,8 +70,8 @@ type Model struct { blinkCtx *blinkCtx // The ID of the blink message we're expecting to receive. blinkTag int - // cursorMode determines the behavior of the cursor - cursorMode Mode + // mode determines the behavior of the cursor + mode Mode } // New creates a new model with default settings. @@ -79,8 +79,8 @@ func New() Model { return Model{ BlinkSpeed: defaultBlinkSpeed, - Blink: true, - cursorMode: CursorBlink, + Blink: true, + mode: CursorBlink, blinkCtx: &blinkCtx{ ctx: context.Background(), @@ -94,7 +94,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case initialBlinkMsg: // We accept all initialBlinkMsgs generated by the Blink command. - if m.cursorMode != CursorBlink || !m.focus { + if m.mode != CursorBlink || !m.focus { return m, nil } @@ -106,7 +106,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // only exactly when it should. // Is this model blink-able? - if m.cursorMode != CursorBlink || !m.focus { + if m.mode != CursorBlink || !m.focus { return m, nil } @@ -116,7 +116,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { } var cmd tea.Cmd - if m.cursorMode == CursorBlink { + if m.mode == CursorBlink { m.Blink = !m.Blink cmd = m.BlinkCmd() } @@ -128,18 +128,18 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { return m, nil } -// CursorMode returns the model's cursor mode. For available cursor modes, see -// type CursorMode. -func (m Model) CursorMode() Mode { - return m.cursorMode +// Mode returns the model's cursor mode. For available cursor modes, see +// type Mode. +func (m Model) Mode() Mode { + return m.mode } -// SetCursorMode sets the model's cursor mode. This method returns a command. +// SetMode sets the model's cursor mode. This method returns a command. // // For available cursor modes, see type CursorMode. -func (m *Model) SetCursorMode(mode Mode) tea.Cmd { - m.cursorMode = mode - m.Blink = m.cursorMode == CursorHide || !m.focus +func (m *Model) SetMode(mode Mode) tea.Cmd { + m.mode = mode + m.Blink = m.mode == CursorHide || !m.focus if mode == CursorBlink { return Blink } @@ -148,7 +148,7 @@ func (m *Model) SetCursorMode(mode Mode) tea.Cmd { // BlinkCmd is an command used to manage cursor blinking. func (m *Model) BlinkCmd() tea.Cmd { - if m.cursorMode != CursorBlink { + if m.mode != CursorBlink { return nil } @@ -179,9 +179,9 @@ func Blink() tea.Msg { // Focus focuses the cursor to allow it to blink if desired. func (m *Model) Focus() tea.Cmd { m.focus = true - m.Blink = m.cursorMode == CursorHide // show the cursor unless we've explicitly hidden it + m.Blink = m.mode == CursorHide // show the cursor unless we've explicitly hidden it - if m.cursorMode == CursorBlink && m.focus { + if m.mode == CursorBlink && m.focus { return m.BlinkCmd() } return nil diff --git a/textinput/textinput.go b/textinput/textinput.go index 238611e1..88457b95 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -2,6 +2,7 @@ package textinput import ( "strings" + "time" "unicode" "github.com/atotto/clipboard" @@ -47,6 +48,10 @@ type Model struct { EchoCharacter rune Cursor cursor.Model + // Deprecated: use cursor.BlinkSpeed instead. + // This is unused and will be removed in the future. + BlinkSpeed time.Duration + // Styles. These will be applied as inline styles. // // For an introduction to styling with Lip Gloss see: @@ -654,3 +659,31 @@ func max(a, b int) int { } return b } + +// Deprecated. + +// Deprecated: use cursor.Mode. +type CursorMode int + +const ( + // Deprecated: use cursor.CursorBlink. + CursorBlink = CursorMode(cursor.CursorBlink) + // Deprecated: use cursor.CursorStatic. + CursorStatic = CursorMode(cursor.CursorStatic) + // Deprecated: use cursor.CursorHide. + CursorHide = CursorMode(cursor.CursorHide) +) + +func (c CursorMode) String() string { + return cursor.Mode(c).String() +} + +// Deprecated: use cursor.Mode(). +func (m Model) CursorMode() CursorMode { + return CursorMode(m.Cursor.Mode()) +} + +// Deprecated: use cursor.SetMode(). +func (m *Model) SetCursorMode(mode CursorMode) tea.Cmd { + return m.Cursor.SetMode(cursor.Mode(mode)) +}