Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ bg = #0D171F
bg_alt = #252E35
border = #5F6468
highlight = #AFCFFF
backdrop = #3E464C
```
<!-- /design/build:theme-conf -->

Expand Down
15 changes: 14 additions & 1 deletion design/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var paletteFields = []struct{ token, field string }{
{"primary", "Primary"}, {"accent", "Accent"}, {"success", "Success"},
{"warning", "Warning"}, {"danger", "Danger"}, {"text", "Text"},
{"dim", "Dim"}, {"subtle", "Subtle"}, {"bg", "Bg"}, {"bg_alt", "BgAlt"},
{"border", "Border"}, {"highlight", "Highlight"},
{"border", "Border"}, {"highlight", "Highlight"}, {"backdrop", "Backdrop"},
}

// tailwindNames renames tokens whose name clashes with a Tailwind utility
Expand Down Expand Up @@ -334,6 +334,19 @@ func renderPalette(t *Tokens) ([]byte, error) {
{"tui-col-earned", "ColEarned"},
{"tui-hero-rows", "HeroRows"},
{"tui-hero-rows-compact", "HeroRowsCompact"},
{"tui-modal-width", "ModalWidth"},
{"tui-modal-indent", "ModalIndent"},
{"tui-modal-label", "ModalLabel"},
{"tui-suggest-width", "SuggestWidth"},
{"tui-suggest-rows", "SuggestRows"},
{"tui-confirm-width", "ConfirmWidth"},
{"tui-keys-col", "KeysCol"},
{"tui-keys-cap", "KeysCap"},
{"tui-keys-gap", "KeysGap"},
{"tui-keys-cols", "KeysCols"},
{"tui-modal-min-width", "ModalMinWidth"},
{"tui-strip-min", "StripMin"},
{"tui-field-width", "FieldWidth"},
} {
v, err := integer(t.Spacing, c.token)
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions design/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{ "name": "bg_alt", "value": "#252E35", "usage": "Selected row, modal fields, panels and cards. Aether's lighter_bg. Tailwind name: bgalt." },
{ "name": "border", "value": "#5F6468", "usage": "Rules and box borders on bg (3:1). Not for text. Aether's muted. Tailwind name: line." },
{ "name": "highlight", "value": "#AFCFFF", "usage": "Wordmark, the elapsed-time digits, emphasis in headings. Aether's bright_blue." },
{ "name": "backdrop", "value": "#3E464C", "usage": "TUI: the screen behind a modal, redrawn as plain text in this colour on bg. It's inactive, so WCAG 1.4.3 exempts it (1.88:1). An aliasOS theme, or a theme.conf that sets bg or border without a backdrop, gets border mixed 60% over bg." },
{ "name": "surface", "value": "#111D26", "usage": "Landing page only: raised cards and the screenshot body, one step above bg." },
{ "name": "code_bg", "value": "#0A1319", "usage": "Landing page only: code blocks, one step below bg." },
{ "name": "kbd_fill", "value": "rgba(255,255,255,0.03)", "usage": "Landing page only: the faint fill inside key caps." }
Expand Down Expand Up @@ -75,6 +76,19 @@
{ "name": "tui-detail-note-rows", "value": 3, "usage": "TUI: the most rows an entry's notes take in the detail pane; longer notes end in an ellipsis." },
{ "name": "tui-hero-rows", "value": 6, "usage": "TUI: rows the wide Timers hero takes, borders included: four rows for the label, task, place and meta line beside three rows of block digits." },
{ "name": "tui-hero-rows-compact", "value": 4, "usage": "TUI: rows the compact Timers hero takes, borders included: the task and elapsed time, then the place and today's total." },
{ "name": "tui-modal-width", "value": 70, "usage": "TUI: a form modal's width, borders included (New timer, Edit entry, the client and project forms). A narrower body gets a modal as wide as the body." },
{ "name": "tui-modal-indent", "value": 3, "usage": "TUI: blank columns inside a modal's border before its labels and buttons, and after its fields." },
{ "name": "tui-modal-label", "value": 11, "usage": "TUI: a form modal's label column (Task, Client, Rate ($/h)). The focus mark (glyph-cursor) follows it, then the field." },
{ "name": "tui-suggest-width", "value": 30, "usage": "TUI: the suggestions box under a Client or Project field, borders included; never wider than the field." },
{ "name": "tui-suggest-rows", "value": 5, "usage": "TUI: the most suggestions the box shows at once; the arrow keys scroll through the rest." },
{ "name": "tui-confirm-width", "value": 56, "usage": "TUI: the delete confirm's width, borders included." },
{ "name": "tui-keys-col", "value": 28, "usage": "TUI: one column of the ? keys sheet: the key cap, a space and its label." },
{ "name": "tui-keys-cap", "value": 11, "usage": "TUI: the key-cap column in the ? keys sheet, room for the shift+tab cap." },
{ "name": "tui-keys-gap", "value": 2, "usage": "TUI: blank columns between the ? keys sheet's columns." },
{ "name": "tui-keys-cols", "value": 3, "usage": "TUI: the most columns the ? keys sheet uses; it drops to fewer when the body is too narrow for them." },
{ "name": "tui-modal-min-width", "value": 20, "usage": "TUI: the narrowest a modal gets, border included, however narrow the body is." },
{ "name": "tui-strip-min", "value": 8, "usage": "TUI: the narrowest a form field's bg_alt strip gets in a modal." },
{ "name": "tui-field-width", "value": 44, "usage": "TUI: a form field's width when the form opens; the modal sets it to its strip's width each time it draws." },
{ "name": "tui-min-width", "value": 64, "usage": "TUI: the narrowest terminal notch draws, in cells, measured from the views: the widest fixed line is the Projects tab's at 57 cells, 61 with the two margins; the compact Timers range chips need 48. Narrower terminals get a centred \"Terminal too small\" message." },
{ "name": "tui-min-height", "value": 22, "usage": "TUI: the shortest terminal notch draws, in rows: the chrome (4), the body's top and bottom padding (2), the compact Timers screen's fixed rows (14) and two list rows (a day header and the selected entry). A wide terminal this short gets the compact layout, since the wide one needs 23 rows (see tui-wide). Shorter terminals get a centred \"Terminal too small\" message." },
{ "name": "tui-chrome-rows", "value": 4, "usage": "TUI: rows taken by the chrome: the tab bar and its rule at the top, and a rule and the hotkey and status line at the bottom (measured from their real output). Content gets the rest." },
Expand Down Expand Up @@ -113,7 +127,7 @@
"glyph": {
"tokens": [
{ "name": "glyph-wordmark", "value": "◷", "usage": "The mark before the notch wordmark." },
{ "name": "glyph-cursor", "value": "▌", "usage": "The selected row's cursor in the TUI gutter, in primary." },
{ "name": "glyph-cursor", "value": "▌", "usage": "The selected row's cursor in the TUI gutter, in primary; also the focus mark before a form field or button, and the mark on the selected suggestion (in bg on primary)." },
{ "name": "glyph-live", "value": "●", "usage": "The dot in the footer: in the running pill, and in subtle when idle." },
{ "name": "glyph-unbilled", "value": "○", "usage": "Status: not invoiced yet, in subtle." },
{ "name": "glyph-invoiced", "value": "◐", "usage": "Status: invoiced, not paid, in accent." },
Expand All @@ -124,17 +138,19 @@
"contrast": {
"pairs": [
{ "fg": "text", "bg": "bg", "min": 4.5, "usage": "Body text." },
{ "fg": "text", "bg": "bg_alt", "min": 4.5, "usage": "Text on the selected row, fields and panels." },
{ "fg": "text", "bg": "bg_alt", "min": 4.5, "usage": "Text on the selected row, in modal fields, on secondary buttons and on key caps." },
{ "fg": "dim", "bg": "bg", "min": 4.5, "usage": "Secondary text." },
{ "fg": "dim", "bg": "bg_alt", "min": 4.5, "usage": "Secondary text on the selected row." },
{ "fg": "subtle", "bg": "bg", "min": 4.5, "usage": "Hints and key labels." },
{ "fg": "subtle", "bg": "bg_alt", "min": 4.5, "usage": "Hints in fields and on the selected row." },
{ "fg": "subtle", "bg": "bg_alt", "min": 4.5, "usage": "Placeholders in modal fields (\"now\", \"optional\") and hints on the selected row." },
{ "fg": "primary", "bg": "bg", "min": 4.5, "usage": "Day headers in the Timers list and the active tab's underline." },
{ "fg": "accent", "bg": "bg", "min": 4.5, "usage": "Field labels, links, and invoiced status (◐) in the Timers list." },
{ "fg": "success", "bg": "bg", "min": 4.5, "usage": "Paid and running status, the hero's elapsed time and status messages." },
{ "fg": "warning", "bg": "bg", "min": 4.5, "usage": "Section titles and invoiced status in Reports, and the Timers hero's unbilled total." },
{ "fg": "danger", "bg": "bg", "min": 4.5, "usage": "Errors and delete actions." },
{ "fg": "danger", "bg": "bg_alt", "min": 4.5, "usage": "Field errors inside modals." },
{ "fg": "danger", "bg": "bg_alt", "min": 4.5, "usage": "The Delete entry button in the edit modal." },
{ "fg": "bg", "bg": "danger", "min": 4.5, "usage": "The Delete button in a delete confirm." },
{ "fg": "backdrop", "bg": "bg", "min": 1, "usage": "The dimmed screen behind a modal. Inactive, so exempt from 1.4.3; listed so the table shows every pair." },
{ "fg": "highlight", "bg": "bg", "min": 4.5, "usage": "Wordmark and elapsed time." },
{ "fg": "bg", "bg": "primary", "min": 4.5, "usage": "Primary button label and the active range chip." },
{ "fg": "bg", "bg": "success", "min": 4.5, "usage": "Running pill label." },
Expand Down
23 changes: 23 additions & 0 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,29 @@ func (d *DB) GetRunningEntry() (*model.Entry, error) {
return entries[0], nil
}

// GetEntry returns the entry id with its project and client, or nil when
// there's no such entry.
func (d *DB) GetEntry(id int64) (*model.Entry, error) {
rows, err := d.sql.Query(
`SELECT e.id, e.project_id, e.task, e.start_time, e.end_time,
e.invoiced, e.paid, e.notes, e.created_at,
p.id, p.client_id, p.name, p.created_at,
c.id, c.name, c.hourly_rate, c.created_at
FROM entries e
JOIN projects p ON p.id = e.project_id
JOIN clients c ON c.id = p.client_id
WHERE e.id = ?`, id)
if err != nil {
return nil, err
}
defer rows.Close()
entries, err := scanEntries(rows)
if err != nil || len(entries) == 0 {
return nil, err
}
return entries[0], nil
}

// ListEntries lists entries with optional filters. Pass zero values to skip a filter.
// dateFrom/dateTo format: "2006-01-02"
func (d *DB) ListEntries(projectID int64, dateFrom, dateTo string, includeRunning bool) ([]*model.Entry, error) {
Expand Down
26 changes: 26 additions & 0 deletions internal/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,3 +1398,29 @@ func TestUpdate_DeletedRowIsNotFound(t *testing.T) {
t.Errorf("UpdateProject after delete: err = %v, want ErrNotFound", err)
}
}

func TestGetEntry(t *testing.T) {
d := newTestDB(t)
c, _ := d.CreateClient("Acme", 95)
p, _ := d.CreateProject(c.ID, "Web")
start := time.Now().Add(-time.Hour).Truncate(time.Second)
e, err := d.AddEntry(p.ID, "Logo", "notes", start, nil)
if err != nil {
t.Fatal(err)
}
got, err := d.GetEntry(e.ID)
if err != nil || got == nil {
t.Fatalf("GetEntry = %v, %v", got, err)
}
if got.Task != "Logo" || got.Notes != "notes" || !got.StartTime.Equal(start) || got.EndTime != nil ||
got.Project == nil || got.Project.Name != "Web" || got.Project.Client == nil || got.Project.Client.Name != "Acme" {
t.Errorf("GetEntry = %+v, want the entry with its project and client", got)
}
if got, err := d.GetEntry(e.ID + 100); got != nil || err != nil {
t.Errorf("GetEntry(missing) = %v, %v; want nil, nil", got, err)
}
d.Close()
if _, err := d.GetEntry(e.ID); err == nil {
t.Error("GetEntry on a closed database should fail")
}
}
20 changes: 20 additions & 0 deletions internal/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Palette struct {
BgAlt lipgloss.Color
Border lipgloss.Color
Highlight lipgloss.Color
// Backdrop is the text colour of the screen behind a modal: inactive,
// so it's meant to sit back, not to pass 4.5:1.
Backdrop lipgloss.Color
}

// Default, the built-in palette, is generated from design/tokens.json into
Expand Down Expand Up @@ -175,6 +178,7 @@ func applyOverridesTo(base Palette, path string) Palette {
}
defer f.Close()

set := map[string]bool{}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
Expand All @@ -192,8 +196,15 @@ func applyOverridesTo(base Palette, path string) Palette {
}
if ptr := p.fieldPtr(key); ptr != nil {
*ptr = lipgloss.Color(val)
set[key] = true
}
}
// The backdrop follows the theme: a theme.conf that changes bg or
// border without its own backdrop gets one mixed from them, as every
// other theme's is, rather than keeping the base's.
if !set["backdrop"] && (set["bg"] || set["border"]) {
p.Backdrop = blend(string(p.Bg), string(p.Border), 0.6)
}

return p
}
Expand Down Expand Up @@ -226,6 +237,8 @@ func (p *Palette) fieldPtr(key string) *lipgloss.Color {
return &p.Border
case "highlight":
return &p.Highlight
case "backdrop":
return &p.Backdrop
}
return nil
}
Expand Down Expand Up @@ -387,6 +400,13 @@ func paletteFromOSTheme(kv map[string]string) (Palette, bool) {
*c = legible(*c, fg, 4.5, bg, string(p.BgAlt))
}
p.Border = legible(p.Border, fg, 3, bg)
// The screen behind a modal: the border mixed most of the way over bg,
// as Default's backdrop is. It's inactive text, so it isn't lifted.
if v, ok := pickHex(kv, "backdrop"); ok {
p.Backdrop = lipgloss.Color(v)
} else {
p.Backdrop = blend(bg, string(p.Border), 0.6)
}
return p, true
}

Expand Down
26 changes: 25 additions & 1 deletion internal/theme/theme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ func TestLoadFrom_AllKnownKeys(t *testing.T) {
"bg=#999999\n"+
"bg_alt=#aaaaaa\n"+
"border=#bbbbbb\n"+
"highlight=#cccccc\n")
"highlight=#cccccc\n"+
"backdrop=#dddddd\n")

p := LoadFrom(path)
want := Palette{
Primary: "#111111", Accent: "#222222", Success: "#333333",
Warning: "#444444", Danger: "#555555", Text: "#666666",
Dim: "#777777", Subtle: "#888888", Bg: "#999999",
BgAlt: "#aaaaaa", Border: "#bbbbbb", Highlight: "#cccccc",
Backdrop: "#dddddd",
}
if p != want {
t.Errorf("LoadFrom = %+v, want %+v", p, want)
Expand Down Expand Up @@ -235,6 +237,9 @@ func TestPaletteFromOSTheme_RichFormatUsesNamedShades(t *testing.T) {
Subtle: "#8a9aa6", Border: "#5f6468", BgAlt: "#252e35",
Success: "#99c2ed", Warning: "#a4cbf7", Danger: "#c79ea9",
Accent: "#9dc6e9", Highlight: "#afcfff",
// No backdrop key: border mixed 60% over bg, about Default's
// #3E464C.
Backdrop: "#3e454a",
}
if p != want {
t.Errorf("paletteFromOSTheme = %+v, want %+v", p, want)
Expand Down Expand Up @@ -627,3 +632,22 @@ func TestCheckReload_ReturnsToStateDirAfterSwapWindow(t *testing.T) {
t.Errorf("Colors.Primary = %v, want #60a0e0 from the state theme", Colors.Primary)
}
}

// A theme.conf that changes bg (or border) without a backdrop gets one
// mixed from them, like every other theme, not the default's: a light bg
// mustn't keep a backdrop meant for a dark one. It's the rule aliasOS
// themes use.
func TestLoadFrom_BackdropFollowsBg(t *testing.T) {
dir := t.TempDir()
p := LoadFrom(writeConfig(t, dir, "bg=#ffffff\n"))
if want := blend("#ffffff", string(Default.Border), 0.6); p.Backdrop != want {
t.Errorf("backdrop = %v, want %v mixed from the new bg", p.Backdrop, want)
}
if r := contrastRatio(string(p.Backdrop), string(p.Bg)); r < 1.5 || r > 4.5 {
t.Errorf("backdrop on bg = %.2f:1, want it dim but visible (inactive text is exempt)", r)
}
p = LoadFrom(writeConfig(t, dir, "bg=#ffffff\nbackdrop=#aaaaaa\n"))
if p.Backdrop != "#aaaaaa" {
t.Errorf("an explicit backdrop = %v, want #aaaaaa kept", p.Backdrop)
}
}
63 changes: 62 additions & 1 deletion internal/theme/tokens_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading