Skip to content

Commit

Permalink
Fix #3: use custom textarea styles
Browse files Browse the repository at this point in the history
  • Loading branch information
plutov committed Jul 25, 2024
1 parent 54ef6c8 commit 0ba1752
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var commandConfigureBlacklist = command{
Run: func(m model) model {
m.state = blacklistView
m.textarea.SetValue(strings.Join(m.domains, "\n"))
m.textarea.CursorEnd()
m.textarea.Focus()
m.textarea.CursorEnd()
return m
},
}
9 changes: 3 additions & 6 deletions cli/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ type model struct {
func NewModel() model {
domains, status, err := hosts.ExtractDomainsFromHostsFile()

state := menuView
ti := textarea.New()
ti.Blur()
if len(domains) == 0 {
domains = hosts.DefaultDomains
}

return model{
textarea: ti,
textarea: GetTextareModel(),
domains: domains,
state: state,
state: menuView,
status: status,
fatalErr: err,
}
Expand All @@ -48,7 +45,7 @@ func (m model) Init() tea.Cmd {
return tea.Quit
}

return textarea.Blink
return nil
}

func (m *model) getCommandsList() []command {
Expand Down
35 changes: 35 additions & 0 deletions cli/textarea.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/lipgloss"
)

func GetTextareModel() textarea.Model {
ti := textarea.New()
tiFocusedStyle := textarea.Style{
Base: lipgloss.NewStyle(),
CursorLine: lipgloss.NewStyle().Background(lipgloss.Color("0")),
CursorLineNumber: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
EndOfBuffer: lipgloss.NewStyle().Foreground(lipgloss.Color("0")),
LineNumber: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
Text: lipgloss.NewStyle(),
}
tiBlurredStyle := textarea.Style{
Base: lipgloss.NewStyle(),
CursorLine: lipgloss.NewStyle(),
CursorLineNumber: lipgloss.NewStyle(),
EndOfBuffer: lipgloss.NewStyle(),
LineNumber: lipgloss.NewStyle(),
Placeholder: lipgloss.NewStyle(),
Prompt: lipgloss.NewStyle(),
Text: lipgloss.NewStyle(),
}
ti.FocusedStyle = tiFocusedStyle
ti.BlurredStyle = tiBlurredStyle
ti.Blur()

return ti
}

0 comments on commit 0ba1752

Please sign in to comment.