feat(cold-turkey): the writing lock (#162)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Wires #161's goal engine and #160's contract into the app: armed from a corner dot or View ▸ Start Cold Turkey…, enforced by the macOS app-kiosk (7-option presentation combo + fullscreen, restored on completion), readout with hairline + near-goal terracotta, and a completion note fading back into focus. While held: focus exit, reading, new buffers, ⌘W/⌃⌘F/⌘N refused (key-code-matched monitor — character matching is layout/Caps-blind; no .closeItem placement exists), ⌘Q asks once per #163's ruling. Typing continuity holds by construction — lock ⇒ focus freezes the branch under the editor and chrome mounts as overlays only. Arm values type directly (1…1000 words / 1…60 min, defaults 250/5). Nothing persists. Wayfinder map #158 Build S2; suite 620, flip-verified pins.
This commit is contained in:
1 parent
7b6abb5d65
commit
a9e199fce4
16 files changed
+1167
-19
No files matched your search
@@ -7,6 +7,8 @@
|
||||
// the soft caret centering. Panes NEVER push the measure: revealed panels
|
||||
// float above the surface and slide off when hover ends. Animation feel is
|
||||
// the fog's "slide curve" knob — calibrate here if not-calm.
|
||||
// #162 (map #158): the chrome lineage GROWS the Cold Turkey lock — the
|
||||
// corner dot, arm-bar, readout, and completion note live here too.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
@@ -135,6 +137,291 @@ struct FocusOverlayPanel<Content: View>: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Cold Turkey chrome (#162, map #158)
|
||||
|
||||
/// The Cold Turkey seat: one bottom-center position, one lineage — the
|
||||
/// arm-bar before Start, the live readout while locked, the completion
|
||||
/// note on quiet return (never two at once, per the contract render).
|
||||
/// Seat = BARE mono on the focus ground — no chip box; Start's accent
|
||||
/// fill is the only boxed element anywhere in the lineage.
|
||||
struct ColdTurkeySeat: View {
|
||||
@Environment(AppGateState.self) private var gate
|
||||
|
||||
var body: some View {
|
||||
let lock = gate.writingLock
|
||||
ZStack {
|
||||
if lock.showsArmBar, !lock.isLocked {
|
||||
ColdTurkeyArmBar()
|
||||
.transition(.opacity)
|
||||
} else if lock.isLocked, let run = lock.run {
|
||||
ColdTurkeyReadout(run: run, now: lock.now)
|
||||
.transition(.opacity)
|
||||
} else if let note = lock.completionNote {
|
||||
ColdTurkeyNote(text: note)
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 46)
|
||||
.animation(.easeInOut(duration: 0.2), value: lock.isLocked)
|
||||
.animation(.easeInOut(duration: 0.2), value: lock.showsArmBar)
|
||||
.animation(.easeInOut(duration: 1.2), value: lock.completionNote)
|
||||
}
|
||||
}
|
||||
|
||||
/// The arm-bar (#160): minutes|words selector + value stepper/entry +
|
||||
/// Start, quiet and non-modal on the focus ground. Esc dismisses — the
|
||||
/// hidden cancel-action button is the PostEditorView ⌘S rail (key
|
||||
/// equivalents ride the menu machinery, which DOES reach behind the
|
||||
/// hosting view — unlike `.onExitCommand`, the #109 Esc probe).
|
||||
/// Amendment (2026-11-04, live dogfood): the bar carries a chip that
|
||||
/// BLENDS into the focus ground — the ground's own color, the faintest
|
||||
/// token hairline, no shadow. The bare seat let the document text show
|
||||
/// through and obscure the controls; blending, not transparency, is the
|
||||
/// ruling now. The value is directly typeable (± steppers stay for the
|
||||
/// coarse moves); defaults 250 words / 5 minutes.
|
||||
private struct ColdTurkeyArmBar: View {
|
||||
@Environment(AppGateState.self) private var gate
|
||||
@State private var minutes = false
|
||||
/// The typeable value for the selected kind — parsed and clamped at
|
||||
/// every read (Start, steppers, submit), so unsubmitted or garbage
|
||||
/// text can never arm an out-of-range block. Switching kinds resets
|
||||
/// it to that kind's default.
|
||||
@State private var fieldText = String(WritingLockState.ArmScale.words.defaultValue)
|
||||
|
||||
private var scale: WritingLockState.ArmScale {
|
||||
minutes ? .minutes : .words
|
||||
}
|
||||
|
||||
private var value: Int {
|
||||
scale.parse(fieldText)
|
||||
}
|
||||
|
||||
private var goal: WritingGoal {
|
||||
minutes ? .minutes(value) : .words(value)
|
||||
}
|
||||
|
||||
/// Rewrite the field to the clamped value (submit, kind switch).
|
||||
private func commitField() {
|
||||
fieldText = String(value)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 9) {
|
||||
HStack(spacing: 14) {
|
||||
selectorButton("Words", isOn: !minutes) {
|
||||
minutes = false
|
||||
fieldText = String(WritingLockState.ArmScale.words.defaultValue)
|
||||
}
|
||||
selectorButton("Minutes", isOn: minutes) {
|
||||
minutes = true
|
||||
fieldText = String(WritingLockState.ArmScale.minutes.defaultValue)
|
||||
}
|
||||
}
|
||||
HStack(spacing: 10) {
|
||||
stepButton("−") { fieldText = String(scale.clamp(value - scale.step)) }
|
||||
HStack(alignment: .firstTextBaseline, spacing: 7) {
|
||||
TextField("", text: $fieldText)
|
||||
.textFieldStyle(.plain)
|
||||
.font(.system(size: 13, design: DesignTokens.mono))
|
||||
.kerning(0.5)
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundStyle(DesignTokens.foreground)
|
||||
.frame(width: 56)
|
||||
.onSubmit(commitField)
|
||||
Text(minutes ? "MIN" : "WORDS")
|
||||
.font(.system(size: 10, design: DesignTokens.mono))
|
||||
.kerning(0.8)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
stepButton("+") { fieldText = String(scale.clamp(value + scale.step)) }
|
||||
Button("Start") {
|
||||
gate.startWritingLock(goal: goal)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.kerning(0.7)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(DesignTokens.surface)
|
||||
.padding(.horizontal, 16)
|
||||
.frame(height: 28)
|
||||
.background(DesignTokens.accent, in: RoundedRectangle(cornerRadius: 6))
|
||||
}
|
||||
Text("esc dismisses · nothing armed yet")
|
||||
.font(.system(size: 9, design: DesignTokens.mono))
|
||||
.kerning(0.8)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(DesignTokens.muted.opacity(0.7))
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 12)
|
||||
.blendingChip()
|
||||
.background {
|
||||
Button("") { gate.writingLock.showsArmBar = false }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
.opacity(0)
|
||||
.frame(width: 1, height: 1)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Selector tab: mono-10 uppercase, the selected kind carries a 2px
|
||||
/// accent underline (the render's `border-bottom` language).
|
||||
private func selectorButton(_ title: String, isOn: Bool, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
Text(title)
|
||||
.font(.system(size: 10, design: DesignTokens.mono))
|
||||
.kerning(0.8)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(isOn ? DesignTokens.foreground : DesignTokens.muted)
|
||||
.padding(.bottom, 3)
|
||||
.overlay(alignment: .bottom) {
|
||||
if isOn {
|
||||
Rectangle()
|
||||
.fill(DesignTokens.accent)
|
||||
.frame(height: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
/// Bare stepper — no box (ruling 1: Start is the only boxed element).
|
||||
private func stepButton(_ glyph: String, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
Text(glyph)
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.foreground)
|
||||
.frame(width: 26, height: 26)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
/// The live readout while locked: numerals + unit (numerals only — the
|
||||
/// piece title is ruled absent) over the 2px progress hairline. Near
|
||||
/// goal (inside the last 20 %) the numerals flip terracotta.
|
||||
private struct ColdTurkeyReadout: View {
|
||||
let run: WritingGoalRun
|
||||
let now: Date
|
||||
|
||||
private var progress: Double {
|
||||
run.progress(now: now)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let shape = WritingLockState.readout(run, now: now)
|
||||
VStack(spacing: 3) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 7) {
|
||||
Text(shape.numerals)
|
||||
.font(.system(size: 13, design: DesignTokens.mono))
|
||||
.kerning(0.65)
|
||||
.foregroundStyle(
|
||||
WritingLockState.isNearGoal(progress: progress)
|
||||
? DesignTokens.accent.opacity(0.8)
|
||||
: DesignTokens.foreground,
|
||||
)
|
||||
Text(shape.unit)
|
||||
.font(.system(size: 10, design: DesignTokens.mono))
|
||||
.kerning(0.8)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
ZStack(alignment: .leading) {
|
||||
Rectangle()
|
||||
.fill(DesignTokens.foreground.opacity(0.06))
|
||||
.frame(width: 148, height: 2)
|
||||
Rectangle()
|
||||
.fill(DesignTokens.accent)
|
||||
.frame(width: max(0, 148 * progress), height: 2)
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 8)
|
||||
.blendingChip()
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// The completion note: `● 500 words · 14:02`, bare mono, fading ~6 s
|
||||
/// (the fade task lives in the state; the transition lives here).
|
||||
private struct ColdTurkeyNote: View {
|
||||
let text: String
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text("●")
|
||||
.foregroundStyle(DesignTokens.accent)
|
||||
Text(text)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.kerning(0.88)
|
||||
.textCase(.uppercase)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.vertical, 8)
|
||||
.blendingChip()
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// The persistent dot (#160 ruling 6): the quiet always-there Cold
|
||||
/// Turkey presence in plain focus — muted 6px pip tucked bottom-right,
|
||||
/// terracotta + label on hover, click opens the arm-bar. Hidden while
|
||||
/// the bar is up or a block runs, and wherever there is nothing prose
|
||||
/// to lock (Posts + drafts + the guest, never Outline — #158 settle 11).
|
||||
struct ColdTurkeyDot: View {
|
||||
@Environment(AppGateState.self) private var gate
|
||||
var model: PostsModel
|
||||
@State private var hover = false
|
||||
|
||||
var body: some View {
|
||||
let lock = gate.writingLock
|
||||
if !lock.isLocked, !lock.showsArmBar, model.canArmWritingLock {
|
||||
Button {
|
||||
lock.showsArmBar = true
|
||||
} label: {
|
||||
HStack(spacing: 8) {
|
||||
Circle()
|
||||
.fill(hover ? DesignTokens.accent : DesignTokens.muted)
|
||||
.frame(width: 6, height: 6)
|
||||
if hover {
|
||||
Text("Cold Turkey")
|
||||
.font(.system(size: 10, design: DesignTokens.mono))
|
||||
.kerning(0.8)
|
||||
.textCase(.uppercase)
|
||||
.foregroundStyle(DesignTokens.muted.opacity(0.85))
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.padding(6)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.onHover { hover = $0 }
|
||||
.animation(.easeInOut(duration: 0.15), value: hover)
|
||||
.padding(.bottom, 12)
|
||||
.padding(.trailing, 14)
|
||||
.help("Start Cold Turkey")
|
||||
.accessibilityLabel("Start Cold Turkey")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The 2026-11-04 dogfood amendment's chip, ONE definition for the
|
||||
/// seat's three surfaces (arm-bar, readout, note): the focus ground's
|
||||
/// own color + the token hairline (the faintest line the palette has),
|
||||
/// no shadow — blending, not transparency. Padding stays per-site.
|
||||
private extension View {
|
||||
func blendingChip() -> some View {
|
||||
background(DesignTokens.background, in: RoundedRectangle(cornerRadius: DesignTokens.radius))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
||||
.strokeBorder(DesignTokens.border),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Soft caret centering (#21)
|
||||
|
||||
/// Soft caret centering (the Neo input, softened): keep the caret inside a
|
||||
|
||||
Reference in new issue
Block a user