Skip to content

Commit 98ce5b0

Browse files
cpcloudcursoragent
andcommitted
feat(ui): add easter egg mag mode for order-of-magnitude display
Press `m` to toggle mag mode: all numbers are replaced with their order of magnitude (floor of log10). Dollar signs and other units are preserved, so ,234.23 becomes $🠡 3. Applies to table cells and dashboard spending/budget figures. closes #125 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e3680ac commit 98ce5b0

File tree

6 files changed

+251
-5
lines changed

6 files changed

+251
-5
lines changed

docs/content/development/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Tests live alongside the code they test:
3939
| `internal/app/inline_input_test.go` | Inline text input editing |
4040
| `internal/app/calendar_test.go` | Date picker overlay |
4141
| `internal/app/column_finder_test.go` | Fuzzy column finder |
42+
| `internal/app/mag_test.go` | Mag mode (order-of-magnitude easter egg) |
4243
| `internal/app/notes_test.go` | Note preview overlay |
4344
| `internal/app/vendor_test.go` | Vendor tab operations |
4445
| `internal/app/rows_test.go` | Row building helpers |

internal/app/dashboard.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,14 @@ func (m *Model) dashProjectRows() []dashRow {
639639
budgetText := ""
640640
budgetStyle := m.styles.Money
641641
if p.BudgetCents != nil {
642-
act := data.FormatCompactOptionalCents(p.ActualCents)
643-
bud := data.FormatCompactCents(*p.BudgetCents)
642+
fmtCents := data.FormatCompactCents
643+
fmtOpt := data.FormatCompactOptionalCents
644+
if m.magMode {
645+
fmtCents = magCents
646+
fmtOpt = magOptionalCents
647+
}
648+
act := fmtOpt(p.ActualCents)
649+
bud := fmtCents(*p.BudgetCents)
644650
if act != "" {
645651
budgetText = act + " / " + bud
646652
if p.ActualCents != nil && *p.ActualCents > *p.BudgetCents {
@@ -726,22 +732,26 @@ func (m *Model) dashSpendingLine() string {
726732
if total == 0 {
727733
return ""
728734
}
735+
fmtCents := data.FormatCompactCents
736+
if m.magMode {
737+
fmtCents = magCents
738+
}
729739
var parts []string
730740
if d.ServiceSpendCents > 0 {
731741
parts = append(parts,
732742
m.styles.DashLabel.Render("Maintenance ")+
733-
m.styles.Money.Render(data.FormatCompactCents(d.ServiceSpendCents)))
743+
m.styles.Money.Render(fmtCents(d.ServiceSpendCents)))
734744
}
735745
if d.ProjectSpendCents > 0 {
736746
parts = append(parts,
737747
m.styles.DashLabel.Render("Projects ")+
738-
m.styles.Money.Render(data.FormatCompactCents(d.ProjectSpendCents)))
748+
m.styles.Money.Render(fmtCents(d.ProjectSpendCents)))
739749
}
740750
sep := m.styles.DashLabel.Render(" \u00b7 ")
741751
line := strings.Join(parts, sep)
742752
if d.ServiceSpendCents > 0 && d.ProjectSpendCents > 0 {
743753
line += sep + m.styles.DashLabel.Render("Total ") +
744-
m.styles.Money.Render(data.FormatCompactCents(total))
754+
m.styles.Money.Render(fmtCents(total))
745755
}
746756
return line
747757
}

internal/app/mag.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2026 Phillip Cloud
2+
// Licensed under the Apache License, Version 2.0
3+
4+
package app
5+
6+
import (
7+
"fmt"
8+
"math"
9+
"strconv"
10+
"strings"
11+
12+
"github.com/cpcloud/micasa/internal/data"
13+
)
14+
15+
const magArrow = "\U0001F821" // 🠡
16+
17+
// magValue converts a numeric cell value to order-of-magnitude notation.
18+
// Non-numeric values are returned unchanged. Dollar prefixes are preserved.
19+
func magValue(c cell) string {
20+
value := strings.TrimSpace(c.Value)
21+
if value == "" || value == "\u2014" {
22+
return value
23+
}
24+
25+
// Only transform kinds that carry numeric data.
26+
switch c.Kind {
27+
case cellText, cellMoney, cellReadonly, cellDrilldown:
28+
// Potentially numeric; continue to parsing below.
29+
case cellDate, cellWarranty, cellUrgency, cellNotes, cellStatus:
30+
return value
31+
}
32+
33+
prefix := ""
34+
numStr := value
35+
36+
// Handle negative money: "-$123.45"
37+
if strings.HasPrefix(numStr, "-$") {
38+
prefix = "-$"
39+
numStr = numStr[2:]
40+
} else if strings.HasPrefix(numStr, "$") {
41+
prefix = "$"
42+
numStr = numStr[1:]
43+
}
44+
45+
numStr = strings.ReplaceAll(numStr, ",", "")
46+
47+
f, err := strconv.ParseFloat(numStr, 64)
48+
if err != nil {
49+
return value
50+
}
51+
52+
if f == 0 {
53+
return prefix + magArrow + " 0"
54+
}
55+
56+
mag := int(math.Floor(math.Log10(math.Abs(f))))
57+
return fmt.Sprintf("%s%s %d", prefix, magArrow, mag)
58+
}
59+
60+
// magCents converts a cent amount to magnitude notation (e.g. 523423 → "$🠡 3").
61+
func magCents(cents int64) string {
62+
return magValue(cell{Value: data.FormatCents(cents), Kind: cellMoney})
63+
}
64+
65+
// magOptionalCents converts an optional cent amount to magnitude notation.
66+
func magOptionalCents(cents *int64) string {
67+
if cents == nil {
68+
return ""
69+
}
70+
return magCents(*cents)
71+
}
72+
73+
// magTransformCells returns a copy of the cell grid with numeric values
74+
// replaced by their order-of-magnitude representation.
75+
func magTransformCells(rows [][]cell) [][]cell {
76+
out := make([][]cell, len(rows))
77+
for i, row := range rows {
78+
transformed := make([]cell, len(row))
79+
for j, c := range row {
80+
transformed[j] = cell{
81+
Value: magValue(c),
82+
Kind: c.Kind,
83+
LinkID: c.LinkID,
84+
}
85+
}
86+
out[i] = transformed
87+
}
88+
return out
89+
}

internal/app/mag_test.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright 2026 Phillip Cloud
2+
// Licensed under the Apache License, Version 2.0
3+
4+
package app
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestMagValueMoney(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
value string
16+
want string
17+
}{
18+
{"thousands", "$5,234.23", "$\U0001F821 3"},
19+
{"hundreds", "$500.00", "$\U0001F821 2"},
20+
{"millions", "$1,000,000.00", "$\U0001F821 6"},
21+
{"tens", "$42.00", "$\U0001F821 1"},
22+
{"single digit", "$7.50", "$\U0001F821 0"},
23+
{"sub-dollar", "$0.50", "$\U0001F821 -1"},
24+
{"zero", "$0.00", "$\U0001F821 0"},
25+
{"negative", "-$5.00", "-$\U0001F821 0"},
26+
{"negative large", "-$12,345.00", "-$\U0001F821 4"},
27+
}
28+
for _, tt := range tests {
29+
t.Run(tt.name, func(t *testing.T) {
30+
c := cell{Value: tt.value, Kind: cellMoney}
31+
assert.Equal(t, tt.want, magValue(c))
32+
})
33+
}
34+
}
35+
36+
func TestMagValuePlainNumbers(t *testing.T) {
37+
tests := []struct {
38+
name string
39+
value string
40+
want string
41+
}{
42+
{"integer", "42", "\U0001F821 1"},
43+
{"zero", "0", "\U0001F821 0"},
44+
{"large", "1000000", "\U0001F821 6"},
45+
{"decimal", "3.14", "\U0001F821 0"},
46+
}
47+
for _, tt := range tests {
48+
t.Run(tt.name, func(t *testing.T) {
49+
c := cell{Value: tt.value, Kind: cellReadonly}
50+
assert.Equal(t, tt.want, magValue(c))
51+
})
52+
}
53+
}
54+
55+
func TestMagValueSkipsNonNumeric(t *testing.T) {
56+
tests := []struct {
57+
name string
58+
value string
59+
kind cellKind
60+
}{
61+
{"text", "Kitchen Remodel", cellText},
62+
{"status", "underway", cellStatus},
63+
{"date", "2026-02-12", cellDate},
64+
{"warranty date", "2027-06-15", cellWarranty},
65+
{"urgency date", "2026-03-01", cellUrgency},
66+
{"notes", "Some long note", cellNotes},
67+
{"empty", "", cellText},
68+
{"dash", "\u2014", cellMoney},
69+
}
70+
for _, tt := range tests {
71+
t.Run(tt.name, func(t *testing.T) {
72+
c := cell{Value: tt.value, Kind: tt.kind}
73+
assert.Equal(t, tt.value, magValue(c), "non-numeric value should be unchanged")
74+
})
75+
}
76+
}
77+
78+
func TestMagTransformCells(t *testing.T) {
79+
rows := [][]cell{
80+
{
81+
{Value: "Kitchen Remodel", Kind: cellText},
82+
{Value: "$5,234.23", Kind: cellMoney},
83+
{Value: "3", Kind: cellDrilldown},
84+
},
85+
{
86+
{Value: "Deck", Kind: cellText},
87+
{Value: "$100.00", Kind: cellMoney},
88+
{Value: "0", Kind: cellDrilldown},
89+
},
90+
}
91+
out := magTransformCells(rows)
92+
93+
// Text cells unchanged.
94+
assert.Equal(t, "Kitchen Remodel", out[0][0].Value)
95+
assert.Equal(t, "Deck", out[1][0].Value)
96+
97+
// Money cells transformed.
98+
assert.Equal(t, "$\U0001F821 3", out[0][1].Value)
99+
assert.Equal(t, "$\U0001F821 2", out[1][1].Value)
100+
101+
// Drilldown counts transformed.
102+
assert.Equal(t, "\U0001F821 0", out[0][2].Value)
103+
assert.Equal(t, "\U0001F821 0", out[1][2].Value)
104+
105+
// Original rows are not modified.
106+
assert.Equal(t, "$5,234.23", rows[0][1].Value)
107+
}
108+
109+
func TestMagModeToggle(t *testing.T) {
110+
m := newTestModel()
111+
assert.False(t, m.magMode)
112+
sendKey(m, "m")
113+
assert.True(t, m.magMode)
114+
sendKey(m, "m")
115+
assert.False(t, m.magMode)
116+
}
117+
118+
func TestMagModeWorksInEditMode(t *testing.T) {
119+
m := newTestModel()
120+
m.enterEditMode()
121+
assert.False(t, m.magMode)
122+
sendKey(m, "m")
123+
assert.True(t, m.magMode)
124+
}
125+
126+
func TestMagCents(t *testing.T) {
127+
assert.Equal(t, "$\U0001F821 3", magCents(523423))
128+
assert.Equal(t, "$\U0001F821 2", magCents(50000))
129+
assert.Equal(t, "$\U0001F821 0", magCents(100))
130+
}
131+
132+
func TestMagOptionalCentsNil(t *testing.T) {
133+
assert.Equal(t, "", magOptionalCents(nil))
134+
}
135+
136+
func TestMagOptionalCentsPresent(t *testing.T) {
137+
cents := int64(100000)
138+
assert.Equal(t, "$\U0001F821 3", magOptionalCents(&cents))
139+
}

internal/app/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Model struct {
6464
inlineInput *inlineInputState
6565
undoStack []undoEntry
6666
redoStack []undoEntry
67+
magMode bool // easter egg: display numbers as order-of-magnitude
6768
status statusMsg
6869
projectTypes []data.ProjectType
6970
maintenanceCategories []data.MaintenanceCategory
@@ -289,6 +290,9 @@ func (m *Model) handleCommonKeys(key tea.KeyMsg) (tea.Cmd, bool) {
289290
m.showHouse = !m.showHouse
290291
m.resizeTables()
291292
return nil, true
293+
case "m":
294+
m.magMode = !m.magMode
295+
return nil, true
292296
case "h", "left":
293297
if tab := m.effectiveTab(); tab != nil {
294298
tab.ColCursor = nextVisibleCol(tab.Specs, tab.ColCursor, false)

internal/app/view.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,9 @@ func (m *Model) tableView(tab *Tab) string {
903903
effectiveHeight = 2
904904
}
905905
displayCells := compactMoneyCells(vp.Cells)
906+
if m.magMode {
907+
displayCells = magTransformCells(displayCells)
908+
}
906909
rows := renderRows(
907910
vp.Specs,
908911
displayCells,

0 commit comments

Comments
 (0)