From 8511766df2491174666128a1524e3b553e2ad3a7 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 20 Feb 2020 10:02:09 -0500 Subject: [PATCH] Highlight prompt in focused text field --- examples/go.mod | 2 ++ examples/inputs/main.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/examples/go.mod b/examples/go.mod index 1a3fd17..4754c82 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -4,6 +4,8 @@ go 1.13 replace github.com/charmbracelet/teaparty => ../ +replace github.com/charmbracelet/tea => ../../tea + require ( github.com/charmbracelet/tea v0.0.0-20200212224832-82af5a5cb50b github.com/charmbracelet/teaparty v0.0.0-20200212224515-b4d35fd52906 diff --git a/examples/inputs/main.go b/examples/inputs/main.go index e948119..584eec8 100644 --- a/examples/inputs/main.go +++ b/examples/inputs/main.go @@ -6,6 +6,13 @@ import ( "github.com/charmbracelet/tea" "github.com/charmbracelet/teaparty/input" + "github.com/muesli/termenv" +) + +var ( + color = termenv.ColorProfile().Color + focusedPrompt = termenv.String("> ").Foreground(color("205")).String() + blurredPrompt = termenv.String("> ").Foreground(color("244")).String() ) func main() { @@ -31,12 +38,15 @@ func initialize() (tea.Model, tea.Cmd) { name := input.DefaultModel() name.Placeholder = "Name" name.Focus() + name.Prompt = focusedPrompt nickName := input.DefaultModel() nickName.Placeholder = "Nickname" + nickName.Prompt = blurredPrompt email := input.DefaultModel() email.Placeholder = "Email" + email.Prompt = blurredPrompt return Model{0, name, nickName, email}, nil } @@ -87,9 +97,11 @@ func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) { for i := 0; i < len(inputs); i++ { if i == m.index { inputs[i].Focus() + inputs[i].Prompt = focusedPrompt continue } inputs[i].Blur() + inputs[i].Prompt = blurredPrompt } m.nameInput = inputs[0]