diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 6bc5889..521b59c 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -6026,3 +6026,59 @@ button.tile:hover { .asm-load .hint { margin: 0; } + +/* Terminal and keyboard */ +.node .term-screen { + fill: #050807; + stroke: #1f2a24; +} + +.node .term-text { + fill: #6ff0a0; + font-family: var(--font-mono); + font-size: 11px; + white-space: pre; + pointer-events: none; +} + +.node .term-cursor { + fill: #6ff0a0; + opacity: 0.7; + animation: term-blink 1s steps(1) infinite; + pointer-events: none; +} + +@keyframes term-blink { + 50% { + opacity: 0; + } +} + +.node .kb-body.typing { + stroke: var(--accent); + stroke-width: 2; +} + +.node .kb-keys rect { + fill: #232c38; + stroke: #3b4554; + stroke-width: 1; +} + +.node .kb-state { + fill: var(--muted); + font-size: 9px; + pointer-events: none; +} + +.node .kb-body.typing ~ .kb-state { + fill: var(--accent); +} + +.node .kb-queue { + fill: var(--text); + font-family: var(--font-mono); + font-size: 11px; + white-space: pre; + pointer-events: none; +} diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index 31e79a6..d570d1a 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -11,6 +11,7 @@ import type { CanvasOps, MenuEntry } from '~/composables/useMenu' import { cableInUse, LANE, plugLayout, ribbon, RIBBON_MAX } from '~/lib/logic/cables' import { latchLayout, latchSeam } from '~/lib/logic/latch' import { probeAt } from '~/lib/logic/probes' +import { keyCode } from '~/lib/logic/devices' import { moveParts, moveStart, type MoveStart } from '~/lib/logic/move' import { wirePath, type HopSpan } from '~/lib/draw' import { downloadSheet, printSheet, sheetSvg } from '~/lib/sheet' @@ -711,6 +712,8 @@ function onPointerDown(e: PointerEvent) { } if (e.button !== 0) return root.value!.setPointerCapture(e.pointerId) + // A click anywhere but the keyboard being typed into stops the typing. + if (ed.typingInto.value && (e.target as Element).closest?.('[data-node]')?.getAttribute('data-node') !== ed.typingInto.value) ed.typeInto(null) const link = ed.linking.value const end = link?.queue[link.at] @@ -835,7 +838,7 @@ function onPointerDown(e: PointerEvent) { at: [0, 0], moved: false, node, - toggle: (node.kind === 'input' || !!row) && !multi, + toggle: (node.kind === 'input' || node.kind === 'keyboard' || !!row) && !multi, row, grabbed: selected.value.has(id) ? ed.selection.value.length : 1, } @@ -1170,6 +1173,7 @@ function onPointerUp(e: PointerEvent) { ed.unplugMoved(new Set(d.orig.nodes.keys())) ed.commit(false) } else if (d.toggle && d.row) ed.toggleRow(d.node, d.row) + else if (d.toggle && d.node.kind === 'keyboard') ed.typeInto(d.node.id) else if (d.toggle) ed.toggleInput(d.node) break case 'wire': { @@ -1286,6 +1290,15 @@ function onKey(e: KeyboardEvent) { } // Paused: the pause menu has the keys. if (ed.paused.value) return + // Typing into a keyboard: the keys go there (Esc stops). + if (ed.typingInto.value) { + if (e.key === 'Escape') return ed.typeInto(null) + const code = keyCode(e) + if (code !== null) { + e.preventDefault() + return ed.typeKey(code) + } + } const mod = e.ctrlKey || e.metaKey const key = e.key.toLowerCase() if (e.key === 'ContextMenu' || (e.shiftKey && e.key === 'F10')) { diff --git a/app/components/editor/NodeView.vue b/app/components/editor/NodeView.vue index fe2ed29..f1b94b0 100644 --- a/app/components/editor/NodeView.vue +++ b/app/components/editor/NodeView.vue @@ -3,6 +3,7 @@ import { gateDrawing, sevenSegment } from '~/lib/draw' import { LANE, nameTags, RIBBON_MAX } from '~/lib/logic/cables' import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wide' import { faceTransform, GRID as G, noteLines, noteScale, PANEL_CONTROL_W, portLines, rgbHex, shapeTransform, type Shape } from '~/lib/logic/geometry' +import { keyLabel, TERMINAL_COLS, TERMINAL_LINES } from '~/lib/logic/devices' import type { CircuitNode } from '~/lib/logic/types' const props = defineProps<{ @@ -171,6 +172,25 @@ const faceHex = (inner: string) => sevenSegment([0, 1, 2, 3].reduce((n, i) => n /** The colour of an RGB pixel inside this chip ('' while off). */ const facePx = (inner: string) => rgbHex(fv(inner, 'r'), fv(inner, 'g'), fv(inner, 'b')) const rgbNow = computed(() => (props.node.rgb ? rgbHex(v('r'), v('g'), v('b')) : '')) +// Terminal and keyboard: what the store keeps for this part. +const TERM_CHAR = 6.6 +const termLines = computed(() => { + if (props.node.kind !== 'terminal' || props.ghost) return [] + void ed.devVersion.value + return (ed.screens.value.get(props.node.id) ?? ['']).slice(-TERMINAL_LINES) +}) +const termCursor = computed(() => { + const lines = termLines.value.length ? termLines.value : [''] + return { x: Math.min(TERMINAL_COLS - 1, lines[lines.length - 1]!.length), y: lines.length - 1 } +}) +const kbTyping = computed(() => ed.typingInto.value === props.node.id) +const kbWaiting = computed(() => { + if (props.node.kind !== 'keyboard' || props.ghost) return [] + void ed.devVersion.value + return [...(ed.keyQueues.value.get(props.node.id) ?? [])] +}) +const kbQueue = computed(() => kbWaiting.value.slice(0, 6).map(keyLabel).join('')) +const kbCount = computed(() => (kbWaiting.value.length ? `${kbWaiting.value.length} waiting` : '')) const FACE_SCALE = 0.6 const hexValue = computed(() => [0, 1, 2, 3].reduce((n, i) => n + (v(`b${i}`) << i), 0)) const segments = computed(() => sevenSegment(hexValue.value)) @@ -401,6 +421,30 @@ const title = computed(() => { {{ node.conn && !connType ? 'type missing' : 'no lines' }} + + + + + +