mirror of
https://github.com/anotherhadi/usbguard-tui.git
synced 2026-06-26 00:22:34 +02:00
Add ilovetui integration
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"charm.land/bubbles/v2/list"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/anotherhadi/ilovetui"
|
||||
"github.com/anotherhadi/usbguard-tui/internal/guard"
|
||||
)
|
||||
|
||||
@@ -30,25 +31,25 @@ func (d deviceDelegate) Render(w io.Writer, m list.Model, index int, item list.I
|
||||
}
|
||||
clr, ok := colorMap[dev.Status]
|
||||
if !ok {
|
||||
clr = colorMuted
|
||||
clr = ilovetui.S.Muted
|
||||
}
|
||||
|
||||
var nameStyle, descStyle lipgloss.Style
|
||||
if selected {
|
||||
nameStyle = lipgloss.NewStyle().
|
||||
Border(lipgloss.NormalBorder(), false, false, false, true).
|
||||
BorderForeground(colorAccent).
|
||||
BorderForeground(ilovetui.S.Primary).
|
||||
Foreground(clr).
|
||||
Bold(true).
|
||||
PaddingLeft(1)
|
||||
descStyle = lipgloss.NewStyle().
|
||||
Border(lipgloss.NormalBorder(), false, false, false, true).
|
||||
BorderForeground(colorAccent).
|
||||
Foreground(colorMuted).
|
||||
BorderForeground(ilovetui.S.Primary).
|
||||
Foreground(ilovetui.S.Muted).
|
||||
PaddingLeft(1)
|
||||
} else {
|
||||
nameStyle = lipgloss.NewStyle().Foreground(clr).PaddingLeft(2)
|
||||
descStyle = lipgloss.NewStyle().Foreground(colorMuted).PaddingLeft(2)
|
||||
descStyle = lipgloss.NewStyle().Foreground(ilovetui.S.Muted).PaddingLeft(2)
|
||||
}
|
||||
|
||||
permIndicator := "○ tmp"
|
||||
@@ -87,7 +88,7 @@ func (d actionDelegate) Render(w io.Writer, m list.Model, index int, item list.I
|
||||
if index == m.Index() {
|
||||
clr, ok := statusColorsSelected[a.status]
|
||||
if !ok {
|
||||
clr = colorAccent
|
||||
clr = ilovetui.S.Primary
|
||||
}
|
||||
fmt.Fprintf(w, " %s", lipgloss.NewStyle().Bold(true).Foreground(clr).Render("> "+a.label))
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/anotherhadi/ilovetui"
|
||||
"github.com/anotherhadi/usbguard-tui/internal/guard"
|
||||
)
|
||||
|
||||
@@ -57,12 +58,11 @@ func New() Model {
|
||||
|
||||
l.Styles = list.DefaultStyles(true)
|
||||
filterStyles := textinput.DefaultStyles(true)
|
||||
filterStyles.Focused.Prompt = filterStyles.Focused.Prompt.Foreground(colorAccent)
|
||||
filterStyles.Blurred.Prompt = filterStyles.Blurred.Prompt.Foreground(colorAccent)
|
||||
filterStyles.Focused.Prompt = filterStyles.Focused.Prompt.Foreground(ilovetui.S.Primary)
|
||||
filterStyles.Blurred.Prompt = filterStyles.Blurred.Prompt.Foreground(ilovetui.S.Primary)
|
||||
l.Styles.Filter = filterStyles
|
||||
|
||||
h := help.New()
|
||||
h.Styles = help.DefaultStyles(true)
|
||||
h := ilovetui.NewHelp()
|
||||
|
||||
rulesManaged := guard.IsRulesManaged()
|
||||
notice := ""
|
||||
@@ -303,11 +303,11 @@ func (m Model) renderActionSelect() string {
|
||||
innerW := m.actionListInnerWidth()
|
||||
|
||||
title := popupTitleStyle.Foreground(color).Width(innerW).Render(dev.Name)
|
||||
hint := lipgloss.NewStyle().Foreground(colorMuted).Width(innerW).Render("↑↓ navigate enter confirm esc cancel")
|
||||
hint := lipgloss.NewStyle().Foreground(ilovetui.S.Muted).Width(innerW).Render("↑↓ navigate enter confirm esc cancel")
|
||||
|
||||
parts := []string{title, m.actionList.View(), ""}
|
||||
if m.rulesManaged {
|
||||
nixosHint := lipgloss.NewStyle().Foreground(colorMuted).Width(innerW).Render("[NixOS: perm rules printed on exit]")
|
||||
nixosHint := lipgloss.NewStyle().Foreground(ilovetui.S.Muted).Width(innerW).Render("[NixOS: perm rules printed on exit]")
|
||||
parts = append(parts, nixosHint)
|
||||
}
|
||||
parts = append(parts, hint)
|
||||
|
||||
+13
-23
@@ -4,49 +4,39 @@ import (
|
||||
"image/color"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/anotherhadi/ilovetui"
|
||||
"github.com/anotherhadi/usbguard-tui/internal/guard"
|
||||
)
|
||||
|
||||
var (
|
||||
colorAllowed color.Color = lipgloss.Color("28")
|
||||
colorAllowedSelected color.Color = lipgloss.Color("42")
|
||||
colorBlocked color.Color = lipgloss.Color("124")
|
||||
colorBlockedSelected color.Color = lipgloss.Color("196")
|
||||
colorRejected color.Color = lipgloss.Color("130")
|
||||
colorRejectedSelected color.Color = lipgloss.Color("214")
|
||||
colorMuted color.Color = lipgloss.Color("240")
|
||||
colorAccent color.Color = lipgloss.Color("99")
|
||||
)
|
||||
|
||||
var statusColors = map[guard.Status]color.Color{
|
||||
guard.Allowed: colorAllowed,
|
||||
guard.Blocked: colorBlocked,
|
||||
guard.Rejected: colorRejected,
|
||||
guard.Allowed: ilovetui.S.Success,
|
||||
guard.Blocked: ilovetui.S.Error,
|
||||
guard.Rejected: ilovetui.S.Warning,
|
||||
}
|
||||
|
||||
var statusColorsSelected = map[guard.Status]color.Color{
|
||||
guard.Allowed: colorAllowedSelected,
|
||||
guard.Blocked: colorBlockedSelected,
|
||||
guard.Rejected: colorRejectedSelected,
|
||||
guard.Allowed: ilovetui.S.Success,
|
||||
guard.Blocked: ilovetui.S.Error,
|
||||
guard.Rejected: ilovetui.S.Warning,
|
||||
}
|
||||
|
||||
var (
|
||||
headerStyle = lipgloss.NewStyle().
|
||||
Bold(true).
|
||||
Foreground(colorAccent).
|
||||
Foreground(ilovetui.S.Primary).
|
||||
PaddingLeft(1)
|
||||
|
||||
daemonActiveStyle = lipgloss.NewStyle().Foreground(colorAllowedSelected)
|
||||
daemonOtherStyle = lipgloss.NewStyle().Foreground(colorMuted)
|
||||
daemonActiveStyle = lipgloss.NewStyle().Foreground(ilovetui.S.Success)
|
||||
daemonOtherStyle = lipgloss.NewStyle().Foreground(ilovetui.S.Muted)
|
||||
|
||||
mutedStyle = lipgloss.NewStyle().Foreground(colorMuted)
|
||||
mutedStyle = lipgloss.NewStyle().Foreground(ilovetui.S.Muted)
|
||||
|
||||
popupStyle = lipgloss.NewStyle().
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(colorAccent).
|
||||
BorderForeground(ilovetui.S.Primary).
|
||||
Padding(1, 3)
|
||||
|
||||
popupTitleStyle = lipgloss.NewStyle().Bold(true).MarginBottom(1)
|
||||
|
||||
warnStyle = lipgloss.NewStyle().Foreground(colorRejected)
|
||||
warnStyle = lipgloss.NewStyle().Foreground(ilovetui.S.Warning)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user