Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
169 changes: 169 additions & 0 deletions native/gockup-lich/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package lich

import (
"image"
"image/color"

"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/unit"

"github.com/lichdotdev/gockup"

"github.com/lichdotdev/lich/native/grimoire"
"github.com/lichdotdev/lich/native/ui"
"github.com/lichdotdev/lich/native/ui/markdown"
)

// app registers the few drawings of cmd/lich-native a fragment cannot compose.
// That is a main package, so they are copies: each names the file it follows.
func (k kit) app() {
k.add("ProviderMark", "a provider's pixel mark in its brand color, as a session's row and header lead with it", func(c *gockup.Ctx, th *ui.Theme) D {
return providerMark(c.Gtx, th, c.Enum("provider"), c.Dp("box"))
}, enum("provider", "", "claude", "codex", "antigravity", "opencode", "omp", "crush", "cursor", "kiro"), num("box", 22, "dp: 22 in a row, 14 in a header"))
k.add("SessionStatus", "the corner of a session's row: working, waiting on the person, done and unread, or nothing; pending is a task not begun", func(c *gockup.Ctx, th *ui.Theme) D {
return sessionStatus(c.Gtx, th, c.Enum("state"))
}, enum("state", "", "idle", "working", "waiting", "done", "pending"))
k.holder("Composer", "the chat's message box: children are its foot, side by side, the attach button first and Send last after a weight=1 Spacer; the first head of them stack over the text instead, full width: the limit's notice, the attached files, the quotes", composer,
str("text", ""), str("placeholder", ""), num("head", 0, "how many of the first children stand over the text"),
flag("shell", "the line runs as a command"), flag("drag", "a file is dragged over the session"))
}

// markColors and markHalf are sidebar_mark.go's.
var markColors = map[string]color.NRGBA{
"claude": {R: 0xd9, G: 0x77, B: 0x57, A: 0xff},
"codex": {R: 0x6e, G: 0x7b, B: 0xff, A: 0xff},
"antigravity": {R: 0x42, G: 0x85, B: 0xf4, A: 0xff},
"kiro": {R: 0x90, G: 0x46, B: 0xff, A: 0xff},
"crush": {R: 0xff, G: 0x5f, B: 0xd2, A: 0xff},
}

const markHalf = 0.35

var marks = map[string]grimoire.Grid{}

func providerMark(gtx C, th *ui.Theme, provider string, box unit.Dp) D {
grid, ok := marks[provider]
if !ok {
grid = grimoire.Mark(provider)
marks[provider] = grid
}
size := image.Pt(gtx.Dp(box), gtx.Dp(box))
if len(grid) == 0 {
return D{Size: size}
}
ink, ok := markColors[provider]
if !ok {
ink = th.Foreground
}
px := max(1, gtx.Dp(1))
defer op.Offset(image.Pt((size.X-len(grid[0])*px)/2, (size.Y-len(grid)*px)/2)).Push(gtx.Ops).Pop()
for y, row := range grid {
for x, cell := range row {
if cell == '.' {
continue
}
fill := ink
if cell == '2' {
fill = ui.Alpha(ink, markHalf)
}
at := image.Pt(x*px, y*px)
paint.FillShape(gtx.Ops, fill, clip.Rect{Min: at, Max: at.Add(image.Pt(px, px))}.Op())
}
}
return D{Size: size}
}

// The corner is sidebar_corner.go's 3x3, on a still step of its motion: the
// snake of a working session, the ring of a waiting one, the whole block.
var (
statusBox = ui.Space(5.5)
statusSide = unit.Dp(16)
statusCells = map[string][9]float64{
"working": {1, 0.10, 0.10, 0.65, 0.35, 0.10, 0.10, 0.10, 0.10},
"waiting": {0.35, 0.65, 1, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10},
"done": {1, 1, 1, 1, 1, 1, 1, 1, 1},
"pending": {0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22},
}
)

// statusSprite is the corner's side in sprite pixels: three cells of three
// with a pixel of gap.
const statusSprite = 11

func sessionStatus(gtx C, th *ui.Theme, state string) D {
size := image.Pt(gtx.Dp(statusBox), gtx.Dp(statusBox))
cells, ok := statusCells[state]
if !ok {
return D{Size: size}
}
tone := map[string]color.NRGBA{"working": th.Primary, "waiting": th.ToneWait, "done": th.TonePass, "pending": th.MutedForeground}[state]
side := max(statusSprite, gtx.Dp(statusSide))
edge := func(i int) int { return (i*side + statusSprite/2) / statusSprite }
defer op.Offset(size.Sub(image.Pt(side, side)).Div(2)).Push(gtx.Ops).Pop()
for i, alpha := range cells {
x, y := i%3*4, i/3*4
paint.FillShape(gtx.Ops, ui.MixOKLab(th.Surface, tone, alpha), clip.Rect(image.Rect(edge(x), edge(y), edge(x+3), edge(y+3))).Op())
}
return D{Size: size}
}

// What chat_view.go and chat_footer.go dress the composer's textarea in.
const (
composerEdgeTint = 0.45
composerFillTint = 0.08
)

var (
composerMax = ui.Space(48)
composerMin = ui.Space(24)
composerPadX = ui.Space(4)
composerPadY = ui.Space(3.5)
composerFootPad = ui.Space(1.5)
)

func composer(c *gockup.Ctx, th *ui.Theme) D {
lean := th.Primary
if c.Bool("shell") {
lean = th.ToneWait
}
tinted := *th
tinted.Palette.Input = ui.MixOKLab(th.Palette.Input, lean, composerFillTint)
ta := tinted.Textarea(editor(c), c.String("placeholder"))
ta.MaxHeight, ta.MinHeight, ta.Radius, ta.Steady = composerMax, composerMin, ui.RadiusLG, true
ta.Size, ta.Leading, ta.PadX, ta.PadY = markdown.BodySize, markdown.BodySize*markdown.LineHeightScale, composerPadX, composerPadY
c.Provide(surfaceKey{}, th.On(tinted.InputFill()))
nodes := c.Children()
n := min(max(int(c.Number("head")), 0), len(nodes))
if n > 0 {
m := op.Record(c.Gtx.Ops)
head := stacked(nodes[:n], layout.Vertical, 0)(spanning(c.Gtx))
call := m.Stop()
ta.MaxHeight += c.Gtx.Metric.PxToDp(head.Size.Y)
ta.Head = func(gtx C) D { call.Add(gtx.Ops); return head }
}
foot := stacked(nodes[n:], layout.Horizontal, 1)
ta.Foot = func(gtx C) D {
return layout.Inset{Left: composerFootPad, Right: composerFootPad, Bottom: composerFootPad}.Layout(gtx, func(gtx C) D { return foot(spanning(gtx)) })
}
d := ta.Layout(c.Gtx)
if c.Bool("drag") {
dashed(c.Gtx, d.Size, ui.RadiusLG, th.Foreground)
return d
}
ui.InsetBorder(c.Gtx, d.Size, c.Gtx.Dp(ui.RadiusLG), th.Over(ui.MixOKLab(th.Palette.Input, lean, composerEdgeTint)))
return d
}

// dashed is chat_attach.go's dragRing.
func dashed(gtx C, size image.Point, radius unit.Dp, ink color.NRGBA) {
ui.DashedRing(gtx, image.Rectangle{Max: size}.Inset(gtx.Dp(1)), radius, dashedWidth, ink, color.NRGBA{})
}

const (
dashedWidth = unit.Dp(1.5)
// dashedOpacity is chat_attach.go's chatGhostOpacity.
dashedOpacity = 0.55
)
Loading
Loading