Skip to content

Commit 0ba1752

Browse files
committed
Fix #3: use custom textarea styles
1 parent 54ef6c8 commit 0ba1752

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

cli/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ var commandConfigureBlacklist = command{
4646
Run: func(m model) model {
4747
m.state = blacklistView
4848
m.textarea.SetValue(strings.Join(m.domains, "\n"))
49-
m.textarea.CursorEnd()
5049
m.textarea.Focus()
50+
m.textarea.CursorEnd()
5151
return m
5252
},
5353
}

cli/model.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ type model struct {
2727
func NewModel() model {
2828
domains, status, err := hosts.ExtractDomainsFromHostsFile()
2929

30-
state := menuView
31-
ti := textarea.New()
32-
ti.Blur()
3330
if len(domains) == 0 {
3431
domains = hosts.DefaultDomains
3532
}
3633

3734
return model{
38-
textarea: ti,
35+
textarea: GetTextareModel(),
3936
domains: domains,
40-
state: state,
37+
state: menuView,
4138
status: status,
4239
fatalErr: err,
4340
}
@@ -48,7 +45,7 @@ func (m model) Init() tea.Cmd {
4845
return tea.Quit
4946
}
5047

51-
return textarea.Blink
48+
return nil
5249
}
5350

5451
func (m *model) getCommandsList() []command {

cli/textarea.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cli
2+
3+
import (
4+
"github.com/charmbracelet/bubbles/textarea"
5+
"github.com/charmbracelet/lipgloss"
6+
)
7+
8+
func GetTextareModel() textarea.Model {
9+
ti := textarea.New()
10+
tiFocusedStyle := textarea.Style{
11+
Base: lipgloss.NewStyle(),
12+
CursorLine: lipgloss.NewStyle().Background(lipgloss.Color("0")),
13+
CursorLineNumber: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
14+
EndOfBuffer: lipgloss.NewStyle().Foreground(lipgloss.Color("0")),
15+
LineNumber: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
16+
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
17+
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
18+
Text: lipgloss.NewStyle(),
19+
}
20+
tiBlurredStyle := textarea.Style{
21+
Base: lipgloss.NewStyle(),
22+
CursorLine: lipgloss.NewStyle(),
23+
CursorLineNumber: lipgloss.NewStyle(),
24+
EndOfBuffer: lipgloss.NewStyle(),
25+
LineNumber: lipgloss.NewStyle(),
26+
Placeholder: lipgloss.NewStyle(),
27+
Prompt: lipgloss.NewStyle(),
28+
Text: lipgloss.NewStyle(),
29+
}
30+
ti.FocusedStyle = tiFocusedStyle
31+
ti.BlurredStyle = tiBlurredStyle
32+
ti.Blur()
33+
34+
return ti
35+
}

0 commit comments

Comments
 (0)