Files
nscan/internal/tui/theme.go
T
mikeandClaude Opus 5.5 c91dbe9f7d Add self-update, release 1.0.2
nscan update installs the newest release from git.micw.org, nscan
update -c only checks; --update and --check-update work as well. The
download lands next to the running binary, is started once with
--version and only then replaces it.

Once a day an ordinary run asks in the background and mentions a newer
release in the title bar and on stderr, only on a terminal and not with
NSCAN_NO_UPDATE_CHECK set. selfupdate.go is goca's copyable template.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 16:25:36 +01:00

83 lines
2.9 KiB
Go

package tui
import (
"strings"
"github.com/charmbracelet/lipgloss"
)
// The mwxcol palette (https://git.micw.org/mike/mwxcol). It defines no
// background, so nscan draws on the terminal's own and uses darker where a
// surface is needed, as the palette's fzf and atuin themes do. Plain text
// keeps the terminal's foreground, which the mwxcol terminal profiles set to
// white.
var (
mwxWhite = lipgloss.Color("#F0F0EA") // normal text
mwxYellow = lipgloss.Color("#F9E2AF") // change, warning
mwxRed = lipgloss.Color("#F38BA8") // error, removal
mwxGreen = lipgloss.Color("#94E2D5") // new, ok
mwxBlue = lipgloss.Color("#B4BEFE") // structure, dates, keys
mwxPink = lipgloss.Color("#F5B2F7") // matches
mwxViolet = lipgloss.Color("#CBA6F7") // accent, pointer
mwxGrey = lipgloss.Color("#AAAABB") // secondary text
mwxDark = lipgloss.Color("#777788") // disabled, offline
mwxDarker = lipgloss.Color("#444455") // separators, selection background
mwxSurface = lipgloss.Color("#2E2E35") // darker at 30% over the terminal background
)
func fg(c lipgloss.Color) lipgloss.Style { return lipgloss.NewStyle().Foreground(c) }
var (
styleText = fg(mwxWhite)
styleBold = styleText.Bold(true)
styleDim = fg(mwxGrey) // labels, secondary text
styleMuted = fg(mwxDark) // offline devices, hints
styleRule = fg(mwxDarker) // separators, empty bar segments
styleHeader = fg(mwxBlue).Bold(true)
styleKey = fg(mwxBlue).Bold(true)
styleTime = fg(mwxBlue)
styleOnline = fg(mwxGreen)
styleNew = fg(mwxGreen).Bold(true)
styleGone = fg(mwxRed)
styleTracked = fg(mwxYellow)
styleWarn = fg(mwxYellow)
styleInfo = fg(mwxGreen)
styleErr = fg(mwxRed).Bold(true)
styleMatch = fg(mwxPink)
styleService = fg(mwxViolet)
styleAccent = fg(mwxViolet)
styleBar = fg(mwxWhite).Background(mwxSurface)
styleBarName = fg(mwxViolet).Background(mwxSurface).Bold(true)
styleBarDim = fg(mwxGrey).Background(mwxSurface)
styleBarWarn = fg(mwxYellow).Background(mwxSurface)
// The selected row looks like fzf's current line: white on darker with a
// violet pointer.
styleSel = fg(mwxWhite).Background(mwxDarker)
styleSelPtr = fg(mwxViolet).Background(mwxDarker).Bold(true)
)
// onSel puts s on the selection background.
func onSel(s lipgloss.Style) lipgloss.Style { return s.Background(mwxDarker) }
// cellStyle colors the table cells of online devices; offline rows are muted.
var cellStyle = [numCols]lipgloss.Style{
colName: styleText,
colIP: styleText,
colMAC: styleDim,
colVendor: styleDim,
colLastSeen: styleTime,
colRTT: styleDim,
colServices: styleService,
}
// progressBar draws a bar of width w with done of total filled.
func progressBar(done, total, w int) string {
filled := 0
if total > 0 {
filled = min(w, w*done/total)
}
return styleAccent.Render(strings.Repeat("█", max(0, filled))) + styleRule.Render(strings.Repeat("░", max(0, w-filled)))
}