diff --git a/go.mod b/go.mod index cf042a8..9234f4b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/charmbracelet/teaparty go 1.13 require ( - github.com/charmbracelet/tea v0.0.0-20200220032354-23432f30dd46 + github.com/charmbracelet/tea v0.2.0 github.com/muesli/termenv v0.5.0 golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect ) diff --git a/go.sum b/go.sum index 2e31bae..9e60a15 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/charmbracelet/tea v0.0.0-20200220032354-23432f30dd46 h1:ZRxnZ9WA8+DX7IpIrUjaAzue12wCA8bHgDWSrqARvGY= github.com/charmbracelet/tea v0.0.0-20200220032354-23432f30dd46/go.mod h1:96S8RyGdd7HfPcgDC8XqPKe+eH/1etFkw6lfhQCesgU= +github.com/charmbracelet/tea v0.2.0/go.mod h1:lADjwO2mMub9qvXSCA9vAkabVWO0HeUrv4uO/lG3C+k= github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f h1:5CjVwnuUcp5adK4gmY6i72gpVFVnZDP2h5TmPScB6u4= github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= diff --git a/input/input.go b/input/input.go index d208f56..23acbba 100644 --- a/input/input.go +++ b/input/input.go @@ -1,10 +1,10 @@ package input import ( + "errors" "time" "github.com/charmbracelet/tea" - "github.com/muesli/termenv" ) @@ -13,7 +13,10 @@ var ( color func(s string) termenv.Color = termenv.ColorProfile().Color ) +type ErrMsg error + type Model struct { + Err error Prompt string Value string Cursor string @@ -149,6 +152,10 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) { return m, nil } + case ErrMsg: + m.Err = msg + return m, nil + case CursorBlinkMsg: m.blink = !m.blink return m, nil @@ -215,7 +222,7 @@ func cursorView(s string, m Model) string { func Blink(model tea.Model) tea.Msg { m, ok := model.(Model) if !ok { - return tea.NewErrMsg("could not assert given model to the model we expected; make sure you're passing as input model") + return ErrMsg(errors.New("could not assert given model to the model we expected; make sure you're passing as input model")) } time.Sleep(m.BlinkSpeed) return CursorBlinkMsg{}