PLAN-2026-10-23-DEEP.md's own "Remaining" note for the Cards tab was still true: no in-TUI IssueCard/AdjustCardLimit form, CLI/API only. Round 7 closed the CLI half of this gap; this closes the TUI half. - New modal (services/tui/internal/model/cardform.go, internal/view/cardform.go): press `n` on the Cards tab to issue a card (tenant picker defaulting to the selected row's owner, cardholder/limit/interval/currency fields), `a` to adjust an existing card's limit (pre-filled from the selected row). Submits via two new client.Clients methods (IssueCard/AdjustCardLimit) that call the same gateway RPCs the CLI's `ration card` commands use. On success the form closes and triggers an immediate refresh; on failure (validation or a real RPC rejection) it stays open with the error shown and prior input preserved, so the operator can fix and retry without re-entering everything. - Real bug found live, not by reading code: the field-typing handler only ever appended msg.Runes[0], assuming one KeyMsg per keystroke. bubbletea's input reader batches consecutive printable bytes read in one syscall into a single KeyMsg carrying multiple runes — typing (or pasting) a cardholder name arrived as one such batched message, so every character after the first was silently dropped. Fixed to append every rune in the batch; re-verified with multi-character names/limits typing correctly. Verified live against the real bare-metal 7-service stack (audit-log, ledger-core, auth, tenant-registry, card-issuance, webhook-ingestion, gateway — started individually with inter-service delays, the same round-6/7-documented workaround for this shared box's sibling-agent load), driven through a real pty via tmux send-keys (not code reading): seeded 3 tenants, opened the issue-card form, picked a tenant, typed cardholder "Jane Operator", limit 250000, interval daily, submitted — card appeared in the Cards tab and in `ration status`'s independent CLI output (card_7816bf..., ACTIVE, $2,500.00, daily). Opened adjust-limit on that card, backspaced/retyped the limit to 500000, submitted — `ration status` confirmed $5,000.00 and the correct new Held balance. Checked both error paths live: empty cardholder is rejected client-side before any RPC; a limit request exceeding the tenant's real reserve-floor headroom returns the actual card-issuance rejection into the still-open form. `go build`/`go vet`/ `go test ./...` clean for services/tui; full `make build` (Rust+Go+SDK) clean. Also added scripts/start-individually.sh, a reusable version of the manual individual-service-startup workaround rounds 6/7's build logs already documented ad hoc for this box's contention — same PID-file format as run-demo.sh, so scripts/stop-demo.sh tears it down too (verified: it did). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package view
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
|
||
"github.com/charmbracelet/lipgloss"
|
||
)
|
||
|
||
// FormFieldRow is the gRPC/tea-free shape model.cardForm's fields are
|
||
// converted to before rendering, so CardForm stays a pure data-in/
|
||
// string-out renderer like every other view.* function (see package
|
||
// doc comment).
|
||
type FormFieldRow struct {
|
||
Label string
|
||
Value string
|
||
Picker bool
|
||
Focused bool
|
||
}
|
||
|
||
var formBoxStyle = lipgloss.NewStyle().
|
||
Border(lipgloss.RoundedBorder()).
|
||
BorderForeground(colorAccent).
|
||
Padding(1, 2)
|
||
|
||
var formLabelStyle = lipgloss.NewStyle().Foreground(colorMuted)
|
||
var formValueStyle = lipgloss.NewStyle().Foreground(colorFg)
|
||
var formFocusedValueStyle = lipgloss.NewStyle().Foreground(colorFg).Background(colorSelected).Bold(true)
|
||
|
||
// CardForm renders the TUI's one interactive modal — the "issue card"/
|
||
// "adjust limit" form (model/cardform.go) — as a bordered box over the
|
||
// Cards tab. infoLine is shown read-only above the fields when non-empty
|
||
// (the adjust-limit form's "which card" context); errMsg, when non-empty,
|
||
// is shown below the fields in the same error color every other tab
|
||
// already uses for a connection error.
|
||
func CardForm(fields []FormFieldRow, infoLine, errMsg string, submitting bool) string {
|
||
var b strings.Builder
|
||
|
||
if infoLine != "" {
|
||
b.WriteString(MutedStyle.Render(infoLine))
|
||
b.WriteString("\n\n")
|
||
}
|
||
|
||
for _, f := range fields {
|
||
valueStyle := formValueStyle
|
||
cursor := " "
|
||
if f.Focused {
|
||
valueStyle = formFocusedValueStyle
|
||
cursor = "›"
|
||
}
|
||
value := f.Value
|
||
if value == "" {
|
||
value = " "
|
||
}
|
||
if f.Picker {
|
||
value = "‹ " + value + " ›"
|
||
}
|
||
b.WriteString(fmt.Sprintf("%s %s %s\n", cursor, formLabelStyle.Render(padCell(f.Label, 32)), valueStyle.Render(value)))
|
||
}
|
||
|
||
if submitting {
|
||
b.WriteString("\n")
|
||
b.WriteString(MutedStyle.Render("submitting…"))
|
||
}
|
||
if errMsg != "" {
|
||
b.WriteString("\n")
|
||
b.WriteString(ErrorStyle.Render("error: " + errMsg))
|
||
}
|
||
|
||
return formBoxStyle.Render(b.String())
|
||
}
|