Skip to content

Commit

Permalink
chore: Add Deprecated Fields to avoid breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jul 21, 2022
1 parent 4bb7aae commit dc88246
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
36 changes: 18 additions & 18 deletions cursor/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ 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.
func New() Model {
return Model{
BlinkSpeed: defaultBlinkSpeed,

Blink: true,
cursorMode: CursorBlink,
Blink: true,
mode: CursorBlink,

blinkCtx: &blinkCtx{
ctx: context.Background(),
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package textinput

import (
"strings"
"time"
"unicode"

"github.com/atotto/clipboard"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))
}

0 comments on commit dc88246

Please sign in to comment.