Highlight prompt in focused text field

This commit is contained in:
Christian Rocha 2020-02-20 10:02:09 -05:00
parent 318f47a6aa
commit 8511766df2
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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]