Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03e09c3c54 | ||
|
|
1d7e0af3cc | ||
|
|
cccadc9a71 | ||
|
|
51337c35ed | ||
|
|
76bbf44144 | ||
|
|
f0b1f38bdc | ||
|
|
650f1d33db |
No files matched your search
@@ -5,6 +5,10 @@ All notable changes to the qqq CLI and its packages. Versions follow [semver](ht
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- The screen saver's Online tile said "nobody around" with two terminals signed in. It now counts signed-in sessions first (the session store's table: sessions active in the last 10 minutes and their users, your own included, "2 sessions · 1 user (you ×2)"), else you plus the people in collaboration presence; it never says nobody is around while you are signed in. The saver also keeps its presence lease on the screen under it (the extension has no idle state), so other clients see you still viewing it instead of gone. A server that stores no sessions and merges presence per user (mock auth) shows both terminals as "1 online · you".
|
||||
- Query in the screen saver looked like a different dog. All sizes are now generated from the drawing on https://www.qrun.io/query/ (`scripts/gen-query-art.mjs`) in its indigo, with a new medium size (25×13 cells, used where there is room) between the large (42×22) and the small (17×9).
|
||||
### Added
|
||||
|
||||
- **F12 shows and hides the Assistant panel** on every screen (Ctrl+G, `:ask` and a click on `12Ask` do
|
||||
@@ -17,6 +21,21 @@ All notable changes to the qqq CLI and its packages. Versions follow [semver](ht
|
||||
assistant's markdown as blocks with numbered links, one per target (a filter on the primary key is
|
||||
that record; JSON and base64 filters compare by content).
|
||||
|
||||
- **Save as PDF…** is the first entry of the UI's printer picker (record `p`, grid Ctrl+P, `:print`; `:print pdf`
|
||||
saves straight away): the server renders the same record sheet, table list or page (printing
|
||||
`printingRenderToPdf`) and the PDF is saved the way downloads and exports are — the save dialog or, with
|
||||
silent downloads, the download folder, the stamped name (`Customer-Ada-Lovelace_2026-11-01_120301.pdf`), no
|
||||
silent overwrite. The CLI's `qqq print`, `qqq print list` and `qqq print text` take `--to-file [path]` (a
|
||||
folder, a file, or the download folder by default).
|
||||
- Ctrl+P on screens that are not records or grids asks **Print what?**: **Content** (the default: the screen's
|
||||
panels as a document with their titles, without navigation or borders) or **Screen** (the terminal as drawn).
|
||||
- Every printed or saved page carries the app's header (instance name, breadcrumb, server, user, time in the
|
||||
profile's date format) and footer (`qqq ui <version> · <server>` or `qqq <version> · <server>`, a grid's filter
|
||||
and sort, page n of m); the CLI sends the same.
|
||||
- `scripts/print-agent.sh` prints to `~/Downloads` unless `QQQ_PRINT_OUT` says otherwise (`--dir` reports it).
|
||||
- The kernel adds `renderToPdf`, `renderValues`, `canSaveAsPdf`, `chromeValues` and content sections on text
|
||||
prints; the TUI's breadcrumbs moved to `breadcrumbs.ts`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **The assistant's answers render** instead of showing raw markdown, in the TUI panel and in
|
||||
|
||||
@@ -190,10 +190,14 @@ returns at once; `qqq print job status <id> --watch` follows later; `qqq print j
|
||||
job still queued). The printer given with `--printer` (or `qqq printer use`) is remembered per profile.
|
||||
`qqq print list person -w "lastName = Odd" --order -id --columns id,firstName,lastName` prints a table list
|
||||
of the whole result (up to 10,000 rows; `--page 2` for one page), and `some-command | qqq print text --title Log`
|
||||
prints text. In `qqq ui`, **Ctrl+P prints what you see** on every screen: a record sheet, a table list of
|
||||
the grid (all rows or this page), or the screen as text. Tables print only where the server enabled Print
|
||||
prints text. Add `--to-file [folder|file]` to any of them to save the PDF instead of printing (no path: the
|
||||
download folder, with the stamped name exports use). In `qqq ui`, **Ctrl+P prints what you see** on every
|
||||
screen: a record sheet, a table list of the grid (all rows or this page), or a screen's content (or the
|
||||
screen as drawn), each page with the app's header and footer; **Save as PDF…** in the printer picker saves
|
||||
it like a download. Tables print only where the server enabled Print
|
||||
for them (qbit-printing 2.1 `registerAll` enables every table). For local testing without hardware,
|
||||
`scripts/print-agent.sh` runs qqq-print-agent's virtual file printer, which writes each job to a directory.
|
||||
`scripts/print-agent.sh` runs qqq-print-agent's virtual file printer, which writes each job to `~/Downloads`
|
||||
(or `QQQ_PRINT_OUT`; `--dir` shows the folder).
|
||||
|
||||
[TRY-IT.md](TRY-IT.md) walks through every command against the sample server.
|
||||
|
||||
|
||||
@@ -22,10 +22,13 @@
|
||||
*/
|
||||
|
||||
import type { Command } from 'commander'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { FAILED_JOB_STATES, MAX_LIST_ROWS, printFilter, isFinalJobState, jobStateSummary, printProcessName, PRINT_PROCESS_PREFIX, readRememberedPrinter, resolvePrinter, whyNotPrintable, writeRememberedPrinter, type Printer, type PrintJob, type Printing } from '@qrun-io/qqq-core'
|
||||
import { existsSync, readFileSync, statSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { profileNameForServer, formatDateValue, localeFromEnv, readDateSettings, resolveDateSettings, saveDownload, type PrintChrome, type RenderedPdf, type RenderRequest, FAILED_JOB_STATES, MAX_LIST_ROWS, printFilter, isFinalJobState, jobStateSummary, printProcessName, PRINT_PROCESS_PREFIX, readRememberedPrinter, resolvePrinter, whyNotPrintable, writeRememberedPrinter, type Printer, type PrintJob, type Printing } from '@qrun-io/qqq-core'
|
||||
import { EXIT, UsageError, type Context } from '../context.js'
|
||||
import { ORDER_OPTION, countFooter, instantText, positiveInt, type Json } from './shared.js'
|
||||
import { getLogin } from '../session.js'
|
||||
import { CLI_VERSION } from '../version.js'
|
||||
import { ORDER_OPTION, countFooter, instantText, positiveInt, writeDownload, type Json } from './shared.js'
|
||||
import { resolvedFilterFrom, type QueryOptions } from './table.js'
|
||||
|
||||
const JOB_COLUMNS = ['id', 'title', 'status', 'printer', 'copies', 'created', 'message']
|
||||
@@ -45,6 +48,61 @@ function printerRows(printers: Printer[], remembered: string | undefined): Json[
|
||||
return printers.map((p) => ({ default: p.id === remembered ? '*' : '', name: p.name, device: p.device ?? '', status: p.status ?? '', approved: p.approved ? 'yes' : 'no', exposed: p.exposed ? 'yes' : 'no', formats: p.formats.join(' '), id: p.id }))
|
||||
}
|
||||
|
||||
/**
|
||||
* The app's header and footer for what the CLI prints: the instance's branding name (else the
|
||||
* profile), the title, the server (profile and host), the signed-in user, the time in the
|
||||
* profile's date format; the footer `qqq <version> · <server>`.
|
||||
*/
|
||||
async function chromeFor(c: Context, title?: string): Promise<PrintChrome> {
|
||||
const t = c.target
|
||||
let host = t.server
|
||||
try {
|
||||
host = new URL(t.server).host
|
||||
} catch {
|
||||
host = t.server
|
||||
}
|
||||
const server = t.name && t.name !== host && t.name !== profileNameForServer(t.server) ? `${t.name} (${host})` : host
|
||||
let app: string | undefined
|
||||
try {
|
||||
app = ((await c.metaData()) as unknown as { branding?: { appName?: string } }).branding?.appName
|
||||
} catch {
|
||||
app = undefined
|
||||
}
|
||||
const login = await getLogin(t).catch(() => undefined)
|
||||
const user = login && login.kind === 'session' ? String((login.user as { name?: string } | undefined)?.name ?? '') : ''
|
||||
let printedAt = new Date().toISOString()
|
||||
try {
|
||||
printedAt = formatDateValue(printedAt, 'DATE_TIME', resolveDateSettings(readDateSettings(t.name), localeFromEnv()), { withSeconds: false })
|
||||
} catch {
|
||||
// the ISO instant stays
|
||||
}
|
||||
return { app: app ?? t.name, title, server, user: user || undefined, printedAt, footerLeft: `qqq ${CLI_VERSION} · ${server}` }
|
||||
}
|
||||
|
||||
/**
|
||||
* --to-file: renders each document on the server and saves it as downloads are saved: a folder
|
||||
* given gets the stamped default names, a file name given is written as given (one document
|
||||
* only), no path saves to the download folder (`qqq config get download-dir`) with the stamped
|
||||
* name, never overwriting.
|
||||
*/
|
||||
async function saveAsPdf(c: Context, printing: Printing, requests: RenderRequest[], out: string | true, title?: string): Promise<void> {
|
||||
const chrome = await chromeFor(c, title)
|
||||
const path = out === true ? undefined : out
|
||||
const folder = path !== undefined && path !== '-' && existsSync(path) && statSync(path).isDirectory()
|
||||
if (path !== undefined && !folder && requests.length > 1) throw new UsageError('--to-file with several documents takes a folder (or no path: the download folder).')
|
||||
const rows: Json[] = []
|
||||
for (const request of requests) {
|
||||
const pdf: RenderedPdf = await printing.renderToPdf(request, new Date(), chrome)
|
||||
if (pdf.message) c.note(pdf.message)
|
||||
const written = folder ? saveDownload(join(path!, pdf.fileName), pdf.bytes, { explicit: false }) : writeDownload(path, pdf.fileName, pdf.bytes)
|
||||
if (written) {
|
||||
c.note(`Saved ${written} (${pdf.bytes.length.toLocaleString('en-US')} bytes)`)
|
||||
rows.push({ saved: written, bytes: pdf.bytes.length })
|
||||
}
|
||||
}
|
||||
if (path !== '-') c.print({ data: rows, rows, columns: ['saved', 'bytes'] })
|
||||
}
|
||||
|
||||
/** Tables the server offers Print on, from the metadata. */
|
||||
async function printableTables(c: Context): Promise<string[]> {
|
||||
const processes = ((await c.metaData() as unknown as Json).processes ?? {}) as Record<string, unknown>
|
||||
@@ -102,16 +160,18 @@ export function registerPrint(program: Command, ctx: () => Context): void {
|
||||
.option('-c, --copies <n>', 'copies of each record (1-100)', '1')
|
||||
.option('--no-wait', 'return once the jobs are queued')
|
||||
.option('--timeout <seconds>', 'how long to wait for the jobs', '120')
|
||||
.action(async (table: string, ids: string[], options: { printer?: string; copies: string; wait: boolean; timeout: string }) => {
|
||||
.option('--to-file [path]', 'save each record sheet as a PDF instead of printing: a folder, a file (one record), or the download folder')
|
||||
.action(async (table: string, ids: string[], options: { printer?: string; copies: string; wait: boolean; timeout: string; toFile?: string | true }) => {
|
||||
const c = ctx()
|
||||
const printing = await printingOf(c)
|
||||
const tables = await printableTables(c)
|
||||
if (!tables.includes(table)) throw new UsageError(`Print is not enabled for table "${table}" on this server${tables.length ? ` (tables with Print: ${tables.join(', ')})` : ''}.`)
|
||||
if (options.toFile !== undefined) return saveAsPdf(c, printing, ids.map((id) => ({ kind: 'record' as const, table, id })), options.toFile)
|
||||
const copies = positiveInt(options.copies, '--copies')
|
||||
const printer = await choosePrinter(c, printing, options.printer)
|
||||
if (options.printer) writeRememberedPrinter(c.target.name, { id: printer.id, name: printer.name })
|
||||
c.note(`Printing ${ids.length} ${table} record${ids.length === 1 ? '' : 's'} on "${printer.name}"${copies > 1 ? `, ${copies} copies each` : ''} (${printProcessName(table)})`)
|
||||
const jobIds = await printing.print({ table, ids, printer: printer.id, copies })
|
||||
const jobIds = await printing.print({ table, ids, printer: printer.id, copies, chrome: await chromeFor(c) })
|
||||
if (!jobIds.length) throw new Error(`Nothing was printed: no ${table} record ${ids.join(', ')} was found (or you may not see ${ids.length === 1 ? 'it' : 'them'}).`)
|
||||
const jobs = options.wait ? await follow(c, printing, jobIds, positiveInt(options.timeout, '--timeout')) : await printing.jobs({ ids: jobIds })
|
||||
c.print({ data: { printer: { id: printer.id, name: printer.name }, jobs }, rows: jobRows(jobs, c), columns: JOB_COLUMNS, footer: countFooter(jobs.length, 'job', [jobStateSummary(jobs), !options.wait && `follow: qqq print job status ${jobIds.join(' ')} --watch`]) })
|
||||
@@ -134,7 +194,8 @@ export function registerPrint(program: Command, ctx: () => Context): void {
|
||||
.option('--copies <n>', 'copies (1-100)', '1')
|
||||
.option('--no-wait', 'return once the job is queued')
|
||||
.option('--timeout <seconds>', 'how long to wait for the job', '300')
|
||||
.action(async (table: string, options: QueryOptions & { columns?: string; page?: string; pageSize: string; title?: string; orientation: string; paper: string; printer?: string; copies: string; wait: boolean; timeout: string }) => {
|
||||
.option('--to-file [path]', 'save the table list as a PDF instead of printing: a folder, a file, - for stdout, or the download folder')
|
||||
.action(async (table: string, options: QueryOptions & { columns?: string; page?: string; pageSize: string; title?: string; orientation: string; paper: string; printer?: string; copies: string; wait: boolean; timeout: string; toFile?: string | true }) => {
|
||||
const c = ctx()
|
||||
const printing = await printingOf(c)
|
||||
const meta = await c.tableMeta<Json>(table)
|
||||
@@ -148,11 +209,15 @@ export function registerPrint(program: Command, ctx: () => Context): void {
|
||||
const filter = await resolvedFilterFrom(c, { ...options, pageSize: '500' }, meta, columns)
|
||||
const pageSize = positiveInt(options.pageSize, '--page-size')
|
||||
const scope = options.page ? { kind: 'page' as const, skip: (positiveInt(options.page, '--page') - 1) * pageSize, limit: pageSize } : { kind: 'all' as const }
|
||||
if (options.toFile !== undefined) {
|
||||
const described = [printFilter(filter as never), options.search ? `quick "${options.search}"` : ''].filter(Boolean).join(' · ')
|
||||
return saveAsPdf(c, printing, [{ kind: 'list', list: { table, columns, filter: filter as unknown as Record<string, unknown>, scope, title: options.title ?? String(meta.label ?? table), filterDescription: described || undefined, orientation: orientation as 'AUTO', pageSize: paper as 'LETTER', primaryKeyField: String(meta.primaryKeyField ?? 'id') } }], options.toFile, String(meta.label ?? table))
|
||||
}
|
||||
const printer = await choosePrinter(c, printing, options.printer)
|
||||
if (options.printer) writeRememberedPrinter(c.target.name, { id: printer.id, name: printer.name })
|
||||
const described = [printFilter(filter as never), options.search ? `quick "${options.search}"` : ''].filter(Boolean).join(' · ')
|
||||
c.note(`Printing ${scope.kind === 'all' ? 'all rows of' : `page ${options.page} of`} ${meta.label ?? table}${described ? ` where ${described}` : ''} on "${printer.name}"`)
|
||||
const outcome = await printing.printTableList({ table, columns, filter: filter as unknown as Record<string, unknown>, scope, title: options.title ?? String(meta.label ?? table), filterDescription: described || undefined, printer: printer.id, copies: positiveInt(options.copies, '--copies'), orientation: orientation as 'AUTO', pageSize: paper as 'LETTER', primaryKeyField: String(meta.primaryKeyField ?? 'id') })
|
||||
const outcome = await printing.printTableList({ table, columns, filter: filter as unknown as Record<string, unknown>, scope, title: options.title ?? String(meta.label ?? table), filterDescription: described || undefined, printer: printer.id, copies: positiveInt(options.copies, '--copies'), orientation: orientation as 'AUTO', pageSize: paper as 'LETTER', primaryKeyField: String(meta.primaryKeyField ?? 'id'), chrome: await chromeFor(c, String(meta.label ?? table)) })
|
||||
if (outcome.message) c.note(outcome.message)
|
||||
if (!outcome.jobIds.length) throw new Error('The server queued no print job.')
|
||||
const jobs = options.wait ? await follow(c, printing, outcome.jobIds, positiveInt(options.timeout, '--timeout')) : await printing.jobs({ ids: outcome.jobIds })
|
||||
@@ -168,14 +233,16 @@ export function registerPrint(program: Command, ctx: () => Context): void {
|
||||
.option('--copies <n>', 'copies (1-100)', '1')
|
||||
.option('--no-wait', 'return once the job is queued')
|
||||
.option('--timeout <seconds>', 'how long to wait for the job', '120')
|
||||
.action(async (file: string | undefined, options: { title: string; subtitle?: string; landscape?: boolean; printer?: string; copies: string; wait: boolean; timeout: string }) => {
|
||||
.option('--to-file [path]', 'save the text page as a PDF instead of printing: a folder, a file, or the download folder')
|
||||
.action(async (file: string | undefined, options: { title: string; subtitle?: string; landscape?: boolean; printer?: string; copies: string; wait: boolean; timeout: string; toFile?: string | true }) => {
|
||||
const c = ctx()
|
||||
const printing = await printingOf(c)
|
||||
const text = readFileSync(file === undefined || file === '-' ? 0 : file, 'utf8')
|
||||
if (!text.trim()) throw new UsageError('Nothing to print: the text is empty.')
|
||||
if (options.toFile !== undefined) return saveAsPdf(c, printing, [{ kind: 'text', title: options.title, subtitle: options.subtitle, text, orientation: options.landscape ? 'LANDSCAPE' : 'PORTRAIT' }], options.toFile, options.title)
|
||||
const printer = await choosePrinter(c, printing, options.printer)
|
||||
if (options.printer) writeRememberedPrinter(c.target.name, { id: printer.id, name: printer.name })
|
||||
const outcome = await printing.printText({ title: options.title, subtitle: options.subtitle, text, printer: printer.id, copies: positiveInt(options.copies, '--copies'), orientation: options.landscape ? 'LANDSCAPE' : 'PORTRAIT' })
|
||||
const outcome = await printing.printText({ title: options.title, subtitle: options.subtitle, text, printer: printer.id, copies: positiveInt(options.copies, '--copies'), orientation: options.landscape ? 'LANDSCAPE' : 'PORTRAIT', chrome: await chromeFor(c, options.title) })
|
||||
const jobs = options.wait ? await follow(c, printing, outcome.jobIds, positiveInt(options.timeout, '--timeout')) : await printing.jobs({ ids: outcome.jobIds })
|
||||
c.print({ data: { printer: { id: printer.id, name: printer.name }, jobs }, rows: jobRows(jobs, c), columns: JOB_COLUMNS, footer: countFooter(jobs.length, 'job', [jobStateSummary(jobs)]) })
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import type { Command } from 'commander'
|
||||
import { UiApiError, unwrap, type UiApiClient } from '@qrun-io/qqq-ui-api-client'
|
||||
import { Assistant, Collaboration, Printing, missingQBitMessage, runProcess, type ProcessMeta, ExtensionNotInstalledError, OperationInputError, ExtensionRegistry, KNOWN_EXTENSIONS, FilterSyntaxError, OUTPUT_FORMATS, ProcessError, UnsafeFileNameError, defaultTimeZone, type DisplayOptions, applyQuery, callOperation, defaultFormat, extensionRegistry, getMetaData, getTableMetaData, render, type CallInput, type CallResult, type MetaDataDocument, type OutputFormat, type Printable } from '@qrun-io/qqq-core'
|
||||
import { Assistant, Collaboration, Printing, downloadProcessFile, missingQBitMessage, runProcess, type ProcessMeta, ExtensionNotInstalledError, OperationInputError, ExtensionRegistry, KNOWN_EXTENSIONS, FilterSyntaxError, OUTPUT_FORMATS, ProcessError, UnsafeFileNameError, defaultTimeZone, type DisplayOptions, applyQuery, callOperation, defaultFormat, extensionRegistry, getMetaData, getTableMetaData, render, type CallInput, type CallResult, type MetaDataDocument, type OutputFormat, type Printable } from '@qrun-io/qqq-core'
|
||||
import { openRealtimeStream } from '@qrun-io/qqq-ui-api-client'
|
||||
import { CLIENT_CHANNEL, authenticatedFetch, clientFor, currentToken, selectTarget, sessionCookieHeaderFor, target, type Target } from './session.js'
|
||||
|
||||
@@ -190,6 +190,7 @@ export class Context {
|
||||
const outcome = await runProcess({ baseUrl: t.server, fetch: authenticatedFetch(t), meta, values, records: recordIds.length ? { ids: recordIds } : undefined, stepTimeoutMillis: 60000 })
|
||||
return outcome.values
|
||||
},
|
||||
download: (reference) => downloadProcessFile(t.server, authenticatedFetch(t), reference),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { Command, CommanderError } from 'commander'
|
||||
import { Context, EXIT, describeError, io } from './context.js'
|
||||
import { versionText } from './version.js'
|
||||
|
||||
export { buildDescription } from './version.js'
|
||||
export { buildDescription, CLI_VERSION } from './version.js'
|
||||
import { registerApi } from './commands/api.js'
|
||||
import { registerAudit } from './commands/audit.js'
|
||||
import { registerAuth } from './commands/auth.js'
|
||||
|
||||
@@ -14,7 +14,8 @@ import assert from 'node:assert/strict'
|
||||
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
|
||||
import type { AddressInfo } from 'node:net'
|
||||
import { after, before, describe, test } from 'node:test'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { mkdtempSync, readFileSync, readdirSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { runCli, sandbox, startFakeServer, type FakeServer } from './harness.js'
|
||||
|
||||
@@ -24,6 +25,7 @@ interface PrintServer {
|
||||
url: string
|
||||
runs: { process: string; values: J; recordIds?: string }[]
|
||||
lists: { process: string; values: J; recordsParam?: string }[]
|
||||
renders: J[]
|
||||
jobs: Map<string, { status: string[]; title: string; reads: number; message?: string }>
|
||||
close(): Promise<void>
|
||||
}
|
||||
@@ -50,6 +52,7 @@ const CANCEL_META = { name: 'printingCancelSelectedJobs', label: 'Cancel queued
|
||||
async function startPrintServer(): Promise<PrintServer> {
|
||||
const runs: PrintServer['runs'] = []
|
||||
const lists: PrintServer['lists'] = []
|
||||
const renders: PrintServer['renders'] = []
|
||||
const jobs: PrintServer['jobs'] = new Map()
|
||||
const state = new Map<string, { process: string; values: J; recordIds?: string }>()
|
||||
let next = 1
|
||||
@@ -69,10 +72,22 @@ async function startPrintServer(): Promise<PrintServer> {
|
||||
let m: RegExpExecArray | null
|
||||
if (path === '/version') return send(res, 200, { apiVersion: '1.9.0', features: ['metaData', 'tables', 'processes', 'version', 'extensions'], extensions: [{ name: 'printing', version: '2.1.0', pathPrefix: '/qbit/printing' }] })
|
||||
if (path === '/metaData/authentication') return send(res, 200, { type: 'MOCK' })
|
||||
if (path === '/metaData') return send(res, 200, { tables: { person: { name: 'person', label: 'Person' } }, processes: { printingPrintRecords_person: { name: 'printingPrintRecords_person', label: 'Print', tableName: 'person' }, printingCancelSelectedJobs: { name: 'printingCancelSelectedJobs', tableName: 'printing_job' }, printingPrintTableList: { name: 'printingPrintTableList' }, printingPrintText: { name: 'printingPrintText' } }, apps: {} })
|
||||
if (path === '/metaData') return send(res, 200, { tables: { person: { name: 'person', label: 'Person' } }, processes: { printingPrintRecords_person: { name: 'printingPrintRecords_person', label: 'Print', tableName: 'person' }, printingCancelSelectedJobs: { name: 'printingCancelSelectedJobs', tableName: 'printing_job' }, printingPrintTableList: { name: 'printingPrintTableList' }, printingPrintText: { name: 'printingPrintText' }, printingRenderToPdf: { name: 'printingRenderToPdf' } }, apps: {} })
|
||||
if (path === '/metaData/process/printingPrintRecords_person') return send(res, 200, PRINT_META)
|
||||
if (path === '/metaData/process/printingCancelSelectedJobs') return send(res, 200, CANCEL_META)
|
||||
if (path === '/metaData/table/person') return send(res, 200, PERSON_META)
|
||||
if (path === '/metaData/process/printingRenderToPdf') return send(res, 200, { name: 'printingRenderToPdf', label: 'Save as PDF', frontendSteps: [{ name: 'download', label: 'Download', components: [{ type: 'DOWNLOAD_FORM' }], viewFields: [{ name: 'downloadFileName', type: 'STRING', label: 'File' }] }] })
|
||||
if (path === '/processes/printingRenderToPdf/init') {
|
||||
const v = JSON.parse(field(body, 'values') ?? '{}') as J
|
||||
renders.push(v)
|
||||
const name = v.kind === 'RECORD' ? `Person-${v.recordId}` : v.kind === 'LIST' ? 'Person' : String(v.title).replace(/[^A-Za-z0-9]+/g, '-')
|
||||
return send(res, 200, { processUUID: 'render', nextStep: 'download', type: 'COMPLETE', values: { downloadFileName: `${name}.pdf`, serverFilePath: `/tmp/r-${renders.length}.pdf`, ...(v.kind === 'LIST' ? { printingMessage: 'Saved the first 10000 of 12000 rows: the limit is 10000 rows. Narrow the filter to save the rest.' } : {}) } })
|
||||
}
|
||||
if (path.startsWith('/download/')) {
|
||||
res.writeHead(200, { 'Content-Type': 'application/pdf' })
|
||||
res.end(`%PDF-1.7 ${path}`)
|
||||
return
|
||||
}
|
||||
if ((m = /^\/metaData\/process\/(printingPrintTableList|printingPrintText)$/.exec(path))) return send(res, 200, LIST_META(m[1]!))
|
||||
if ((m = /^\/processes\/(printingPrintTableList|printingPrintText)\/init$/.exec(path))) {
|
||||
lists.push({ process: m[1]!, values: JSON.parse(field(body, 'values') ?? '{}') as J, recordsParam: field(body, 'recordsParam') })
|
||||
@@ -132,6 +147,7 @@ async function startPrintServer(): Promise<PrintServer> {
|
||||
url: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
|
||||
runs,
|
||||
lists,
|
||||
renders,
|
||||
jobs,
|
||||
close: () => new Promise<void>((resolve) => { server.closeAllConnections(); server.close(() => resolve()) }),
|
||||
}
|
||||
@@ -249,6 +265,11 @@ describe('qqq print and qqq printer', () => {
|
||||
assert.deepEqual(filter.criteria, [{ fieldName: 'lastName', operator: 'EQUALS', values: ['Odd'] }])
|
||||
assert.deepEqual(filter.orderBys, [{ fieldName: 'id', isAscending: false }])
|
||||
assert.equal(run.values.filterDescription, 'lastName EQUALS Odd')
|
||||
// the app header and footer
|
||||
assert.match(String(run.values.footerLeft), /^qqq \d+\.\d+\.\d+ · 127\.0\.0\.1:\d+$/)
|
||||
assert.match(String(run.values.headerServer), /^127\.0\.0\.1:\d+$/)
|
||||
assert.equal(run.values.headerTitle, 'Person')
|
||||
assert.match(String(run.values.headerPrintedAt), /\d/)
|
||||
})
|
||||
|
||||
test('print list --page prints one page; default columns skip hidden and binary fields; bad options are usage errors', async () => {
|
||||
@@ -271,5 +292,40 @@ describe('qqq print and qqq printer', () => {
|
||||
const empty = await qqq(['print', 'text', '-', '--title', 'Nothing'], printServer.url, ' \n')
|
||||
assert.equal(empty.code, 2)
|
||||
})
|
||||
|
||||
test('--to-file saves record sheets instead of printing: a folder gets stamped names; no job is queued', async () => {
|
||||
const folder = mkdtempSync(join(tmpdir(), 'qqq-cli-pdf-'))
|
||||
const before = printServer.runs.length
|
||||
const result = await qqq(['print', 'person', '1', '2', '--to-file', folder])
|
||||
assert.equal(result.code, 0, result.stderr)
|
||||
const files = readdirSync(folder).sort()
|
||||
assert.equal(files.length, 2)
|
||||
assert.match(files[0]!, /^Person-1_\d{4}-\d{2}-\d{2}_\d{6}\.pdf$/)
|
||||
assert.match(readFileSync(join(folder, files[0]!), 'utf8'), /^%PDF-1\.7 \/download\/Person-1\.pdf/)
|
||||
assert.match(result.stderr, /Saved .*Person-2_\d{4}/)
|
||||
assert.equal(printServer.runs.length, before, 'no print job')
|
||||
assert.deepEqual(printServer.renders.slice(-2).map((r) => [r.kind, r.tableName, r.recordId]), [['RECORD', 'person', '1'], ['RECORD', 'person', '2']])
|
||||
assert.match(String(printServer.renders.at(-1)!.footerLeft), /^qqq \d/)
|
||||
const two = await qqq(['print', 'person', '1', '2', '--to-file', join(folder, 'one.pdf')])
|
||||
assert.equal(two.code, 2)
|
||||
assert.match(two.stderr, /takes a folder/)
|
||||
})
|
||||
|
||||
test('print list --to-file writes the named file as given and shows the limit note; without a path it goes to the download folder', async () => {
|
||||
const folder = mkdtempSync(join(tmpdir(), 'qqq-cli-pdf-'))
|
||||
const named = join(folder, 'people.pdf')
|
||||
const result = await qqq(['print', 'list', 'person', '-w', 'lastName = Odd', '--to-file', named])
|
||||
assert.equal(result.code, 0, result.stderr)
|
||||
assert.match(readFileSync(named, 'utf8'), /^%PDF/)
|
||||
assert.match(result.stderr, /Saved the first 10000 of 12000 rows/)
|
||||
const render = printServer.renders.at(-1)!
|
||||
assert.deepEqual([render.kind, render.scope, render.printingPrinterId], ['LIST', 'ALL', undefined])
|
||||
const downloads = mkdtempSync(join(tmpdir(), 'qqq-cli-dl-'))
|
||||
assert.equal((await qqq(['config', 'set', 'download-dir', downloads])).code, 0)
|
||||
const text = await qqq(['print', 'text', '-', '--title', 'Build log', '--to-file'], printServer.url, 'hello\n')
|
||||
assert.equal(text.code, 0, text.stderr)
|
||||
assert.match(readdirSync(downloads)[0]!, /^Build-log_\d{4}-\d{2}-\d{2}_\d{6}\.pdf$/)
|
||||
assert.equal((await qqq(['config', 'set', 'download-dir', ''])).code, 0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
import type { CallInput, CallResult } from '../api/call.js'
|
||||
import { readConfig, writeConfig } from '../session/profiles.js'
|
||||
import { downloadReference } from '../process/screen.js'
|
||||
import { exportFileName } from '../render/files.js'
|
||||
import type { ExtensionRegistry } from './registry.js'
|
||||
|
||||
export const PRINTING = 'printing'
|
||||
@@ -33,6 +35,8 @@ export const COPIES_FIELD = 'printingCopies'
|
||||
export const JOB_IDS_VALUE = 'printingJobIds'
|
||||
export const TABLE_LIST_PROCESS = 'printingPrintTableList'
|
||||
export const TEXT_PROCESS = 'printingPrintText'
|
||||
/** Renders a record sheet, table list or text page to a PDF download (Save as PDF). */
|
||||
export const RENDER_PROCESS = 'printingRenderToPdf'
|
||||
/** The most rows the server prints in one table list. */
|
||||
export const MAX_LIST_ROWS = 10_000
|
||||
/** "All rows" is the default list choice up to this many rows (or whenever the grid is filtered). */
|
||||
@@ -95,6 +99,8 @@ export interface PrintingTransport {
|
||||
call(id: string, input: CallInput): Promise<CallResult>
|
||||
/** Runs a process to its end with these values and selected record ids; returns its final values. */
|
||||
runProcess(processName: string, options: { values: Record<string, unknown>; recordIds: string[] }): Promise<Record<string, unknown>>
|
||||
/** Fetches a process download (GET /download/{file}); needed for Save as PDF. */
|
||||
download?(reference: { fileName: string; query: Record<string, string> }): Promise<{ bytes: Uint8Array; contentType: string }>
|
||||
}
|
||||
|
||||
interface QueryRecord {
|
||||
@@ -203,6 +209,75 @@ export function canPrintLists(meta: { processes?: Record<string, unknown> } | un
|
||||
return Boolean(meta?.processes?.[TABLE_LIST_PROCESS]) && Boolean(meta?.processes?.[TEXT_PROCESS])
|
||||
}
|
||||
|
||||
/**
|
||||
* The header and footer every printed page carries (printing 0.4.1+ renderers): the app or
|
||||
* instance name, the screen title or breadcrumb, the server, the user and the printed-at time in
|
||||
* the user's date format on top; the client's footer (`qqq ui 1.0.1 · server`), a grid's filter and
|
||||
* sort, and the page number at the bottom.
|
||||
*/
|
||||
export interface PrintChrome {
|
||||
app?: string
|
||||
title?: string
|
||||
server?: string
|
||||
user?: string
|
||||
printedAt?: string
|
||||
footerLeft?: string
|
||||
footerNote?: string
|
||||
}
|
||||
|
||||
/** The process values of a chrome (blank fields left out: the server's defaults apply). */
|
||||
export function chromeValues(chrome: PrintChrome | undefined): Record<string, string> {
|
||||
if (!chrome) return {}
|
||||
const out: Record<string, string> = {}
|
||||
const put = (key: string, value: string | undefined) => {
|
||||
if (value !== undefined && value.trim()) out[key] = value.trim()
|
||||
}
|
||||
put('headerApp', chrome.app)
|
||||
put('headerTitle', chrome.title)
|
||||
put('headerServer', chrome.server)
|
||||
put('headerUser', chrome.user)
|
||||
put('headerPrintedAt', chrome.printedAt)
|
||||
put('footerLeft', chrome.footerLeft)
|
||||
put('footerNote', chrome.footerNote)
|
||||
return out
|
||||
}
|
||||
|
||||
/** One section of a screen's content: a panel's title (blank for none) and its lines. */
|
||||
export interface ContentSection {
|
||||
title: string
|
||||
lines: string[]
|
||||
}
|
||||
|
||||
/** Whether the server can render documents to a PDF download ("Save as PDF"). */
|
||||
export function canSaveAsPdf(meta: { processes?: Record<string, unknown> } | undefined): boolean {
|
||||
return Boolean(meta?.processes?.[RENDER_PROCESS])
|
||||
}
|
||||
|
||||
/** What Save as PDF renders: a record sheet, a table list, or a text page. */
|
||||
export type RenderRequest =
|
||||
| { kind: 'record'; table: string; id: string }
|
||||
| { kind: 'list'; list: Omit<TableListRequest, 'printer' | 'copies'> }
|
||||
| { kind: 'text'; title: string; subtitle?: string; text: string; sections?: ContentSection[]; orientation?: 'PORTRAIT' | 'LANDSCAPE' }
|
||||
|
||||
/** A PDF rendered for the client: the default file name (stamped), the server's name, the bytes, and a note. */
|
||||
export interface RenderedPdf {
|
||||
fileName: string
|
||||
serverName: string
|
||||
bytes: Uint8Array
|
||||
message?: string
|
||||
}
|
||||
|
||||
/** The process values of a render request. */
|
||||
export function renderValues(request: RenderRequest, chrome?: PrintChrome): Record<string, unknown> {
|
||||
const header = chromeValues(chrome)
|
||||
if (request.kind === 'record') return { kind: 'RECORD', tableName: request.table, recordId: request.id, ...header }
|
||||
if (request.kind === 'text') return { kind: 'TEXT', title: request.title, ...(request.subtitle ? { subtitle: request.subtitle } : {}), text: request.text, ...(request.sections?.length ? { sections: JSON.stringify(request.sections) } : {}), orientation: request.orientation ?? 'PORTRAIT', pageSize: 'LETTER', ...header }
|
||||
const values = tableListValues({ ...request.list, printer: '' })
|
||||
delete values[PRINTER_FIELD]
|
||||
delete values[COPIES_FIELD]
|
||||
return { kind: 'LIST', ...values, ...header }
|
||||
}
|
||||
|
||||
/** What a grid print covers. */
|
||||
export type ListScope = { kind: 'all' } | { kind: 'page'; skip: number; limit: number } | { kind: 'selected'; ids: string[] } | { kind: 'sheets'; ids: string[] }
|
||||
|
||||
@@ -308,6 +383,7 @@ export interface PrintRequest {
|
||||
/** Printer row id. */
|
||||
printer: string
|
||||
copies?: number
|
||||
chrome?: PrintChrome
|
||||
}
|
||||
|
||||
export interface TableListRequest {
|
||||
@@ -329,12 +405,16 @@ export interface TableListRequest {
|
||||
pageSize?: 'LETTER' | 'A4'
|
||||
/** The primary key field, for a selection. */
|
||||
primaryKeyField?: string
|
||||
chrome?: PrintChrome
|
||||
}
|
||||
|
||||
export interface TextRequest {
|
||||
title: string
|
||||
subtitle?: string
|
||||
text: string
|
||||
/** A screen's content as sections (printed instead of the raw text when given). */
|
||||
sections?: ContentSection[]
|
||||
chrome?: PrintChrome
|
||||
printer: string
|
||||
copies?: number
|
||||
orientation?: 'PORTRAIT' | 'LANDSCAPE'
|
||||
@@ -376,6 +456,7 @@ export function tableListValues(request: TableListRequest): Record<string, unkno
|
||||
pageSize: request.pageSize ?? 'LETTER',
|
||||
[PRINTER_FIELD]: request.printer,
|
||||
[COPIES_FIELD]: request.copies ?? 1,
|
||||
...chromeValues(request.chrome),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,7 +519,7 @@ export class Printing {
|
||||
if (!request.ids.length) throw new Error('nothing to print: no record ids')
|
||||
const copies = request.copies ?? 1
|
||||
if (!Number.isInteger(copies) || copies < 1 || copies > 100) throw new Error('copies must be 1 to 100')
|
||||
const values = await this.transport.runProcess(printProcessName(request.table), { values: { [PRINTER_FIELD]: request.printer, [COPIES_FIELD]: copies }, recordIds: request.ids })
|
||||
const values = await this.transport.runProcess(printProcessName(request.table), { values: { [PRINTER_FIELD]: request.printer, [COPIES_FIELD]: copies, ...chromeValues(request.chrome) }, recordIds: request.ids })
|
||||
return jobIdsOf(values)
|
||||
}
|
||||
|
||||
@@ -453,10 +534,26 @@ export class Printing {
|
||||
async printText(request: TextRequest): Promise<PrintOutcome> {
|
||||
this.require()
|
||||
if (!request.text.trim()) throw new Error('nothing to print: the text is empty')
|
||||
const values = await this.transport.runProcess(TEXT_PROCESS, { values: { title: request.title, ...(request.subtitle ? { subtitle: request.subtitle } : {}), text: request.text, orientation: request.orientation ?? 'PORTRAIT', pageSize: 'LETTER', [PRINTER_FIELD]: request.printer, [COPIES_FIELD]: request.copies ?? 1 }, recordIds: [] })
|
||||
const values = await this.transport.runProcess(TEXT_PROCESS, { values: { ...chromeValues(request.chrome), title: request.title, ...(request.subtitle ? { subtitle: request.subtitle } : {}), text: request.text, ...(request.sections?.length ? { sections: JSON.stringify(request.sections) } : {}), orientation: request.orientation ?? 'PORTRAIT', pageSize: 'LETTER', [PRINTER_FIELD]: request.printer, [COPIES_FIELD]: request.copies ?? 1 }, recordIds: [] })
|
||||
return { jobIds: jobIdsOf(values) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a record sheet, table list or text page to a PDF on the server (no printer, no job)
|
||||
* and downloads it; the default name is the server's (the document title) with the date and
|
||||
* time stamp downloads and exports use: `Customer-Ada-Lovelace_2026-11-01_120301.pdf`.
|
||||
*/
|
||||
async renderToPdf(request: RenderRequest, now: Date = new Date(), chrome?: PrintChrome): Promise<RenderedPdf> {
|
||||
this.require()
|
||||
if (!this.transport.download) throw new Error('this client cannot download process files')
|
||||
if (request.kind === 'text' && !request.text.trim()) throw new Error('nothing to save: the text is empty')
|
||||
const values = await this.transport.runProcess(RENDER_PROCESS, { values: renderValues(request, chrome), recordIds: [] })
|
||||
const reference = downloadReference(values)
|
||||
if (!reference) throw new Error('the server rendered no PDF (no download in its answer)')
|
||||
const { bytes } = await this.transport.download(reference)
|
||||
return { fileName: exportFileName(reference.fileName, 'pdf', now), serverName: reference.fileName, bytes, message: values.printingMessage === undefined ? undefined : String(values.printingMessage) }
|
||||
}
|
||||
|
||||
/** Cancels jobs still queued in QQQ (jobs a device has taken must be handled at the device). */
|
||||
async cancel(ids: string[]): Promise<void> {
|
||||
this.require()
|
||||
|
||||
@@ -10,7 +10,7 @@ import { join } from 'node:path'
|
||||
import { test } from 'node:test'
|
||||
import type { CallInput, CallResult } from '../api/call.js'
|
||||
import { ExtensionNotInstalledError, ExtensionRegistry, knownExtension } from '../extensions/registry.js'
|
||||
import { MAX_LIST_ROWS, Printing, canPrintLists, canPrintTo, listScopeChoices, tableListValues, isFinalJobState, jobIdsOf, jobOf, jobStateSummary, printProcessName, printerOf, readRememberedPrinter, resolvePrinter, tableHasPrint, whyNotPrintable, writeRememberedPrinter, type PrintingTransport } from '../extensions/printing.js'
|
||||
import { MAX_LIST_ROWS, Printing, canSaveAsPdf, chromeValues, renderValues, canPrintLists, canPrintTo, listScopeChoices, tableListValues, isFinalJobState, jobIdsOf, jobOf, jobStateSummary, printProcessName, printerOf, readRememberedPrinter, resolvePrinter, tableHasPrint, whyNotPrintable, writeRememberedPrinter, type PrintingTransport } from '../extensions/printing.js'
|
||||
import { readConfig, upsertProfile } from '../session/profiles.js'
|
||||
|
||||
const withPrinting = ExtensionRegistry.fromVersion({ extensions: [{ name: 'printing', version: '2.0.0' }] })
|
||||
@@ -201,3 +201,58 @@ test('grid print choices: all rows first when filtered or small, this page first
|
||||
assert.equal(canPrintLists({ processes: { printingPrintTableList: {}, printingPrintText: {} } }), true)
|
||||
assert.equal(canPrintLists({ processes: { printingPrintTableList: {} } }), false)
|
||||
})
|
||||
|
||||
test('save as PDF: render values for a record, a list (no printer) and a text page', () => {
|
||||
assert.deepEqual(renderValues({ kind: 'record', table: 'customer', id: '1' }), { kind: 'RECORD', tableName: 'customer', recordId: '1' })
|
||||
const list = renderValues({ kind: 'list', list: { table: 'person', columns: ['id'], filter: { criteria: [], orderBys: [{ fieldName: 'id', isAscending: true }] }, scope: { kind: 'all' }, title: 'Person' } })
|
||||
assert.equal(list.kind, 'LIST')
|
||||
assert.equal(list.scope, 'ALL')
|
||||
assert.equal(list.printingPrinterId, undefined)
|
||||
assert.equal(list.printingCopies, undefined)
|
||||
assert.deepEqual(renderValues({ kind: 'text', title: 'Home', text: 'x' }), { kind: 'TEXT', title: 'Home', text: 'x', orientation: 'PORTRAIT', pageSize: 'LETTER' })
|
||||
assert.equal(canSaveAsPdf({ processes: { printingRenderToPdf: {} } }), true)
|
||||
assert.equal(canSaveAsPdf({ processes: {} }), false)
|
||||
})
|
||||
|
||||
test('save as PDF: renders on the server, downloads the file and names it with the download stamp', async () => {
|
||||
const downloads: unknown[] = []
|
||||
const { runs, transport } = fake(() => ({}), async () => ({ downloadFileName: 'Customer-Ada-Lovelace.pdf', serverFilePath: '/tmp/qqq-print-1.pdf', printingMessage: 'Saved the first 10000 of 12000 rows' }))
|
||||
transport.download = async (reference) => {
|
||||
downloads.push(reference)
|
||||
return { bytes: new TextEncoder().encode('%PDF-1.7'), contentType: 'application/pdf' }
|
||||
}
|
||||
const printing = new Printing(withPrinting, transport)
|
||||
const pdf = await printing.renderToPdf({ kind: 'record', table: 'customer', id: '1' }, new Date(2026, 10, 1, 12, 3, 1))
|
||||
assert.equal(pdf.fileName, 'Customer-Ada-Lovelace_2026-11-01_120301.pdf')
|
||||
assert.equal(pdf.serverName, 'Customer-Ada-Lovelace.pdf')
|
||||
assert.equal(new TextDecoder().decode(pdf.bytes), '%PDF-1.7')
|
||||
assert.equal(pdf.message, 'Saved the first 10000 of 12000 rows')
|
||||
assert.deepEqual(runs[0], { name: 'printingRenderToPdf', values: { kind: 'RECORD', tableName: 'customer', recordId: '1' }, recordIds: [] })
|
||||
assert.deepEqual(downloads, [{ fileName: 'Customer-Ada-Lovelace.pdf', query: { filePath: '/tmp/qqq-print-1.pdf' } }])
|
||||
await assert.rejects(printing.renderToPdf({ kind: 'text', title: 't', text: ' ' }), /empty/)
|
||||
delete transport.download
|
||||
await assert.rejects(printing.renderToPdf({ kind: 'record', table: 'customer', id: '1' }), /cannot download/)
|
||||
await assert.rejects(new Printing(without, transport).renderToPdf({ kind: 'record', table: 'customer', id: '1' }), ExtensionNotInstalledError)
|
||||
const { transport: none } = fake(() => ({}), async () => ({}))
|
||||
none.download = async () => ({ bytes: new Uint8Array(), contentType: '' })
|
||||
await assert.rejects(new Printing(withPrinting, none).renderToPdf({ kind: 'record', table: 'customer', id: '1' }), /no PDF/)
|
||||
})
|
||||
|
||||
test('the app header and footer travel with every request; blank fields are left to the server', async () => {
|
||||
const chrome = { app: 'QQQ All', title: 'Sales › Customer › Ada Lovelace', server: 'local (localhost:8078)', user: 'Admin', printedAt: '2026-11-01 12:03', footerLeft: 'qqq ui 1.0.1 · local', footerNote: ' ' }
|
||||
assert.deepEqual(chromeValues(chrome), { headerApp: 'QQQ All', headerTitle: 'Sales › Customer › Ada Lovelace', headerServer: 'local (localhost:8078)', headerUser: 'Admin', headerPrintedAt: '2026-11-01 12:03', footerLeft: 'qqq ui 1.0.1 · local' })
|
||||
assert.deepEqual(chromeValues(undefined), {})
|
||||
const sections = [{ title: 'Recently viewed', lines: ['Ada Lovelace'] }]
|
||||
const text = renderValues({ kind: 'text', title: 'Home', text: 'raw', sections }, chrome)
|
||||
assert.equal(text.sections, JSON.stringify(sections))
|
||||
assert.equal(text.headerApp, 'QQQ All')
|
||||
assert.equal(renderValues({ kind: 'record', table: 'customer', id: '1' }, chrome).headerTitle, 'Sales › Customer › Ada Lovelace')
|
||||
const { runs, transport } = fake(() => ({}), async () => ({ printingJobIds: 'j1' }))
|
||||
const printing = new Printing(withPrinting, transport)
|
||||
await printing.print({ table: 'customer', ids: ['1'], printer: 'p1', chrome })
|
||||
await printing.printText({ title: 'Home', text: 'raw', sections, printer: 'p1', chrome })
|
||||
await printing.printTableList({ table: 'person', columns: ['id'], filter: {}, scope: { kind: 'all' }, printer: 'p1', chrome: { ...chrome, footerNote: 'Filter: x' } })
|
||||
assert.equal(runs[0]!.values.headerUser, 'Admin')
|
||||
assert.equal(runs[1]!.values.sections, JSON.stringify(sections))
|
||||
assert.equal(runs[2]!.values.footerNote, 'Filter: x')
|
||||
})
|
||||
+14
-6
@@ -84,11 +84,19 @@ passes it on — most do not, so Ctrl+P is the key to rely on):
|
||||
selected row**. The server prints up to 10,000 rows (more prints the first 10,000 and says so), repeats
|
||||
the header on every page, turns the page landscape when the columns need it and puts the table, filter,
|
||||
sort, row count, user and time in the header and footer;
|
||||
- any other screen (home, dashboards, the developer view, SQL results, process results, output) prints the
|
||||
**screen as text**: a monospace PDF of what is drawn, without the status line and F-key bar, sized so a
|
||||
wide terminal keeps its lines.
|
||||
- any other screen (home, dashboards, the developer view, SQL results, process results, Search, History,
|
||||
output) first asks **Print what?**: **Content** (the default) prints the screen's panels as a document —
|
||||
each panel a section under its title, no Apps sidebar, title bar, key lines or borders, wrapped to the
|
||||
page — and **Screen** prints the terminal as drawn (monospace, sized so a wide terminal keeps its lines).
|
||||
|
||||
Then the printer picker: printers that can print now (approved, exposed by a connected print agent, PDF)
|
||||
Every page carries the app's **header** (the instance's name, the screen's breadcrumb such as `People ›
|
||||
Person › Ada Lovelace`, the server, you, and the time in your date format) and **footer** (`qqq ui 1.0.1 ·
|
||||
<server>`, a grid's filter and sort, page n of m).
|
||||
|
||||
Then the printer picker, with **Save as PDF…** first: it renders the same document on the server and saves
|
||||
it the way downloads and exports are saved — the save dialog (or, with `download-mode silent`, straight to
|
||||
the download folder), the stamped name (`Customer-Ada-Lovelace_2026-11-01_120301.pdf`), never overwriting
|
||||
without asking. `:print pdf` saves without the picker. Then printers that can print now (approved, exposed by a connected print agent, PDF)
|
||||
come first, the others are listed with the reason and cannot be picked; the printer chosen is remembered
|
||||
per profile and preselected next time, marked "(last used)". `:print <printer>` skips the picker (name,
|
||||
unique prefix or id). The title bar and status line show `print 1/3 RECEIVED` while jobs run, and a flash
|
||||
@@ -477,7 +485,7 @@ the plain sample server; one that fails shows `…`, then its last value dimmed
|
||||
|
||||
| Tile | Needs | Shows |
|
||||
|------|-------|-------|
|
||||
| Online | collaboration | people in presence across a few tables per refresh (favourites and recents first), who and on what; the signed-in user's other sessions as "you elsewhere" |
|
||||
| Online | the session store, or collaboration | who is signed in: with the session store qbit, the sessions active in the last 10 minutes and their users ("3 sessions · 2 users (you ×2, bob)"; your own sessions count); otherwise you plus the people in presence across a few tables per refresh (favourites and recents first), who and on what. It never says "nobody around" while you are signed in. A server that stores no sessions (mock auth) or merges presence per user cannot tell two terminals of one user apart: both show "1 online · you". The saver keeps the presence lease of the screen under it, so others see you still viewing it, not gone |
|
||||
| Jobs | `durableJobs` | running, queued and recently failed jobs (all users with jobs_admin, else yours) |
|
||||
| Health | health | the summary status and up / degraded / down / unknown counts |
|
||||
| Database | db-performance | live sessions, connections of the maximum, cache hit ratio, blocking chains |
|
||||
@@ -497,7 +505,7 @@ the other tiles under it as one centred stack, rotating every 8 s). In a tall na
|
||||
the tile panel under Query. The block letters say the profile's
|
||||
short name when it has 6 characters or fewer (else the profile name), with the server host in plain text
|
||||
beneath; letters, digits, `-`, `_` and `.` are drawn in block letters, anything else falls back to plain
|
||||
text. Query blinks, wags and hops every ten seconds and faces the way he drifts; the art (braille, with a
|
||||
text. Query blinks, wags and hops every ten seconds and faces the way he drifts. His art is Query's own drawing from https://www.qrun.io/query/ (one colour, indigo `#818cf8`) rasterised into braille at three sizes (42×22, 25×13 and 17×9 cells; the medium is used where there is room, from 100 columns) by `scripts/gen-query-art.mjs`; the art (braille, with a
|
||||
line-art version for `--ascii`) is in `src/saver/query-art.ts`.
|
||||
|
||||
Burn-in guard (F9 › Settings › Screen saver burn-in guard, `:saver burnin on|off`, default on): nothing
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Copyright 2026 QRun.IO, Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (see LICENSE).
|
||||
*/
|
||||
|
||||
// Generates the screen saver's Query art (src/saver/query-art.ts: LARGE, MEDIUM, SMALL and the dot
|
||||
// boxes of the eye and the tail) from Query's own drawing: the inline SVG on https://www.qrun.io/query/
|
||||
// (viewBox 0 0 331.41 348.44; the first path is the sitting dog, the second his eye). Needs `inkscape`
|
||||
// and ImageMagick (`magick`) on the PATH; run by hand when the drawing changes:
|
||||
// node scripts/gen-query-art.mjs query-hero.svg [outdir]
|
||||
// Each size is the drawing rasterised at 8× the dot grid, averaged down to it (a box filter, so a thin
|
||||
// stroke keeps its weight as coverage) and thresholded per size (thinner strokes need a lower cut).
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const [svgPath, outDir = '.'] = process.argv.slice(2)
|
||||
if (!svgPath) throw new Error('usage: gen-query-art.mjs query-hero.svg [outdir]')
|
||||
const svg = readFileSync(svgPath, 'utf8').replaceAll('currentColor', '#ffffff')
|
||||
const paths = [...svg.matchAll(/<path[^>]*>/g)].map((m) => m[0])
|
||||
const wrap = (body) => `<svg viewBox="0 0 331.41 348.44" xmlns="http://www.w3.org/2000/svg"><rect width="331.41" height="348.44" fill="#000"/>${body}</svg>`
|
||||
const work = mkdtempSync(join(tmpdir(), 'query-art-'))
|
||||
|
||||
/** Coverage 0…1 per dot of an SVG body, on a grid of w×h dots. */
|
||||
function raster(body, w, h) {
|
||||
const file = join(work, 'in.svg')
|
||||
writeFileSync(file, wrap(body))
|
||||
const png = join(work, 'out.png')
|
||||
execFileSync('inkscape', [file, '-o', png, '-w', String(w * 8), '-h', String(h * 8)], { stdio: 'ignore' })
|
||||
const raw = execFileSync('magick', [png, '-colorspace', 'Gray', '-filter', 'Box', '-resize', `${w}x${h}!`, '-depth', '8', 'gray:-'], { maxBuffer: 1 << 24 })
|
||||
return Array.from({ length: h }, (_, y) => Array.from({ length: w }, (_, x) => raw[y * w + x] / 255))
|
||||
}
|
||||
|
||||
const DOT = [[0x01, 0x02, 0x04, 0x40], [0x08, 0x10, 0x20, 0x80]]
|
||||
function braille(bits) {
|
||||
const rows = []
|
||||
for (let cy = 0; cy < bits.length / 4; cy++) {
|
||||
let line = ''
|
||||
for (let cx = 0; cx < bits[0].length / 2; cx++) {
|
||||
let code = 0
|
||||
for (let dx = 0; dx < 2; dx++) for (let dy = 0; dy < 4; dy++) if (bits[cy * 4 + dy]?.[cx * 2 + dx]) code |= DOT[dx][dy]
|
||||
line += code ? String.fromCodePoint(0x2800 + code) : ' '
|
||||
}
|
||||
rows.push(line)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
const SIZES = { large: { w: 42, h: 22, cut: 0.42 }, medium: { w: 25, h: 13, cut: 0.28 }, small: { w: 17, h: 9, cut: 0.2 } }
|
||||
const out = {}
|
||||
for (const [name, { w, h, cut }] of Object.entries(SIZES)) {
|
||||
const dw = w * 2
|
||||
const dh = h * 4
|
||||
const bits = raster(paths[0], dw, dh).map((r) => r.map((v) => v >= cut))
|
||||
// his eye: the second path alone, any coverage at all
|
||||
const eyeCov = raster(paths[1], dw, dh)
|
||||
const eyeDots = []
|
||||
eyeCov.forEach((r, y) => r.forEach((v, x) => { if (v >= 0.12) eyeDots.push([x, y]) }))
|
||||
const eye = eyeDots.length ? [Math.min(...eyeDots.map((d) => d[0])), Math.min(...eyeDots.map((d) => d[1])), Math.max(...eyeDots.map((d) => d[0])), Math.max(...eyeDots.map((d) => d[1]))] : [0, 0, 0, 0]
|
||||
// the eye is part of the dog path's raster too: keep the eye dots drawn
|
||||
for (const [x, y] of eyeDots) bits[y][x] = true
|
||||
// the tail: the low left corner of the drawing
|
||||
const tail = [0, Math.round(dh * 0.62), Math.round(dw * 0.2), dh - 1]
|
||||
out[name] = { rows: braille(bits), eye, tail, w, h }
|
||||
}
|
||||
const ts = Object.entries(out).map(([name, o]) => `/** ${name} Query, ${o.w}×${o.h} cells, facing right (generated by scripts/gen-query-art.mjs). */\nconst ${name.toUpperCase()} = [\n${o.rows.map((r) => ` ${JSON.stringify(r)},`).join('\n')}\n]\n`).join('\n')
|
||||
const parts = `const PARTS: Record<QuerySize, Parts> = {\n${Object.entries(out).map(([n, o]) => ` ${n}: { eye: [${o.eye}], tail: [${o.tail}] },`).join('\n')}\n}\n`
|
||||
writeFileSync(join(outDir, 'query-art.generated.txt'), `${ts}\n${parts}`)
|
||||
for (const [n, o] of Object.entries(out)) console.log(`--- ${n} ${o.w}x${o.h} eye ${o.eye} tail ${o.tail}\n${o.rows.join('\n')}`)
|
||||
@@ -5,11 +5,13 @@
|
||||
|
||||
import { useKeyboard, usePaste, useTerminalDimensions } from '@opentui/react'
|
||||
import { Component, useEffect, useReducer, type ReactNode } from 'react'
|
||||
import type { AppTreeNode } from './client'
|
||||
import { FKeyZone, PaneZone, StatusZone, useMouseDispatcher } from './mouse/app-zones'
|
||||
import { MouseCapture, MouseLayer, MouseRoot } from './mouse/zone'
|
||||
import { presenceText, usePresence } from './presence'
|
||||
import type { AppStore } from './store'
|
||||
import { breadcrumbs } from './breadcrumbs'
|
||||
|
||||
export { appPath, breadcrumbs } from './breadcrumbs'
|
||||
import { glyphs, theme } from './theme'
|
||||
import { pad, trunc } from './util/text'
|
||||
|
||||
@@ -39,32 +41,6 @@ export class ErrorBoundary extends Component<{ children: ReactNode; resetKey: st
|
||||
}
|
||||
}
|
||||
|
||||
/** The apps above a table, process or app in the app tree (labels, outermost first). */
|
||||
export function appPath(nodes: AppTreeNode[], name: string, type: string, path: string[] = []): string[] | undefined {
|
||||
for (const n of nodes) {
|
||||
if (n.name === name && n.type === type) return path
|
||||
if (n.children) {
|
||||
const found = appPath(n.children, name, type, [...path, n.label])
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** The title-bar path of the top screen: its apps, the table, then the record or form. */
|
||||
export function breadcrumbs(store: AppStore): string[] {
|
||||
const top = store.screen as (import('./types').Screen & { tableName?: string; processName?: string; appName?: string }) | undefined
|
||||
if (!top) return []
|
||||
const tree = (store.meta?.appTree ?? []) as AppTreeNode[]
|
||||
const tableLabel = top.tableName ? store.meta?.tables?.[top.tableName]?.label ?? top.tableName : undefined
|
||||
if (top.kind === 'table') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), top.title()]
|
||||
if (top.kind === 'record') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), tableLabel!, top.title()]
|
||||
if (top.kind === 'form') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), top.title()]
|
||||
if (top.kind === 'process') return [...(appPath(tree, top.processName!, 'PROCESS') ?? []), top.title()]
|
||||
if (top.kind === 'app') return [...(appPath(tree, top.appName!, 'APP') ?? []), top.title()]
|
||||
return [top.title()]
|
||||
}
|
||||
|
||||
function TitleBar({ store, width }: { store: AppStore; width: number }) {
|
||||
const t = theme()
|
||||
const presence = usePresence(store.screen?.presenceScope?.())
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2026 QRun.IO, Inc.
|
||||
* Licensed under the Apache License, Version 2.0 (see LICENSE).
|
||||
*/
|
||||
|
||||
/** The title-bar path of a screen (apps, table, record), shared by the title bar and printed headers. */
|
||||
|
||||
import type { AppTreeNode } from './client'
|
||||
import type { AppStore } from './store'
|
||||
|
||||
/** The apps above a table, process or app in the app tree (labels, outermost first). */
|
||||
export function appPath(nodes: AppTreeNode[], name: string, type: string, path: string[] = []): string[] | undefined {
|
||||
for (const n of nodes) {
|
||||
if (n.name === name && n.type === type) return path
|
||||
if (n.children) {
|
||||
const found = appPath(n.children, name, type, [...path, n.label])
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** The title-bar path of the top screen: its apps, the table, then the record or form. */
|
||||
export function breadcrumbs(store: AppStore): string[] {
|
||||
const top = store.screen as (import('./types').Screen & { tableName?: string; processName?: string; appName?: string }) | undefined
|
||||
if (!top) return []
|
||||
const tree = (store.meta?.appTree ?? []) as AppTreeNode[]
|
||||
const tableLabel = top.tableName ? store.meta?.tables?.[top.tableName]?.label ?? top.tableName : undefined
|
||||
if (top.kind === 'table') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), top.title()]
|
||||
if (top.kind === 'record') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), tableLabel!, top.title()]
|
||||
if (top.kind === 'form') return [...(appPath(tree, top.tableName!, 'TABLE') ?? []), top.title()]
|
||||
if (top.kind === 'process') return [...(appPath(tree, top.processName!, 'PROCESS') ?? []), top.title()]
|
||||
if (top.kind === 'app') return [...(appPath(tree, top.appName!, 'APP') ?? []), top.title()]
|
||||
return [top.title()]
|
||||
}
|
||||
@@ -72,6 +72,11 @@ export class SaverOverlay implements Overlay {
|
||||
features: s.version?.features ?? [],
|
||||
status: () => s.status,
|
||||
events: realtimeEvents,
|
||||
sessionTable: () => {
|
||||
// the session store qbit's table (storedSession)
|
||||
const t = Object.values(tables).find((x) => /^(stored_?)?sessions?$/i.test(x.name))
|
||||
return t && t.readPermission !== false ? t.name : undefined
|
||||
},
|
||||
favouriteTables: favourites,
|
||||
tableLabel: (name) => tables[name]?.label ?? name,
|
||||
intervalMs: () => this.model.intervalMs,
|
||||
|
||||
+238
-20
@@ -17,12 +17,16 @@
|
||||
*/
|
||||
|
||||
import { writeFileSync } from 'node:fs'
|
||||
import { exportFileName, FAILED_JOB_STATES, MAX_LIST_ROWS, Printing, canPrintLists, isFinalJobState, listScopeChoices, readRememberedPrinter, resolvePrinter, runProcess, tableHasPrint, whyNotPrintable, writeRememberedPrinter, type ListScope, type Printer, type PrintJob, type PrintOutcome, type ProcessMeta } from '@qrun-io/qqq-core'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { canSaveAsPdf, downloadProcessFile, formatDateValue, profileNameForServer, readConfig, saveDownload, type ContentSection, type PrintChrome, type RenderRequest, exportFileName, FAILED_JOB_STATES, MAX_LIST_ROWS, Printing, canPrintLists, isFinalJobState, listScopeChoices, readRememberedPrinter, resolvePrinter, runProcess, tableHasPrint, whyNotPrintable, writeRememberedPrinter, type ListScope, type Printer, type PrintJob, type PrintOutcome, type ProcessMeta } from '@qrun-io/qqq-core'
|
||||
import { ChoiceOverlay, type Choice } from './overlays/basic'
|
||||
import type { AppStore } from './store'
|
||||
import type { Screen } from './types'
|
||||
import { errorText } from './util/text'
|
||||
import { saveFile } from './overlays/files-helpers'
|
||||
import { breadcrumbs } from './breadcrumbs'
|
||||
import { dateSettingsFor } from './controls/date-settings'
|
||||
import { CLI_VERSION } from '@qrun-io/qqq-cli/program'
|
||||
import { history } from './history/record'
|
||||
|
||||
/** The printing module of the store's server, or undefined without a client or the extension. */
|
||||
@@ -35,6 +39,7 @@ export function printingOf(store: AppStore): Printing | undefined {
|
||||
const meta = await client.processMeta(processName) as unknown as ProcessMeta
|
||||
return (await runProcess({ baseUrl: client.server, fetch: client.fetch, meta, values, records: recordIds.length ? { ids: recordIds } : undefined, stepTimeoutMillis: 60000 })).values
|
||||
},
|
||||
download: (reference) => downloadProcessFile(client.server, client.fetch, reference),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -66,17 +71,26 @@ export function printerChoices(printers: Printer[], rememberedId: string | undef
|
||||
return { choices, initial: remembered >= 0 ? remembered : Math.max(0, firstPrintable) }
|
||||
}
|
||||
|
||||
/** The first entry of the printer picker when the server can render to a PDF download. */
|
||||
export const SAVE_AS_PDF = 'Save as PDF…'
|
||||
|
||||
/**
|
||||
* The printer picker: printable printers first, the last used one on this profile preselected.
|
||||
* With `hint` (`:print <printer>`) the printer is chosen by name, id or unique prefix without the
|
||||
* picker. The choice is remembered for the profile, then `send` queues the print.
|
||||
* The printer picker: "Save as PDF…" first (when the server can render to a download and the
|
||||
* caller says what to render), then the printers, printable ones first, the last used one on this
|
||||
* profile preselected. With `hint` (`:print <printer>`) the printer is chosen by name, id or unique
|
||||
* prefix without the picker; `:print pdf` saves. A printer choice is remembered for the profile,
|
||||
* then `send` queues the print.
|
||||
*/
|
||||
export function pickPrinter(store: AppStore, title: string, send: (printing: Printing, printer: Printer) => void, hint?: string): void {
|
||||
export function pickPrinter(store: AppStore, title: string, send: (printing: Printing, printer: Printer) => void, hint?: string, renders?: RenderRequest[]): void {
|
||||
const printing = printingOf(store)
|
||||
if (!printing) return store.flash(`Printing needs ${store.client ? 'the printing extension' : 'a server connection'}.`, 'error')
|
||||
const canSave = Boolean(renders?.length) && canSaveAsPdf(store.meta as never)
|
||||
if (hint && /^(pdf|file)$/i.test(hint.trim())) {
|
||||
return canSave ? savePdfs(store, printing, renders!) : store.flash('This server cannot render to PDF (it needs the printingRenderToPdf process of qbit-printing).', 'error')
|
||||
}
|
||||
const profile = store.status.profile
|
||||
store.run(printing.printers(), (printers) => {
|
||||
if (!printers.length) return store.message('No printers: no print agent has exposed a printer to this server yet.', 'info', 'Print')
|
||||
if (!printers.length && !canSave) return store.message('No printers: no print agent has exposed a printer to this server yet.', 'info', 'Print')
|
||||
const go = (printer: Printer) => {
|
||||
writeRememberedPrinter(profile, { id: printer.id, name: printer.name })
|
||||
send(printing, printer)
|
||||
@@ -92,7 +106,44 @@ export function pickPrinter(store: AppStore, title: string, send: (printing: Pri
|
||||
return why ? store.flash(`"${printer.name}" cannot print now: ${why}.`, 'error') : go(printer)
|
||||
}
|
||||
const { choices, initial } = printerChoices(printers, readRememberedPrinter(profile)?.id)
|
||||
store.open(new ChoiceOverlay<Printer>(store, title, choices, go, 'printers that cannot print now are shown with the reason; the choice is remembered for this profile', initial))
|
||||
const anyPrintable = choices.some((c) => !c.disabled)
|
||||
const all: Choice<Printer | 'pdf'>[] = [
|
||||
...(canSave ? [{ label: SAVE_AS_PDF, value: 'pdf' as const, detail: 'render it and save it like a download: download folder, file dialog' }] : []),
|
||||
...choices,
|
||||
]
|
||||
const first = canSave && !anyPrintable ? 0 : initial + (canSave ? 1 : 0)
|
||||
store.open(new ChoiceOverlay<Printer | 'pdf'>(store, title, all, (choice) => (choice === 'pdf' ? savePdfs(store, printing, renders!) : go(choice)),
|
||||
'Save as PDF saves where downloads go; printers that cannot print now are shown with the reason; the printer is remembered for this profile', first))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Save as PDF: renders each document on the server and saves it as downloads and exports are
|
||||
* saved: the save dialog (or, with silent downloads, the download folder), the stamped default
|
||||
* name (`Customer-Ada-Lovelace_2026-11-01_120301.pdf`), no silent overwrite. More than one
|
||||
* document go next to the first, each with its own stamped name.
|
||||
*/
|
||||
export function savePdfs(store: AppStore, printing: Printing, renders: RenderRequest[]): void {
|
||||
store.flash(`Rendering ${renders.length === 1 ? 'the PDF' : `${renders.length} PDFs`}…`)
|
||||
const chrome = chromeOf(store)
|
||||
store.run(printing.renderToPdf(renders[0]!, new Date(), chrome), (first) => {
|
||||
saveFile(store, renders.length === 1 ? 'Save as PDF' : `Save ${renders.length} PDFs (the others go next to this one)`, first.fileName, (path) => {
|
||||
const saved = [saveDownload(path, first.bytes, { explicit: true })]
|
||||
const notes = first.message ? [first.message] : []
|
||||
const done = () => {
|
||||
history.record(store, { kind: 'print', summary: `Saved ${saved.length === 1 ? saved[0] : `${saved.length} PDFs to ${dirname(saved[0]!)}`}` })
|
||||
store.message([`Saved ${saved.length === 1 ? saved[0] : `${saved.length} PDFs to ${dirname(saved[0]!)}`} (${first.bytes.length.toLocaleString('en-US')} bytes${saved.length > 1 ? ' for the first' : ''}).`, ...notes].join('\n'), 'info', 'Save as PDF')
|
||||
}
|
||||
const rest = renders.slice(1)
|
||||
if (!rest.length) return done()
|
||||
store.run((async () => {
|
||||
for (const request of rest) {
|
||||
const pdf = await printing.renderToPdf(request, new Date(), chrome)
|
||||
if (pdf.message) notes.push(pdf.message)
|
||||
saved.push(saveDownload(join(dirname(path), pdf.fileName), pdf.bytes, { explicit: false }))
|
||||
}
|
||||
})(), done)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -114,7 +165,7 @@ export function openPrintDialog(store: AppStore, table: string, ids: string[], w
|
||||
const unavailable = printUnavailable(store, table)
|
||||
if (!printingOf(store) || unavailable) return store.flash(`Print ${unavailable ?? 'needs a server connection'}.`, 'error')
|
||||
if (!ids.length) return store.flash('Nothing to print: select records first (Space).', 'error')
|
||||
pickPrinter(store, `Print ${what} on…`, (printing, printer) => queued(store, printing, printer, what, printing.print({ table, ids, printer: printer.id }).then((jobIds) => ({ jobIds }))), hint)
|
||||
pickPrinter(store, `Print ${what} on…`, (printing, printer) => queued(store, printing, printer, what, printing.print({ table, ids, printer: printer.id, chrome: chromeOf(store) }).then((jobIds) => ({ jobIds }))), hint, ids.map((id) => ({ kind: 'record' as const, table, id })))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -161,8 +212,8 @@ export function printTargetOf(screen: Screen | undefined): PrintTarget {
|
||||
* The text of the screen as drawn (the renderer's character frame), without the status line and
|
||||
* the function-key bar, trailing spaces and trailing blank lines removed.
|
||||
*/
|
||||
export function captureScreenText(store: AppStore): string {
|
||||
const frame = store.captureScreen?.() ?? ''
|
||||
export function captureScreenText(store: AppStore, captured?: string): string {
|
||||
const frame = captured ?? store.captureScreen?.() ?? ''
|
||||
const lines = frame.replace(/\r/g, '').split('\n')
|
||||
while (lines.length && !lines[lines.length - 1]!.trim()) lines.pop()
|
||||
const body = lines.slice(0, Math.max(0, lines.length - 2)).map((l) => l.replace(/\s+$/, ''))
|
||||
@@ -182,31 +233,198 @@ export function printScreen(store: AppStore, hint?: string): void {
|
||||
if (target.kind === 'record') {
|
||||
if (tableHasPrint(store.meta as never, target.table)) return openPrintDialog(store, target.table, target.ids, target.what, hint)
|
||||
if (!canPrintLists(store.meta as never)) return saveInstead(store, target)
|
||||
return printText(store, target.what, hint)
|
||||
return askWhat(store, target.what, hint)
|
||||
}
|
||||
if (target.kind === 'text') return printText(store, target.title, hint)
|
||||
if (target.kind === 'text') return askWhat(store, target.title, hint)
|
||||
const grid = target.grid
|
||||
const choices = listScopeChoices({ total: grid.total, pageIndex: grid.pageIndex, pageSize: grid.pageSize, pageRows: grid.pageRows, selected: grid.selected, filtered: Boolean(grid.filterText), recordSheets: tableHasPrint(store.meta as never, grid.table) })
|
||||
const scoped = (scope: ListScope) => {
|
||||
if (scope.kind === 'sheets') return openPrintDialog(store, grid.table, scope.ids, `${scope.ids.length} ${grid.label} records`, hint)
|
||||
const what = scope.kind === 'all' ? `${grid.label}: ${grid.total === undefined ? 'all' : Math.min(grid.total, MAX_LIST_ROWS).toLocaleString('en-US')} rows` : scope.kind === 'page' ? `${grid.label}: page ${grid.pageIndex + 1}` : `${grid.label}: ${scope.ids.length} selected rows`
|
||||
pickPrinter(store, `Print ${what} on…`, (p, printer) => queued(store, p, printer, what, p.printTableList({
|
||||
const list = {
|
||||
table: grid.table, columns: grid.columns.map((c) => c.name), widths: grid.columns.every((c) => c.width) ? grid.columns.map((c) => c.width!) : undefined,
|
||||
filter: grid.filter, scope, title: grid.label, filterDescription: grid.filterText || undefined, printer: printer.id, primaryKeyField: grid.primaryKeyField,
|
||||
})), hint)
|
||||
filter: grid.filter, scope, title: grid.label, filterDescription: grid.filterText || undefined, primaryKeyField: grid.primaryKeyField,
|
||||
}
|
||||
pickPrinter(store, `Print ${what} on…`, (p, printer) => queued(store, p, printer, what, p.printTableList({ ...list, printer: printer.id, chrome: chromeOf(store) })), hint, [{ kind: 'list', list }])
|
||||
}
|
||||
if (grid.selectAll) return scoped({ kind: 'all' })
|
||||
store.open(new ChoiceOverlay<ListScope>(store, `Print ${grid.label}: what?`, choices.map((c) => ({ label: c.label, value: c.value, detail: c.detail })), scoped, 'the table list uses the columns, filter and sort you see; the header repeats on every page'))
|
||||
}
|
||||
|
||||
/** Prints the screen's text (monospace PDF). */
|
||||
function printText(store: AppStore, title: string, hint?: string): void {
|
||||
const text = captureScreenText(store)
|
||||
if (!text.trim()) return store.flash('There is nothing on the screen to print.', 'error')
|
||||
const wide = text.split('\n').some((l) => l.length > 110)
|
||||
pickPrinter(store, `Print this screen (${title}) on…`, (p, printer) => queued(store, p, printer, `screen ${title}`, p.printText({ title, subtitle: `qqq ui · ${store.status.server.replace(/^https?:\/\//, '')}`, text, printer: printer.id, orientation: wide ? 'LANDSCAPE' : 'PORTRAIT' })), hint)
|
||||
function printText(store: AppStore, title: string, text: string, sections?: ContentSection[], hint?: string): void {
|
||||
const wide = !sections && text.split('\n').some((l) => l.length > 110)
|
||||
const page = { title, text, sections, orientation: wide ? 'LANDSCAPE' as const : 'PORTRAIT' as const }
|
||||
const chrome = chromeOf(store)
|
||||
const what = sections ? `${title} (content)` : `screen ${title}`
|
||||
pickPrinter(store, `Print ${sections ? 'the content of' : 'this screen'} (${title}) on…`, (p, printer) => queued(store, p, printer, what, p.printText({ ...page, printer: printer.id, chrome })), hint, [{ kind: 'text', ...page }])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// the app's header and footer, and a screen's content as sections
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The header and footer every printed page carries: the app (instance branding, else the
|
||||
* profile), the breadcrumb of the screen, the server (profile and host), the user, the time in
|
||||
* the profile's date format; the footer `qqq ui <version> · <server>` and, for grids, the filter.
|
||||
*/
|
||||
export function chromeOf(store: AppStore, footerNote?: string, now: Date = new Date()): PrintChrome {
|
||||
const branding = (store.meta as { branding?: { appName?: string } } | undefined)?.branding
|
||||
let host = store.status.server
|
||||
try {
|
||||
host = new URL(store.status.server).host
|
||||
} catch {
|
||||
host = store.status.server.replace(/^https?:\/\//, '')
|
||||
}
|
||||
const profile = store.status.profile
|
||||
const server = profile && profile !== host && profile !== profileNameForServer(store.status.server) ? `${profile} (${host})` : host
|
||||
let printedAt = now.toISOString()
|
||||
try {
|
||||
printedAt = formatDateValue(now.toISOString(), 'DATE_TIME', dateSettingsFor(store), { withSeconds: false })
|
||||
} catch {
|
||||
printedAt = now.toISOString()
|
||||
}
|
||||
return {
|
||||
app: branding?.appName ?? profileNote(profile) ?? 'QQQ',
|
||||
title: breadcrumbs(store).join(' › '),
|
||||
server,
|
||||
user: store.status.user,
|
||||
printedAt,
|
||||
footerLeft: `qqq ui ${CLI_VERSION} · ${server}`,
|
||||
footerNote,
|
||||
}
|
||||
}
|
||||
|
||||
/** The profile's description (its note in config.json), if it has one. */
|
||||
function profileNote(profile: string): string | undefined {
|
||||
try {
|
||||
return readConfig().profiles[profile]?.note || undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const TOP_LEFT = new Set(['┌', '╭'])
|
||||
const TOP_RIGHT = new Set(['┐', '╮'])
|
||||
const BOTTOM_LEFT = new Set(['└', '╰'])
|
||||
const BOX = /[─│┌┐└┘├┤┬┴┼╭╮╰╯═║╔╗╚╝╟╢╠╣▏▕]/g
|
||||
|
||||
interface Box { top: number; left: number; bottom: number; right: number; title: string }
|
||||
|
||||
/** Boxes drawn with single lines in a character grid (their title from the top edge). */
|
||||
function boxesOf(grid: string[][]): Box[] {
|
||||
const out: Box[] = []
|
||||
for (let r = 0; r < grid.length; r++) {
|
||||
const row = grid[r]!
|
||||
for (let c = 0; c < row.length; c++) {
|
||||
if (!TOP_LEFT.has(row[c]!)) continue
|
||||
let right = -1
|
||||
for (let x = c + 1; x < row.length; x++) {
|
||||
if (TOP_RIGHT.has(row[x]!)) { right = x; break }
|
||||
if (TOP_LEFT.has(row[x]!)) break
|
||||
}
|
||||
if (right < 0) continue
|
||||
let bottom = -1
|
||||
for (let y = r + 1; y <= grid.length; y++) {
|
||||
// a panel cut off by the bottom of its region runs to the end
|
||||
if (y === grid.length) { bottom = y; break }
|
||||
const ch = grid[y]![c]
|
||||
if (ch !== undefined && BOTTOM_LEFT.has(ch)) { bottom = y; break }
|
||||
if (ch !== '│' && ch !== '║') { bottom = y; break }
|
||||
}
|
||||
if (bottom < 0) continue
|
||||
const title = row.slice(c + 1, right).join('').replace(/^[─\s]+|[─\s]+$/g, '').trim()
|
||||
out.push({ top: r, left: c, bottom, right, title })
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Text lines without box characters, trimmed; blank and border-only lines collapse. */
|
||||
function cleanLines(lines: string[]): string[] {
|
||||
const out: string[] = []
|
||||
for (const raw of lines) {
|
||||
const line = raw.replace(BOX, ' ').replace(/\s+$/, '')
|
||||
if (!line.trim()) {
|
||||
if (out.length && out[out.length - 1] !== '') out.push('')
|
||||
continue
|
||||
}
|
||||
out.push(line)
|
||||
}
|
||||
while (out.length && out[out.length - 1] === '') out.pop()
|
||||
const indent = Math.min(...out.filter((l) => l.trim()).map((l) => l.length - l.trimStart().length))
|
||||
return Number.isFinite(indent) && indent > 0 ? out.map((l) => l.slice(indent)) : out
|
||||
}
|
||||
|
||||
/**
|
||||
* A screen's content as sections, read from the drawn frame: the content panel only (not the
|
||||
* Apps sidebar, the title bar, the status line or the key bar), each inner panel as a section
|
||||
* with its title and lines, the text around them as untitled sections, in reading order, borders
|
||||
* removed and the panel's key hint dropped.
|
||||
*/
|
||||
export function contentSections(frame: string): ContentSection[] {
|
||||
const lines = frame.replace(/\r/g, '').split('\n')
|
||||
while (lines.length && !lines[lines.length - 1]!.trim()) lines.pop()
|
||||
const body = lines.slice(1, Math.max(1, lines.length - 2))
|
||||
const grid = body.map((l) => Array.from(l))
|
||||
// the Apps sidebar ("Apps (Tab)", "Apps · type to find") is navigation, not content
|
||||
const boxes = boxesOf(grid).filter((b) => !/^Apps(\s+\(|\s+·|$)/.test(b.title))
|
||||
if (!boxes.length) {
|
||||
const text = cleanLines(body)
|
||||
return text.length ? [{ title: '', lines: text }] : []
|
||||
}
|
||||
const area = (b: Box) => (b.bottom - b.top) * (b.right - b.left)
|
||||
const panel = boxes.reduce((a, b) => (area(b) > area(a) ? b : a))
|
||||
const inside = boxes.filter((b) => b !== panel && b.top > panel.top && b.bottom <= panel.bottom && b.left >= panel.left && b.right <= panel.right)
|
||||
const children = inside.filter((b) => !inside.some((o) => o !== b && b.top > o.top && b.bottom < o.bottom && b.left > o.left && b.right < o.right))
|
||||
const sections: ContentSection[] = []
|
||||
let free: string[] = []
|
||||
const flush = () => {
|
||||
const text = cleanLines(free)
|
||||
if (text.length) sections.push({ title: '', lines: text })
|
||||
free = []
|
||||
}
|
||||
const freeRows: Array<{ row: number; text: string }> = []
|
||||
for (let r = panel.top + 1; r < panel.bottom; r++) {
|
||||
const cells = grid[r]!.slice(panel.left + 1, panel.right).map((ch, i) => (children.some((b) => r >= b.top && r <= b.bottom && panel.left + 1 + i >= b.left && panel.left + 1 + i <= b.right) ? ' ' : ch))
|
||||
freeRows.push({ row: r, text: cells.join('') })
|
||||
}
|
||||
// the panel's last line is its key hint ("a actions · … · Esc back"): not content
|
||||
const lastText = [...freeRows].reverse().find((f) => f.text.trim())
|
||||
if (lastText && /(Esc|a actions| · )/.test(lastText.text) && /(Esc|actions|Enter)/.test(lastText.text)) lastText.text = ''
|
||||
const starts = new Map<number, Box[]>()
|
||||
for (const b of children) starts.set(b.top, [...(starts.get(b.top) ?? []), b].sort((x, y) => x.left - y.left))
|
||||
for (const f of freeRows) {
|
||||
const opening = starts.get(f.row)
|
||||
if (opening) {
|
||||
flush()
|
||||
for (const b of opening) {
|
||||
const text = cleanLines(grid.slice(b.top + 1, b.bottom).map((row) => row.slice(b.left + 1, b.right).join('')))
|
||||
if (b.title || text.length) sections.push({ title: b.title, lines: text })
|
||||
}
|
||||
}
|
||||
free.push(f.text)
|
||||
}
|
||||
flush()
|
||||
return sections
|
||||
}
|
||||
|
||||
/** Ctrl+P on a screen that is not a record or a grid: its content as a document, or the screen as drawn. */
|
||||
function askWhat(store: AppStore, title: string, hint?: string): void {
|
||||
const frame = store.captureScreen?.() ?? ''
|
||||
const sections = contentSections(frame)
|
||||
const screen = captureScreenText(store, frame)
|
||||
if (!screen.trim()) return store.flash('There is nothing on the screen to print.', 'error')
|
||||
if (hint || !sections.length) return printText(store, title, screen, sections.length ? sections : undefined, hint)
|
||||
store.open(new ChoiceOverlay<'content' | 'screen'>(store, 'Print what?', [
|
||||
{ label: 'Content', value: 'content', detail: "the screen's panels as a document: no navigation, no borders" },
|
||||
{ label: 'Screen', value: 'screen', detail: 'the terminal as you see it, line for line' },
|
||||
], (what) => printText(store, title, screen, what === 'content' ? sections : undefined), 'both carry the app header and footer'))
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Without printing: the grid's export, else the screen text saved as a file. */
|
||||
function saveInstead(store: AppStore, target: PrintTarget): void {
|
||||
const screen = store.screen as { exportDialog?: () => void } | undefined
|
||||
|
||||
@@ -24,7 +24,7 @@ import { pad, trunc } from '../util/text'
|
||||
import { Canvas, type Style } from './canvas'
|
||||
import { FONT_HEIGHT, blockText, blockWidth, canDraw } from './font'
|
||||
import { sparkline, type TileState } from './model'
|
||||
import { queryFrame, queryPoseAt, querySize, type QueryPose } from './query-art'
|
||||
import { QUERY_COLOR, queryFrame, queryPoseAt, querySize, type QueryPose, type QuerySize } from './query-art'
|
||||
import { SAVER_STYLES, type SaverStyle, type SaverStyleSetting } from './settings'
|
||||
|
||||
export interface SaverTile {
|
||||
@@ -226,7 +226,7 @@ function drawPin(c: Canvas, input: SaverInput): void {
|
||||
}
|
||||
|
||||
function palette(t: ThemeTokens): string[] {
|
||||
return [t.acc, t.acc2, t.ok, t.warn, t.markFg, t.err]
|
||||
return [QUERY_COLOR, t.acc2, t.ok, t.warn, t.markFg, t.err]
|
||||
}
|
||||
|
||||
/** The block-letter logo under Query: the profile's name, with the server host beneath. */
|
||||
@@ -262,16 +262,18 @@ export interface Box {
|
||||
interface BounceSprite {
|
||||
w: number
|
||||
h: number
|
||||
size: 'large' | 'small'
|
||||
size: QuerySize
|
||||
logo: boolean
|
||||
}
|
||||
|
||||
/** Query with the name logo under him when there is room (large Query only when it all fits). */
|
||||
function bounceSprite(bodyH: number, width: number, logo: NameLogo): BounceSprite {
|
||||
const large = querySize('large')
|
||||
const medium = querySize('medium')
|
||||
const small = querySize('small')
|
||||
const extra = 2 + logo.rows.length
|
||||
if (bodyH >= large.height + extra && width >= Math.max(large.width, logo.w) + 4) return { w: Math.max(large.width, logo.w), h: large.height + extra, size: 'large', logo: true }
|
||||
if (bodyH >= medium.height + extra && width >= Math.max(medium.width, logo.w) + 4) return { w: Math.max(medium.width, logo.w), h: medium.height + extra, size: 'medium', logo: true }
|
||||
if (bodyH >= small.height + extra) return { w: Math.min(width, Math.max(small.width, logo.w)), h: small.height + extra, size: 'small', logo: true }
|
||||
return { w: small.width, h: small.height, size: 'small', logo: false }
|
||||
}
|
||||
@@ -301,7 +303,7 @@ export interface BounceLayout {
|
||||
/** The sprite is drawn (false in the panel half of the alternation). */
|
||||
showSprite: boolean
|
||||
panel?: Box
|
||||
size: 'large' | 'small'
|
||||
size: QuerySize
|
||||
showLogo: boolean
|
||||
dx: 1 | -1
|
||||
dy: 1 | -1
|
||||
@@ -354,7 +356,7 @@ export function bounceLayout(input: SaverInput): BounceLayout {
|
||||
return { ...base, sprite: box, showSprite: true }
|
||||
}
|
||||
|
||||
function drawQuery(c: Canvas, x: number, y: number, size: 'large' | 'small', pose: QueryPose, input: SaverInput, color: string): void {
|
||||
function drawQuery(c: Canvas, x: number, y: number, size: QuerySize, pose: QueryPose, input: SaverInput, color: string): void {
|
||||
c.block(x, y, queryFrame(size, pose, input.ascii), { fg: color, bold: true })
|
||||
}
|
||||
|
||||
@@ -420,13 +422,14 @@ function paintStarfield(c: Canvas, input: SaverInput): Box {
|
||||
c.put(sx, sy, chars[level]!, { fg: level >= 3 ? t.acc2 : level >= 2 ? t.fg : t.dim })
|
||||
}
|
||||
// Query drifts through left to right, bobbing
|
||||
const q = querySize('small')
|
||||
const gsize = guestSize(input.width, bodyH)
|
||||
const q = querySize(gsize)
|
||||
const step = Math.floor(input.now / FRAME_MILLIS)
|
||||
const span = input.width + q.width * 2
|
||||
const qx = (step % span) - q.width
|
||||
const qy = Math.round(1 + bodyH * 0.25 + Math.sin(input.now / 1500) * 2)
|
||||
const pose = queryPoseAt(input.now, { dx: 1, dy: Math.cos(input.now / 1500) > 0 ? 1 : -1 })
|
||||
drawQuery(c, qx, Math.max(1, qy + pose.dy), 'small', pose, input, t.acc2)
|
||||
drawQuery(c, qx, Math.max(1, qy + pose.dy), gsize, pose, input, QUERY_COLOR)
|
||||
// the tiles float in the middle
|
||||
const hud = hudSize(input, input.width - 4, bodyH - 2)
|
||||
const ox = Math.round(Math.sin(input.now / 4000) * 2)
|
||||
@@ -437,6 +440,11 @@ function paintStarfield(c: Canvas, input: SaverInput): Box {
|
||||
return { x: hx, y: hy, w: hud.w, h: hud.h }
|
||||
}
|
||||
|
||||
/** Query's size where he is a guest (not the sprite): medium when the screen is wide and tall enough for him, else small. */
|
||||
function guestSize(width: number, bodyH: number): QuerySize {
|
||||
return width >= 100 && bodyH >= 34 ? 'medium' : 'small'
|
||||
}
|
||||
|
||||
/** Whether the flip clock is mid-flip (the first 500 ms of a minute). */
|
||||
function flipping(now: number): boolean {
|
||||
return now % 60_000 < 500
|
||||
@@ -471,7 +479,8 @@ function paintFlip(c: Canvas, input: SaverInput): Box {
|
||||
const now = hhmm(input.now)
|
||||
const before = hhmm(input.now - (input.now % 60_000) - 1)
|
||||
const half = flipping(input.now) && input.now % 60_000 < 250
|
||||
const q = querySize('small')
|
||||
const qsize = guestSize(input.width, bodyH)
|
||||
const q = querySize(qsize)
|
||||
const columns = input.tiles.length > 1 && input.width >= 100 ? 2 : 1
|
||||
const wantRows = Math.ceil(input.tiles.length / columns)
|
||||
// double-size digits when the screen has room for them and the tiles
|
||||
@@ -488,7 +497,7 @@ function paintFlip(c: Canvas, input: SaverInput): Box {
|
||||
const date = trunc(new Date(input.now).toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }), input.width - 4)
|
||||
const host = trunc(`${input.server} · ${input.profile}`, input.width - 4)
|
||||
// the tiles with Query beside them, bottom-aligned
|
||||
const colW = Math.max(0, Math.min(columns === 2 ? 43 : 56, Math.floor((input.width - 6 - q.width - 3 - (columns - 1) * 3) / columns)))
|
||||
const colW = Math.max(0, Math.min(columns === 2 ? 43 : 56, Math.floor((input.width - 6 - (queryBeside ? q.width + 3 : 0) - (columns - 1) * 3) / columns)))
|
||||
const tilesW = input.tiles.length ? columns * colW + (columns - 1) * 3 : 0
|
||||
const blockW = input.tiles.length ? (queryBeside ? tilesW + 3 + q.width : Math.max(tilesW, q.width)) : q.width
|
||||
const rowsCap = Math.max(1, bodyH - (cardH + 4) - (queryBeside ? 0 : q.height + 1))
|
||||
@@ -537,12 +546,12 @@ function paintFlip(c: Canvas, input: SaverInput): Box {
|
||||
if (input.tiles.length) tileBlock(c, bx, y, input.tiles, columns, colW, tileRows, input)
|
||||
// Query peeks up beside the tiles: ears and eyes, all of him when he hops
|
||||
const pose = queryPoseAt(input.now, { dx: -1 })
|
||||
const shown = Math.min(blockH, pose.action ? q.height : 3)
|
||||
const frame = queryFrame('small', pose, input.ascii).slice(0, shown)
|
||||
const shown = Math.min(blockH, pose.action ? q.height : qsize === 'medium' ? 5 : 3)
|
||||
const frame = queryFrame(qsize, pose, input.ascii).slice(0, shown)
|
||||
const qx = input.tiles.length && queryBeside ? bx + tilesW + 3 : bx + Math.floor((blockW - q.width) / 2)
|
||||
const qy = y + blockH - shown
|
||||
c.fill(qx, qy, q.width, shown, {})
|
||||
c.block(qx, qy, frame, { fg: t.acc2, bold: true })
|
||||
c.block(qx, qy, frame, { fg: QUERY_COLOR, bold: true })
|
||||
return { x: gx, y: gy, w: groupW, h: groupH }
|
||||
}
|
||||
|
||||
@@ -562,7 +571,8 @@ function paintBig(c: Canvas, input: SaverInput): Box {
|
||||
.map((x, i) => ({ x, i }))
|
||||
.sort((a, b) => (b.x.state.value!.interest ?? 0) - (a.x.state.value!.interest ?? 0) || a.i - b.i)
|
||||
.map((e) => e.x)
|
||||
const q = querySize('small')
|
||||
const qsize = guestSize(input.width, bodyH)
|
||||
const q = querySize(qsize)
|
||||
const rotation = Math.floor(input.now / 8000)
|
||||
// compact: the stack is at most about 90 columns wide, however wide the screen
|
||||
const avail = Math.min(input.width - 4, 90)
|
||||
@@ -614,7 +624,7 @@ function paintBig(c: Canvas, input: SaverInput): Box {
|
||||
const color = tile ? (levelColor(t, tile) === t.fg ? t.acc2 : levelColor(t, tile)) : t.acc2
|
||||
const heroX = centred(heroW)
|
||||
if (!tile) {
|
||||
drawQuery(c, heroX, y, 'small', queryPoseAt(input.now), input, t.acc2)
|
||||
drawQuery(c, heroX, y, qsize, queryPoseAt(input.now), input, QUERY_COLOR)
|
||||
} else {
|
||||
const pose: QueryPose = { ...pose0, ...(asleep ? { blink: true, wag: false } : {}) }
|
||||
const numberAt = (x: number, ny: number) => {
|
||||
@@ -622,12 +632,12 @@ function paintBig(c: Canvas, input: SaverInput): Box {
|
||||
else c.put(x, ny, big, { fg: color, bold: true })
|
||||
}
|
||||
if (beside) {
|
||||
drawQuery(c, heroX, y, 'small', pose, input, t.acc2)
|
||||
drawQuery(c, heroX, y, qsize, pose, input, QUERY_COLOR)
|
||||
if (asleep) c.put(heroX + q.width - 1, y - 1, input.now % 2000 < 1000 ? 'z' : 'zZ', { fg: t.dim })
|
||||
numberAt(heroX + q.width + 3, y + Math.floor((heroH - numH) / 2))
|
||||
} else {
|
||||
numberAt(heroX + Math.floor((heroW - numW) / 2), y)
|
||||
drawQuery(c, heroX + Math.floor((heroW - q.width) / 2), y + numH + 1, 'small', pose, input, t.acc2)
|
||||
drawQuery(c, heroX + Math.floor((heroW - q.width) / 2), y + numH + 1, qsize, pose, input, QUERY_COLOR)
|
||||
if (asleep) c.put(heroX + Math.floor((heroW + q.width) / 2) - 1, y + numH, input.now % 2000 < 1000 ? 'z' : 'zZ', { fg: t.dim })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,57 +7,73 @@
|
||||
* Query, the qrun.io mascot, for the screen saver.
|
||||
*
|
||||
* Source: the sitting-dog line drawing on Query's page, https://www.qrun.io/query/ (the inline SVG,
|
||||
* viewBox 0 0 331.41 348.44, that the page's hero bounces). The large art is that drawing traced
|
||||
* into braille dots (2×4 dots per cell, 66×76 dots); the small art is hand-drawn on a 24×24 dot
|
||||
* grid after it. Each braille cell is a bitmap, so the frames are made from the art itself: blink
|
||||
* (the eye's dots cleared), tail wag (the tail's dots moved), mirrored to face the way he drifts,
|
||||
* eyes glancing up or down. The ASCII glyph set gets a plain line-art version of the same bitmap
|
||||
* (hand-drawn for the small size).
|
||||
* viewBox 0 0 331.41 348.44, in one colour: indigo-400, #818cf8). All three sizes are that drawing
|
||||
* rasterised and thresholded into braille dots (2×4 dots per cell) by scripts/gen-query-art.mjs, so
|
||||
* they share its proportions: large 42×22 cells, medium 25×13, small 17×9. Each braille cell is a
|
||||
* bitmap, so the frames are made from the art itself: blink (the eye's dots cleared), tail wag (the
|
||||
* tail's dots moved), mirrored to face the way he drifts, eyes glancing up or down. The ASCII glyph
|
||||
* set gets a plain line-art version of the same bitmap.
|
||||
*/
|
||||
|
||||
export type QuerySize = 'small' | 'large'
|
||||
/** The drawing's colour (the logo's own fill). */
|
||||
export const QUERY_COLOR = '#818cf8'
|
||||
|
||||
/** Large Query, 33×19 cells, facing right. */
|
||||
export type QuerySize = 'small' | 'medium' | 'large'
|
||||
|
||||
/** large Query, 42×22 cells, facing right (generated by scripts/gen-query-art.mjs). */
|
||||
const LARGE = [
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡴⠞⠛⠛⠛⠛⠳⢦⣄⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡾⠋⠀⠀⠀⠀⠀⠀⢀⡀⠹⣇⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀⠀⢠⡆⠀⠀⠀⠀⠸⠗⠀⠻⣤⣤⣤⣀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠈⢿⡀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡼⠋",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀⠀⠀⠀⢸⡇⠀⠀⠀⠘⣿⠛⠛⠋⠉⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢷⣤⣀⣤⡾⠁⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡟⠁⠉⠀⠀⠀⠀⠀⠀⠀⣿⡀⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀",
|
||||
"⠀⠀⠀⠀⠀⠀⠀⢀⡾⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀",
|
||||
"⠀⣀⣀⠀⠀⠀⢀⡾⠁⠀⠀⠀⠀⣤⡴⠶⠶⠶⠶⣤⡀⠀⠀⠀⠀⠀⣰⠏⠀⠀⠀⠀⠀",
|
||||
"⠀⠙⣿⣷⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣆⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀",
|
||||
"⠀⠀⣿⣿⠃⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠀⠈⣷⠀⠀⠀⠀⠀⠀",
|
||||
"⠀⢠⡿⣿⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠟⠀⠀⡀⠀⠀⣿⡀⠀⠀⠀⠀⠀",
|
||||
"⠀⣼⢻⡇⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠟⠁⠀⠀⠀⢿⡀⠀⢸⡇⠀⠀⠀⠀⠀",
|
||||
"⠀⣿⡈⠷⠶⠟⢁⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠛⠛⠛⠳⣦⡸⣧⠀⠈⠛⠳⣦⡀⠀⠀",
|
||||
"⠀⠈⠳⣦⣤⡴⠛⢧⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣼⡇⠹⣦⣤⣤⣤⣬⡗⠀⠀",
|
||||
" ",
|
||||
" ⣀⣀⣄⣀⣀ ",
|
||||
" ⢀⡴⠋⠁ ⠈⠙⢢⡀ ",
|
||||
" ⣰⠋ ⢠⣦ ⣧ ",
|
||||
" ⢰⠇ ⢸⠁ ⠉ ⠈⠓⠒⠲⡆ ",
|
||||
" ⡟ ⢸⡄ ⢠⠇ ",
|
||||
" ⡇ ⢷ ⢀⣀⣀⣤⡤⠴⠋ ",
|
||||
" ⢻⡀ ⣼ ⢸ ",
|
||||
" ⣹⠓⠒⠚⠁ ⢸ ",
|
||||
" ⢀⡴⠃ ⠸⡆ ",
|
||||
" ⢀⡴⠋ ⢧ ",
|
||||
" ⢀⡴⠉ ⢸ ",
|
||||
" ⣰⠋ ⢸⠃ ",
|
||||
" ⡼⠁ ⢀⣀⣀⣀⡀ ⡼ ",
|
||||
" ⠰⣶⣄ ⢰⠃ ⠘⠉⠉ ⠈⠉⠓⣆ ⡼⠁ ",
|
||||
" ⢸⢹ ⡟ ⢸⠆ ⣷ ",
|
||||
" ⣼⣸ ⢠⡇ ⢀⡞ ⢸ ",
|
||||
" ⢠⡇⡏ ⢸⡇ ⢀⡴⠋ ⢰⡀ ⠸⡇ ",
|
||||
" ⢸ ⣇⣀⡼⠁ ⠠⣴⣯⣤⣤⣤⣄ ⣧ ⢧⣤⡀ ",
|
||||
" ⠘⢧⡀⠁⣀⢶⡀ ⠈⢳⠸⣄ ⠙⡆ ",
|
||||
" ⠉⠉⠁ ⠉⠉⠉⠉⠙⠛⠛⠛⠛⠛⠛⠛⠛⠋⠉ ⠈⠉⠉⠉⠉⠁ ",
|
||||
" ",
|
||||
]
|
||||
|
||||
/** Small Query, 12×6 cells, facing right (hand-drawn on 24×24 dots). */
|
||||
/** medium Query, 25×13 cells, facing right (generated by scripts/gen-query-art.mjs). */
|
||||
const MEDIUM = [
|
||||
" ",
|
||||
" ⢀⠔⠋⠉⠉⠑⢆ ",
|
||||
" ⢠⠃ ⡆ ⠛⠘⠤⠤⡀ ",
|
||||
" ⣾ ⢧ ⢀⣀⡼⠁ ",
|
||||
" ⠹⣄⣀⡼ ⢹⠉ ",
|
||||
" ⡰⠃⠁ ⢸⡀ ",
|
||||
" ⢀⡴⠊ ⡇ ",
|
||||
" ⢠⠎ ⡇ ",
|
||||
" ⣦⡀⢠⠇ ⠐⠚⠙⠒⢦ ⣰⠁ ",
|
||||
" ⣸⡇⢸ ⡸ ⢹ ",
|
||||
" ⣿⠁⣸ ⣠⠞⠁⠐⡆⢸⡄ ",
|
||||
" ⢧⣉⡵⣄⣀⣀⣀⣈⣉⣉⣉⣱⢱⣀⣉⣳ ",
|
||||
" ",
|
||||
]
|
||||
|
||||
/** small Query, 17×9 cells, facing right (generated by scripts/gen-query-art.mjs). */
|
||||
const SMALL = [
|
||||
'⠀⠀⠀⠀⢀⠤⠒⠒⠢⢄⠀⠀',
|
||||
'⠀⠀⠀⠀⡇⢸⠀⠁⣀⣀⡩⠕',
|
||||
'⠀⠀⠀⠀⡨⠃⠀⠀⢇⠀⠀⠀',
|
||||
'⠀⡀⢠⠊⢀⠤⢄⠀⢸⠀⠀⠀',
|
||||
'⠀⢇⡇⠀⠀⠀⡠⠃⢸⠀⠀⠀',
|
||||
'⠀⠀⠣⠤⠤⠼⠶⠶⠮⠵⠀⠀',
|
||||
]
|
||||
|
||||
/** Small Query for the ASCII glyph set, 12×6 cells, facing right. */
|
||||
const SMALL_ASCII = [
|
||||
' .--. ',
|
||||
' /( o`-.',
|
||||
" \\_) .-'",
|
||||
' _ / | ',
|
||||
' ( | _/ | ',
|
||||
" `-'--'-' ",
|
||||
" ⣀⣤⣀⡀ ",
|
||||
" ⡞⢡ ⠰⠹⣀⡀ ",
|
||||
" ⢸ ⢸⡀⢀⣀⠤⠃ ",
|
||||
" ⢈⡗⠚ ⠘⡇ ",
|
||||
" ⢀⡴⠋ ⣇ ",
|
||||
" ⢀⡀⢀⠎ ⡠⠤⣀ ⡏ ",
|
||||
" ⡷⡼ ⢨⠃⠸⡄ ",
|
||||
" ⢸⢧⢇ ⠴⠥⢜⡄⠧⡀ ",
|
||||
" ⠉⠉⠓⠒⠒⠒⠒⠊⠙⠒⠃ ",
|
||||
]
|
||||
|
||||
interface Parts {
|
||||
@@ -67,8 +83,9 @@ interface Parts {
|
||||
}
|
||||
|
||||
const PARTS: Record<QuerySize, Parts> = {
|
||||
large: { eye: [51, 7, 53, 10], tail: [2, 51, 8, 68] },
|
||||
small: { eye: [14, 4, 14, 4], tail: [2, 15, 3, 18] },
|
||||
large: { eye: [57,13,59,16], tail: [0,55,17,87] },
|
||||
medium: { eye: [34,8,35,9], tail: [0,32,10,51] },
|
||||
small: { eye: [23,5,23,6], tail: [0,22,7,35] },
|
||||
}
|
||||
|
||||
// braille dot bits by (column, row) inside a cell
|
||||
@@ -158,11 +175,11 @@ export function mirrorAscii(row: string): string {
|
||||
return [...row].reverse().map((c) => MIRROR[c] ?? c).join('')
|
||||
}
|
||||
|
||||
const BASE: Record<QuerySize, Bitmap> = { large: decodeBraille(LARGE), small: decodeBraille(SMALL) }
|
||||
const BASE: Record<QuerySize, Bitmap> = { large: decodeBraille(LARGE), medium: decodeBraille(MEDIUM), small: decodeBraille(SMALL) }
|
||||
|
||||
/** Width and height in cells of Query at a size. */
|
||||
export function querySize(size: QuerySize): { width: number; height: number } {
|
||||
return size === 'large' ? { width: 33, height: 19 } : { width: 12, height: 6 }
|
||||
return size === 'large' ? { width: 42, height: 22 } : size === 'medium' ? { width: 25, height: 13 } : { width: 17, height: 9 }
|
||||
}
|
||||
|
||||
export interface QueryPose {
|
||||
@@ -178,12 +195,6 @@ export interface QueryPose {
|
||||
|
||||
/** One frame of Query: rows of text (braille, or ASCII line art), all the same width. */
|
||||
export function queryFrame(size: QuerySize, pose: QueryPose = {}, ascii = false): string[] {
|
||||
if (ascii && size === 'small') {
|
||||
let rows = SMALL_ASCII.map((r) => (pose.blink ? r.replace('o', '-') : r))
|
||||
if (pose.wag) rows = rows.map((r, i) => (i === 3 ? ` _${r.slice(2)}` : i === 4 ? `( ${r.slice(3)}` : r))
|
||||
if (pose.facing === 'left') rows = rows.map(mirrorAscii)
|
||||
return rows
|
||||
}
|
||||
const parts = PARTS[size]
|
||||
const bits = BASE[size].map((r) => [...r])
|
||||
const [ex0, ey0, ex1, ey1] = parts.eye
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* | tile | needs | reads |
|
||||
* |---------|----------------------|----------------------------------------------------------|
|
||||
* | people | collaboration | GET presence per table, a few tables per refresh |
|
||||
* | people | session store, or collaboration | the session table (sessions active in the last 10 minutes), else GET presence per table, a few tables per refresh |
|
||||
* | jobs | durableJobs feature | GET /jobs?state=recent (scope all, else mine) |
|
||||
* | health | health | GET /health/summary |
|
||||
* | db | db-performance | GET overview + activity |
|
||||
@@ -34,6 +34,8 @@ export interface SaverContext {
|
||||
events: EventRate
|
||||
/** Tables to sample for presence, most likely first (favourites, recents, then the rest). */
|
||||
presenceTables(): string[]
|
||||
/** The server's session table (the session store qbit's), when it has one the user can read. */
|
||||
sessionTable?(): string | undefined
|
||||
/** The profile's favourite tables (count tiles). */
|
||||
favouriteTables: string[]
|
||||
tableLabel(name: string): string
|
||||
@@ -51,22 +53,75 @@ interface Viewer {
|
||||
mode?: string
|
||||
}
|
||||
|
||||
/** Everyone seen in presence lately across the sampled tables (this terminal is not: it left). */
|
||||
/** Sessions that count as online: active in the last 10 minutes. */
|
||||
export const SESSION_ACTIVE_MILLIS = 10 * 60_000
|
||||
|
||||
function userLabel(userId: string): string {
|
||||
return userId.includes(':') ? userId.slice(userId.indexOf(':') + 1) : userId
|
||||
}
|
||||
|
||||
/**
|
||||
* Who is online: signed-in sessions from the session store's table when the server has one and it
|
||||
* holds sessions active in the last 10 minutes (own sessions count: "2 sessions · 1 user (you ×2)"),
|
||||
* else this terminal plus everyone seen in collaboration presence across a few tables per refresh
|
||||
* (the saver keeps its lease, so the signed-in viewer is always one of them). Never "nobody around"
|
||||
* while the viewer is signed in.
|
||||
*/
|
||||
export function presenceSource(ctx: SaverContext): TileSource {
|
||||
const seen = new Map<string, { name: string; table: string; mode?: string; at: number }>()
|
||||
const skip = new Set<string>()
|
||||
let cursor = 0
|
||||
let sessionsGone = false
|
||||
const now = ctx.now ?? Date.now
|
||||
const names = new Map<string, string>()
|
||||
|
||||
async function sessions(): Promise<TileValue | undefined> {
|
||||
const table = ctx.sessionTable?.()
|
||||
if (!table || sessionsGone) return undefined
|
||||
const cutoff = new Date(now() - SESSION_ACTIVE_MILLIS).toISOString()
|
||||
let rows: Array<{ values: Record<string, unknown> }>
|
||||
try {
|
||||
rows = await ctx.client.query(table, {
|
||||
criteria: [{ fieldName: 'modifyDate', operator: 'GREATER_THAN', values: [cutoff] }, { fieldName: 'expiresAt', operator: 'GREATER_THAN', values: [new Date(now()).toISOString()] }],
|
||||
booleanOperator: 'AND', limit: 500,
|
||||
})
|
||||
} catch (error) {
|
||||
const status = (error as { status?: number }).status
|
||||
if (status === 403 || status === 404) sessionsGone = true
|
||||
return undefined
|
||||
}
|
||||
if (!rows.length) return undefined
|
||||
const self = ctx.status()
|
||||
const perUser = new Map<string, number>()
|
||||
for (const r of rows) {
|
||||
const id = String(r.values.userId ?? '')
|
||||
if (id) perUser.set(id, (perUser.get(id) ?? 0) + 1)
|
||||
}
|
||||
const isSelf = (id: string) => id === self.userId || (Boolean(self.user) && (names.get(id) === self.user || userLabel(id).toLowerCase() === self.user.toLowerCase()))
|
||||
const list = [...perUser.entries()].sort((a, b) => Number(isSelf(b[0])) - Number(isSelf(a[0])) || a[0].localeCompare(b[0]))
|
||||
const who = list.map(([id, n]) => `${isSelf(id) ? 'you' : names.get(id) ?? userLabel(id)}${n > 1 ? ` ×${n}` : ''}`)
|
||||
const total = rows.length
|
||||
const users = perUser.size
|
||||
return {
|
||||
value: `${total} online`,
|
||||
detail: `${total} session${total === 1 ? '' : 's'} · ${users} user${users === 1 ? '' : 's'} (${who.join(', ')})`,
|
||||
big: String(total), interest: 50 + total, level: 'ok',
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: 'people', label: 'Online', needs: 'collaboration',
|
||||
present: () => ctx.has('collaboration'),
|
||||
id: 'people', label: 'Online', needs: 'collaboration or the session store',
|
||||
present: () => ctx.has('collaboration') || Boolean(ctx.sessionTable?.()),
|
||||
async load(): Promise<TileValue> {
|
||||
const all = ctx.presenceTables().filter((t) => !skip.has(t))
|
||||
if (!all.length) throw new SourceAbsent('no tables to watch')
|
||||
const bySession = await sessions()
|
||||
if (bySession) return bySession
|
||||
const self = ctx.status()
|
||||
const signedIn = Boolean(self.userId || self.user)
|
||||
const all = ctx.has('collaboration') ? ctx.presenceTables().filter((t) => !skip.has(t)) : []
|
||||
if (!all.length && !signedIn) throw new SourceAbsent('no tables to watch')
|
||||
const batch: string[] = []
|
||||
for (let i = 0; i < Math.min(PRESENCE_TABLES_PER_REFRESH, all.length); i++) batch.push(all[(cursor + i) % all.length]!)
|
||||
cursor = (cursor + batch.length) % Math.max(1, all.length)
|
||||
const self = ctx.status()
|
||||
let failures = 0
|
||||
await Promise.all(batch.map(async (table) => {
|
||||
try {
|
||||
@@ -74,10 +129,11 @@ export function presenceSource(ctx: SaverContext): TileSource {
|
||||
const t = now()
|
||||
for (const [id, v] of seen) if (v.table === table) seen.delete(id)
|
||||
for (const v of snap.viewers ?? []) {
|
||||
// this terminal left presence when the saver came up: the signed-in user seen here is
|
||||
// another session of theirs (a browser tab, another terminal)
|
||||
const you = v.userId === self.userId || (Boolean(self.user) && v.displayName === self.user)
|
||||
seen.set(v.userId, { name: you ? 'you elsewhere' : v.displayName || v.userId, table, mode: v.mode, at: t })
|
||||
// this terminal is you (it keeps its lease while the saver shows): not a second person
|
||||
if (you) continue
|
||||
names.set(v.userId, v.displayName || v.userId)
|
||||
seen.set(v.userId, { name: v.displayName || v.userId, table, mode: v.mode, at: t })
|
||||
}
|
||||
} catch (error) {
|
||||
const status = (error as { status?: number }).status
|
||||
@@ -85,16 +141,16 @@ export function presenceSource(ctx: SaverContext): TileSource {
|
||||
else failures++
|
||||
}
|
||||
}))
|
||||
if (failures === batch.length) throw new Error('presence did not answer')
|
||||
if (batch.length && failures === batch.length && !signedIn) throw new Error('presence did not answer')
|
||||
// a person not seen again within one sweep of the list (plus a lease) has left
|
||||
const ttl = Math.ceil(all.length / PRESENCE_TABLES_PER_REFRESH) * ctx.intervalMs() + 45_000
|
||||
const ttl = Math.ceil(Math.max(1, all.length) / PRESENCE_TABLES_PER_REFRESH) * ctx.intervalMs() + 45_000
|
||||
const t = now()
|
||||
for (const [id, v] of seen) if (t - v.at > ttl) seen.delete(id)
|
||||
const people = [...seen.values()].sort((a, b) => a.name.localeCompare(b.name))
|
||||
const detail = people.length
|
||||
? people.sort((a, b) => Number(a.name === 'you elsewhere') - Number(b.name === 'you elsewhere')).map((p) => `${p.name}${p.mode === 'EDITING' ? ' editing' : ''} · ${ctx.tableLabel(p.table)}`).join(', ')
|
||||
: 'nobody around'
|
||||
return { value: String(people.length), detail, big: String(people.length), interest: people.length ? 50 + people.length : 5 }
|
||||
const others = [...seen.values()].sort((a, b) => a.name.localeCompare(b.name))
|
||||
const total = others.length + (signedIn ? 1 : 0)
|
||||
const parts = [...(signedIn ? ['you'] : []), ...others.map((p) => `${p.name}${p.mode === 'EDITING' ? ' editing' : ''} · ${ctx.tableLabel(p.table)}`)]
|
||||
const detail = parts.length ? `${total} online · ${parts.join(', ')}` : 'nobody around'
|
||||
return { value: String(total), detail, big: String(total), interest: total ? 50 + total : 5 }
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +201,15 @@ export class AppStore {
|
||||
this.bump()
|
||||
}
|
||||
|
||||
/** Tells the presence source which scope is on top (called on every repaint; cheap when unchanged). */
|
||||
/**
|
||||
* Tells the presence source which scope is on top (called on every repaint; cheap when unchanged).
|
||||
* The screen saver or lock keeps the lease on the scope that was on top (the extension has no idle
|
||||
* state: the user stays as a viewer rather than vanishing from the others' screens, as a person
|
||||
* who stepped away from a record) and waking re-syncs.
|
||||
*/
|
||||
private syncPresence(): void {
|
||||
const scope = this.lock ? undefined : this.screen?.presenceScope?.()
|
||||
presenceSource().enter?.(scope)
|
||||
if (this.lock) return
|
||||
presenceSource().enter?.(this.screen?.presenceScope?.())
|
||||
}
|
||||
|
||||
/** Replaces the top screen (a form that saved becomes the record). */
|
||||
|
||||
@@ -16,6 +16,10 @@ export const printing = {
|
||||
enabled: false,
|
||||
/** The 2.1 table-list and text prints (on with the extension unless a test turns them off). */
|
||||
lists: true,
|
||||
/** Save as PDF (printingRenderToPdf). */
|
||||
render: true,
|
||||
/** Render runs: the values each started with. */
|
||||
renders: [] as J[],
|
||||
/** Table-list and text runs: the process and the values it finished with. */
|
||||
listRuns: [] as Array<{ process: string; values: J }>,
|
||||
/** Print runs: the values and record ids each one finished with. */
|
||||
@@ -24,6 +28,8 @@ export const printing = {
|
||||
reset(): void {
|
||||
this.enabled = false
|
||||
this.lists = true
|
||||
this.render = true
|
||||
this.renders = []
|
||||
this.listRuns = []
|
||||
this.runs = []
|
||||
this.jobs.clear()
|
||||
@@ -41,6 +47,7 @@ export function printProcessesMeta(): J {
|
||||
if (!printing.enabled) return {}
|
||||
return {
|
||||
printingPrintRecords_person: { name: 'printingPrintRecords_person', label: 'Print', tableName: 'person' },
|
||||
...(printing.render ? { printingRenderToPdf: { name: 'printingRenderToPdf', label: 'Save as PDF' } } : {}),
|
||||
...(printing.lists ? { printingPrintTableList: { name: 'printingPrintTableList', label: 'Print a table list' }, printingPrintText: { name: 'printingPrintText', label: 'Print text' } } : {}),
|
||||
}
|
||||
}
|
||||
@@ -76,6 +83,16 @@ export async function printRoute(path: string, method: string, body: unknown): P
|
||||
})
|
||||
return json({ type: 'COMPLETE', processUUID: 'pr', nextStep: 'result', values: { printingJobIds: ids.join(',') } })
|
||||
}
|
||||
if (printing.render && path === '/metaData/process/printingRenderToPdf') {
|
||||
return json({ name: 'printingRenderToPdf', label: 'Save as PDF', frontendSteps: [{ name: 'download', label: 'Download', components: [{ type: 'DOWNLOAD_FORM' }], viewFields: [{ name: 'downloadFileName', label: 'File', type: 'STRING' }] }] })
|
||||
}
|
||||
if (printing.render && path === '/processes/printingRenderToPdf/init') {
|
||||
const v = values()
|
||||
printing.renders.push(v)
|
||||
const name = v.kind === 'RECORD' ? `Person-${v.recordId}` : v.kind === 'LIST' ? 'Person' : String(v.title).replace(/[^A-Za-z0-9]+/g, '-')
|
||||
return json({ type: 'COMPLETE', processUUID: 'rd', nextStep: 'download', values: { downloadFileName: `${name}.pdf`, serverFilePath: `/tmp/qqq-print-${printing.renders.length}.pdf` } })
|
||||
}
|
||||
if (printing.render && path.startsWith('/download/')) return new Response(`%PDF-1.7 ${path}`, { status: 200, headers: { 'content-type': 'application/pdf' } })
|
||||
const list = /^\/(?:metaData\/process|processes)\/(printingPrintTableList|printingPrintText)(\/.*)?$/.exec(path)
|
||||
if (list && printing.lists) {
|
||||
const name = list[1]!
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
|
||||
import { afterEach, beforeAll, beforeEach, expect, test } from 'bun:test'
|
||||
import { KeyCodes } from '@opentui/core/testing'
|
||||
import { printerOf, readRememberedPrinter, writeRememberedPrinter } from '@qrun-io/qqq-core'
|
||||
import { captureScreenText, printTargetOf, printerChoices } from '../src/printing'
|
||||
import { printerOf, readRememberedPrinter, writeFilePreferences, writeRememberedPrinter } from '@qrun-io/qqq-core'
|
||||
import { mkdtempSync, readFileSync, readdirSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { captureScreenText, contentSections, printTargetOf, printerChoices } from '../src/printing'
|
||||
import { printing } from './fake-print'
|
||||
import { command, isolate, press, startTui, waitFor, type Harness } from './helpers'
|
||||
|
||||
@@ -14,6 +17,7 @@ let h: Harness | undefined
|
||||
beforeAll(() => isolate())
|
||||
beforeEach(() => {
|
||||
printing.reset()
|
||||
writeFilePreferences({ downloadMode: undefined, downloadDir: undefined })
|
||||
writeRememberedPrinter('fake', undefined)
|
||||
})
|
||||
afterEach(() => {
|
||||
@@ -72,7 +76,7 @@ test('record: p opens the printer picker, Enter prints, the job is followed in t
|
||||
await press(h, () => h!.setup.mockInput.typeText('Virtual PDF'))
|
||||
await enter()
|
||||
await waitFor(h, () => printing.runs.length === 1)
|
||||
expect(printing.runs[0]).toEqual({ values: { printingPrinterId: 'p1', printingCopies: 1 }, recordIds: '2' })
|
||||
expect(printing.runs[0]).toMatchObject({ values: { printingPrinterId: 'p1', printingCopies: 1 }, recordIds: '2' })
|
||||
f = await waitFor(h, (x) => x.includes('Queued a print job for Person First2 Odd on Virtual PDF printer'))
|
||||
expect(h.store.status.print).toBe('print 0/1 QUEUED')
|
||||
await poll()
|
||||
@@ -102,7 +106,7 @@ test('grid: Space selects records, p, "a record sheet for each selected row" pri
|
||||
expect(f).toContain('Back office laser (last used)')
|
||||
await enter()
|
||||
await waitFor(h, () => printing.runs.length === 1)
|
||||
expect(printing.runs[0]).toEqual({ values: { printingPrinterId: 'p3', printingCopies: 1 }, recordIds: '1,2' })
|
||||
expect(printing.runs[0]).toMatchObject({ values: { printingPrinterId: 'p3', printingCopies: 1 }, recordIds: '1,2' })
|
||||
await waitFor(h, () => h!.store.status.print === 'print 0/2 QUEUED')
|
||||
await poll()
|
||||
await poll()
|
||||
@@ -206,20 +210,88 @@ test('Ctrl+P on a record prints its record sheet; F8 says Print where there is n
|
||||
expect(f).toContain('8Print')
|
||||
expect(printTargetOf(h.store.screen)).toEqual({ kind: 'text', title: h.store.screen!.title() })
|
||||
await press(h, () => h!.setup.mockInput.pressKey(KeyCodes.F8))
|
||||
f = await waitFor(h, (x) => x.includes('Print this screen'))
|
||||
f = await waitFor(h, (x) => x.includes('Print what?'))
|
||||
// Content first (the default), Screen second
|
||||
expect(f.indexOf('Content')).toBeLessThan(f.indexOf('Screen '))
|
||||
await enter()
|
||||
f = await waitFor(h, (x) => x.includes('Print the content of'))
|
||||
await enter()
|
||||
await waitFor(h, () => printing.listRuns.at(-1)?.values.printingPrinterId !== undefined)
|
||||
const run = printing.listRuns.at(-1)!
|
||||
expect(run.process).toBe('printingPrintText')
|
||||
const sections = JSON.parse(String(run.values.sections)) as Array<{ title: string; lines: string[] }>
|
||||
expect(sections.length).toBeGreaterThan(0)
|
||||
const content = JSON.stringify(sections)
|
||||
expect(content).not.toContain('Apps (Tab)')
|
||||
expect(content).not.toContain('│')
|
||||
expect(content).not.toContain('1Help')
|
||||
// the app header and footer
|
||||
expect(run.values.headerApp).toBe('Fake')
|
||||
expect(run.values.headerTitle).toBe(h.store.screen!.title())
|
||||
expect(String(run.values.headerServer)).toContain('fake.test')
|
||||
expect(run.values.headerUser).toBe(h.store.status.user)
|
||||
expect(String(run.values.headerPrintedAt)).toMatch(/\d/)
|
||||
expect(String(run.values.footerLeft)).toMatch(/^qqq ui \d+\.\d+\.\d+ · .*fake\.test/)
|
||||
})
|
||||
|
||||
test('Print what? → Screen prints the terminal as drawn; a record print carries the breadcrumb', async () => {
|
||||
printing.enabled = true
|
||||
h = await startTui(120, 36)
|
||||
await ctrlP()
|
||||
await waitFor(h, (x) => x.includes('Print what?'))
|
||||
await arrow('down')
|
||||
await enter()
|
||||
await waitFor(h, (x) => x.includes('Print this screen'))
|
||||
await enter()
|
||||
await waitFor(h, () => printing.listRuns.at(-1)?.values.printingPrinterId !== undefined)
|
||||
const run = printing.listRuns.at(-1)!
|
||||
expect(run.values.sections).toBeUndefined()
|
||||
expect(String(run.values.text)).toContain('Apps')
|
||||
expect(String(run.values.text)).not.toContain('1Help')
|
||||
await command(h, 'table get person 2')
|
||||
await waitFor(h, (f) => f.includes('First2 Odd'))
|
||||
await ctrlP()
|
||||
await waitFor(h, (x) => x.includes('Print Person First2 Odd on…'))
|
||||
await press(h, () => h!.setup.mockInput.typeText('Virtual PDF'))
|
||||
await enter()
|
||||
await waitFor(h, () => printing.runs.length === 1)
|
||||
expect(printing.runs[0]!.values.headerTitle).toBe('People › Person › First2 Odd')
|
||||
})
|
||||
|
||||
test('content sections: the content panel only, inner panels as titled sections in reading order, no borders, no key hint', () => {
|
||||
const frame = [
|
||||
' Fake ─ Home Tester ',
|
||||
'┌─ Apps (Tab) ─┐┌─ Home ───────────────────────────────────────────┐',
|
||||
'│▸ People ││Good morning, Tester │',
|
||||
'│ ││┌─ Recently viewed ─┐┌─ Quick actions ───────────┐ │',
|
||||
'│ │││ Ada Lovelace ││ ▷ Simple Sleep run │ │',
|
||||
'│ │││ Blair Sample ││ + New Person create │ │',
|
||||
'│ ││└───────────────────┘└───────────────────────────┘ │',
|
||||
'│ ││ Applications (2) │',
|
||||
'│ ││ a actions · Tab panels · Esc back │',
|
||||
'└──────────────┘└───────────────────────────────────────────────────┘',
|
||||
' fake.test · fake · mock session · jobs n/a ',
|
||||
' 1Help 2Search 8Print ',
|
||||
].join('\n')
|
||||
const sections = contentSections(frame)
|
||||
expect(sections).toEqual([
|
||||
{ title: '', lines: ['Good morning, Tester'] },
|
||||
{ title: 'Recently viewed', lines: ['Ada Lovelace', 'Blair Sample'] },
|
||||
{ title: 'Quick actions', lines: ['▷ Simple Sleep run', '+ New Person create'] },
|
||||
{ title: '', lines: ['Applications (2)'] },
|
||||
])
|
||||
expect(contentSections('')).toEqual([])
|
||||
// a panel cut off by the bottom of the content panel still becomes a section
|
||||
const clipped = [' t', '┌─ Main ──────────────┐', '│┌─ Apps grid ───────┐│', '││ Alerts Cluster ││', '││ 3 tables ││', ' status', ' keys'].join('\n')
|
||||
expect(contentSections(clipped)).toEqual([{ title: 'Apps grid', lines: ['Alerts Cluster', '3 tables'] }])
|
||||
})
|
||||
|
||||
|
||||
test('Print Screen (when the terminal passes it on) and :print <printer> print without the picker', async () => {
|
||||
printing.enabled = true
|
||||
h = await startTui(120, 36)
|
||||
await press(h, () => h!.store.handleKey({ name: 'printscreen', sequence: '' } as never))
|
||||
await waitFor(h, (x) => x.includes('Print this screen'))
|
||||
await waitFor(h, (x) => x.includes('Print what?'))
|
||||
await esc()
|
||||
await command(h, 'print back office')
|
||||
await waitFor(h, () => printing.listRuns.length === 1 && printing.listRuns[0]!.values.printingPrinterId === 'p3')
|
||||
@@ -232,3 +304,67 @@ test('the screen capture drops the status line and the function-key bar and trim
|
||||
expect(captureScreenText(store)).toBe(' Title bar\n body line')
|
||||
expect(captureScreenText({} as never)).toBe('')
|
||||
})
|
||||
|
||||
test('Save as PDF is the first picker entry: a record renders on the server and saves like a download (silent mode: the download folder, stamped name)', async () => {
|
||||
printing.enabled = true
|
||||
const folder = mkdtempSync(join(tmpdir(), 'qqq-tui-pdf-'))
|
||||
writeFilePreferences({ downloadMode: 'silent', downloadDir: folder })
|
||||
h = await startTui(120, 36)
|
||||
await command(h, 'table get person 2')
|
||||
await waitFor(h, (f) => f.includes('First2 Odd'))
|
||||
await ctrlP()
|
||||
const f = await waitFor(h, (x) => x.includes('Print Person First2 Odd on…'))
|
||||
const picker = f.split('\n').filter((l) => l.includes('║'))
|
||||
expect(picker.findIndex((l) => l.includes('Save as PDF…'))).toBeLessThan(picker.findIndex((l) => l.includes('Back office laser')))
|
||||
await press(h, () => h!.setup.mockInput.typeText('Save as PDF'))
|
||||
await enter()
|
||||
await waitFor(h, (x) => x.includes('Saved '))
|
||||
expect(printing.renders).toMatchObject([{ kind: 'RECORD', tableName: 'person', recordId: '2' }])
|
||||
expect(printing.runs).toEqual([])
|
||||
const files = readdirSync(folder)
|
||||
expect(files.length).toBe(1)
|
||||
expect(files[0]).toMatch(/^Person-2_\d{4}-\d{2}-\d{2}_\d{6}\.pdf$/)
|
||||
expect(readFileSync(join(folder, files[0]!), 'utf8')).toStartWith('%PDF-1.7 /download/Person-2.pdf')
|
||||
})
|
||||
|
||||
test('Save as PDF on a grid saves the table list; with the dialog (default mode) the save dialog offers the stamped name', async () => {
|
||||
printing.enabled = true
|
||||
h = await startTui(140, 40)
|
||||
await command(h, 'table query person -w "lastName = Odd"')
|
||||
await waitFor(h, (f) => f.includes('First2 '))
|
||||
await ctrlP()
|
||||
await waitFor(h, (x) => x.includes('Print Person: what?'))
|
||||
await enter()
|
||||
await waitFor(h, (x) => x.includes('Print Person: 15 rows on…'))
|
||||
await press(h, () => h!.setup.mockInput.typeText('Save as PDF'))
|
||||
await enter()
|
||||
const f = await waitFor(h, (x) => x.includes('Save as PDF') && /Person_\d{4}-\d{2}-\d{2}_\d{6}\.pdf/.test(x))
|
||||
expect(f).toContain('Name')
|
||||
const render = printing.renders[0]!
|
||||
expect(render.kind).toBe('LIST')
|
||||
expect(render.scope).toBe('ALL')
|
||||
expect(JSON.parse(String(render.filterJSON)).criteria[0]).toMatchObject({ fieldName: 'lastName', values: ['Odd'] })
|
||||
expect(render.printingPrinterId).toBeUndefined()
|
||||
})
|
||||
|
||||
test(':print pdf saves the screen as a PDF without the picker; a server without the render process shows no Save as PDF entry', async () => {
|
||||
printing.enabled = true
|
||||
const folder = mkdtempSync(join(tmpdir(), 'qqq-tui-pdf-'))
|
||||
writeFilePreferences({ downloadMode: 'silent', downloadDir: folder })
|
||||
h = await startTui(120, 36)
|
||||
await command(h, 'print pdf')
|
||||
await waitFor(h, (x) => x.includes('Saved '))
|
||||
expect(printing.renders[0]!.kind).toBe('TEXT')
|
||||
expect(String(printing.renders[0]!.text)).toContain('Apps')
|
||||
expect(readdirSync(folder)[0]).toMatch(/_\d{4}-\d{2}-\d{2}_\d{6}\.pdf$/)
|
||||
await esc()
|
||||
printing.render = false
|
||||
// F10 › Reset refreshes the metadata: the render process is gone
|
||||
await command(h, 'reset')
|
||||
await waitFor(h, () => h!.store.screen?.kind === 'home')
|
||||
await command(h, 'table get person 2')
|
||||
await waitFor(h, (x) => x.includes('First2 Odd'))
|
||||
await ctrlP()
|
||||
const f = await waitFor(h, (x) => x.includes('Print Person First2 Odd on…'))
|
||||
expect(f).not.toContain('Save as PDF…')
|
||||
})
|
||||
@@ -7,6 +7,7 @@ import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
|
||||
import { removePin, setPin } from '@qrun-io/qqq-core'
|
||||
import { UiApiError } from '@qrun-io/qqq-ui-api-client'
|
||||
import { SaverOverlay } from '../src/overlays/saver'
|
||||
import { setPresenceSource } from '../src/presence'
|
||||
import { FONT_HEIGHT, blockText, blockWidth, canDraw } from '../src/saver/font'
|
||||
import { ALTERNATE_MILLIS, AUTO_STYLE_MILLIS, FRAME_MILLIS, SHIFT_MILLIS, bounce, bounceLayout, isDimmed, logoName, nextFrameDelay, paintSaver, saverFrame, styleAt, type SaverInput, type SaverTile } from '../src/saver/layout'
|
||||
import { EventRate, MAX_BACKOFF_MS, TileModel, isAbsent, sparkline, type TileSource, type TileValue } from '../src/saver/model'
|
||||
@@ -126,17 +127,53 @@ describe('sources', () => {
|
||||
const s = presenceSource(ctx({ now: () => t, data: (_id, input) => ({ viewers: viewers[(input as { query: { table: string } }).query.table] ?? [] }) }))
|
||||
const v = await s.load()
|
||||
expect(v.value).toBe('3')
|
||||
expect(v.detail).toMatch(/^Bob · PERSON, Carol editing · ORDER, you elsewhere · PERSON$/)
|
||||
expect(v.detail).toBe('3 online · you, Bob · PERSON, Carol editing · ORDER')
|
||||
viewers.person = []
|
||||
viewers.order = []
|
||||
t = 120_000
|
||||
expect((await s.load()).value).toBe('0')
|
||||
expect((await s.load()).value).toBe('1')
|
||||
})
|
||||
|
||||
test('presence on a table that refuses it is skipped; the source hides when nothing is left', async () => {
|
||||
const s = presenceSource(ctx({ data: () => { throw new UiApiError(404, {}) } }))
|
||||
await s.load()
|
||||
await expect(s.load()).rejects.toThrow('no tables')
|
||||
const refuse = () => { throw new UiApiError(404, {}) }
|
||||
// signed out: nothing to show once every table refuses
|
||||
const out = presenceSource(ctx({ status: () => ({ apiVersion: '1', pingMs: 1, stream: 'connected', lastEvent: '', user: '' }), data: refuse }))
|
||||
await out.load()
|
||||
await expect(out.load()).rejects.toThrow('no tables')
|
||||
// signed in: never "nobody around", this terminal is online
|
||||
const me = presenceSource(ctx({ data: refuse }))
|
||||
await me.load()
|
||||
const v = await me.load()
|
||||
expect(v.value).toBe('1')
|
||||
expect(v.detail).toBe('1 online · you')
|
||||
})
|
||||
|
||||
test('online by session: sessions active in the last 10 minutes, own sessions counted, others by user', async () => {
|
||||
const queries: unknown[] = []
|
||||
const rows = [{ userId: 'core:me' }, { userId: 'core:me' }, { userId: 'core:bob' }]
|
||||
const client = { query: async (_t: string, f: unknown) => { queries.push(f); return rows.map((values) => ({ values })) }, data: async () => ({}), count: async () => 0 }
|
||||
const mk = (over: Partial<SaverContext> & { data?: (id: string, input: unknown) => unknown } = {}) => ctx({ client: client as never, sessionTable: () => 'storedSession', now: () => 1_000_000_000_000, ...over })
|
||||
const v = await presenceSource(mk()).load()
|
||||
expect(v.value).toBe('3 online')
|
||||
expect(v.detail).toBe('3 sessions · 2 users (you ×2, bob)')
|
||||
expect(v.big).toBe('3')
|
||||
const f = queries[0] as { criteria: Array<{ fieldName: string; operator: string; values: string[] }> }
|
||||
expect(f.criteria[0]).toMatchObject({ fieldName: 'modifyDate', operator: 'GREATER_THAN', values: [new Date(1_000_000_000_000 - 600_000).toISOString()] })
|
||||
// the owner's case: the same user twice
|
||||
rows.splice(2, 1)
|
||||
expect((await presenceSource(mk()).load()).detail).toBe('2 sessions · 1 user (you ×2)')
|
||||
// an empty session table (a mock-auth server stores none) falls back to presence and still counts you
|
||||
rows.length = 0
|
||||
const fb = await presenceSource(mk({ data: () => ({ viewers: [] }) })).load()
|
||||
expect(fb.value).toBe('1')
|
||||
expect(fb.detail).toBe('1 online · you')
|
||||
// no session table, no collaboration: the tile hides
|
||||
expect(presenceSource(ctx({ has: () => false })).present()).toBe(false)
|
||||
expect(presenceSource(ctx({ has: () => false, sessionTable: () => 'storedSession' })).present()).toBe(true)
|
||||
// a session table the user may not read is skipped for good
|
||||
const denied = { ...client, query: async () => { throw new UiApiError(403, {}) } }
|
||||
const d = presenceSource(mk({ client: denied as never, data: () => ({ viewers: [] }) }))
|
||||
expect((await d.load()).value).toBe('1')
|
||||
})
|
||||
|
||||
test('jobs: counts by status, falls back to my jobs on 403', async () => {
|
||||
@@ -170,7 +207,7 @@ describe('sources', () => {
|
||||
|
||||
describe('Query', () => {
|
||||
test('both sizes have their documented size; braille round-trips; mirrored and blinking frames differ', () => {
|
||||
for (const size of ['small', 'large'] as const) {
|
||||
for (const size of ['small', 'medium', 'large'] as const) {
|
||||
const { width, height } = querySize(size)
|
||||
const frame = queryFrame(size)
|
||||
expect(frame.length).toBe(height)
|
||||
@@ -187,6 +224,49 @@ describe('Query', () => {
|
||||
expect(mirrorAscii("(/`")).toBe("'\\)")
|
||||
})
|
||||
|
||||
test('every size keeps the logo\'s silhouette: floppy ear left of the head and snout, tail curled at the low left, sitting body, front legs and the ground line at the bottom', () => {
|
||||
expect(querySize('large')).toEqual({ width: 42, height: 22 })
|
||||
expect(querySize('medium')).toEqual({ width: 25, height: 13 })
|
||||
expect(querySize('small')).toEqual({ width: 17, height: 9 })
|
||||
for (const size of ['large', 'medium', 'small'] as const) {
|
||||
const rows = queryFrame(size)
|
||||
const bits = decodeBraille(rows)
|
||||
const H = bits.length
|
||||
const W = bits[0]!.length
|
||||
const dots = (y0: number, y1: number, x0 = 0, x1 = W) => {
|
||||
const out: Array<[number, number]> = []
|
||||
for (let y = Math.floor(y0 * H); y < Math.ceil(y1 * H); y++) for (let x = Math.floor(x0 * W); x < Math.ceil(x1 * W); x++) if (bits[y]?.[x]) out.push([x, y])
|
||||
return out
|
||||
}
|
||||
const minX = (d: Array<[number, number]>) => Math.min(...d.map((p) => p[0]))
|
||||
const maxX = (d: Array<[number, number]>) => Math.max(...d.map((p) => p[0]))
|
||||
// the picture is the logo's: dots across the whole height and most of the width, nothing past the cells
|
||||
expect(dots(0, 1).length).toBeGreaterThan(H)
|
||||
expect(rows.length).toBe(querySize(size).height)
|
||||
// head and ear: the top third; the ear (its left edge) is well left of the snout (the right edge), the snout is the rightmost thing up there
|
||||
const head = dots(0, 0.34)
|
||||
expect(head.length).toBeGreaterThan(5)
|
||||
expect(maxX(head)).toBeGreaterThan(W * 0.7)
|
||||
expect(minX(head)).toBeLessThan(W * 0.55)
|
||||
expect(maxX(head) - minX(head)).toBeGreaterThan(W * 0.3)
|
||||
// the top of the head sits above the middle of the back, right of the tail
|
||||
expect(minX(head)).toBeGreaterThan(W * 0.2)
|
||||
// the tail: ink in the low-left corner, left of where the body's back reaches the ground
|
||||
const tail = dots(0.6, 1, 0, 0.22)
|
||||
expect(tail.length).toBeGreaterThan(4)
|
||||
// the sitting body: the chest edge at the right in the middle rows and the haunch at the left
|
||||
const middle = dots(0.4, 0.75)
|
||||
expect(maxX(middle)).toBeGreaterThan(W * 0.6)
|
||||
expect(minX(middle)).toBeLessThan(W * 0.5)
|
||||
// front legs and the ground line: the bottom row of cells spans most of the width
|
||||
const ground = dots(0.84, 1)
|
||||
expect(maxX(ground) - minX(ground)).toBeGreaterThan(W * 0.6)
|
||||
expect(maxX(ground)).toBeGreaterThan(W * 0.7)
|
||||
// the eye is inside the head, right of the ear's left edge
|
||||
expect(queryFrame(size, { blink: true })).not.toEqual(rows)
|
||||
}
|
||||
})
|
||||
|
||||
test('poses: blinks, acts every ten seconds, faces the way he drifts', () => {
|
||||
expect(queryPoseAt(0).blink).toBe(true)
|
||||
expect(queryPoseAt(1000).blink).toBe(false)
|
||||
@@ -520,7 +600,7 @@ describe('burn-in guard', () => {
|
||||
const cy = (minY + maxY) / 2
|
||||
for (const r of spans) {
|
||||
expect(Math.abs((r.from + r.to) / 2 - cx)).toBeLessThanOrEqual(width * 0.4)
|
||||
expect(Math.abs(r.y - cy)).toBeLessThanOrEqual(height * 0.4 + 1)
|
||||
expect(Math.abs(r.y - cy)).toBeLessThanOrEqual(height * 0.4 + 2)
|
||||
}
|
||||
{
|
||||
// the group as a whole stays near the middle of the screen, fully on it
|
||||
@@ -688,6 +768,31 @@ describe('in the TUI', () => {
|
||||
await command(h, 'saver dim 10')
|
||||
})
|
||||
|
||||
test('the saver keeps the presence lease of the screen under it (others see an idle viewer, not a gone one); waking resyncs', async () => {
|
||||
const calls: Array<string | undefined> = []
|
||||
const none = { count: 0, people: [] }
|
||||
setPresenceSource({ get: () => none, subscribe: () => () => undefined, enter: (scope) => { calls.push(scope) } })
|
||||
try {
|
||||
await command(h, 'table query person')
|
||||
await waitFor(h, (f) => f.includes('30 records'))
|
||||
expect(calls.at(-1)).toBe('table:person')
|
||||
calls.length = 0
|
||||
await command(h, 'saver flip')
|
||||
await waitFor(h, (f) => f.includes('preview: flip'))
|
||||
// never left (the same scope may be announced again; the source ignores a repeat)
|
||||
expect(calls.every((c) => c === 'table:person')).toBe(true)
|
||||
await press(h, () => h.setup.mockInput.typeText('x'))
|
||||
expect(h.store.lock).toBeUndefined()
|
||||
h.store.bump()
|
||||
await waitFor(h, (f) => f.includes('30 records'))
|
||||
expect(calls.includes(undefined)).toBe(false)
|
||||
expect(calls.every((c) => c === 'table:person')).toBe(true)
|
||||
} finally {
|
||||
setPresenceSource(undefined)
|
||||
h.store.back()
|
||||
}
|
||||
})
|
||||
|
||||
test('F9 → Settings lists the saver style, refresh and preview', () => {
|
||||
const labels = (h.store.commands() as unknown as { entries(f: string): Array<{ label: string }> }).entries('').map((e) => e.label)
|
||||
expect(labels.some((l) => l.startsWith('Screen saver style:'))).toBe(true)
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
# QQQ_PRINT_AGENT_DIR qqq-print-agent checkout with tools/virtual-agent
|
||||
# (default <QRun-IO>/qqq-print-agent next to this repo)
|
||||
# QQQ_PRINT_STATE pid, log and device identity (default ${TMPDIR:-/tmp}/qqq-print-agent-<port>)
|
||||
# QQQ_PRINT_OUT where printed documents go (default <state>/printed)
|
||||
# QQQ_PRINT_OUT where printed documents go (default ~/Downloads, as downloads and exports;
|
||||
# the agent's own default too); --dir prints the folder in use
|
||||
# QQQ_PRINT_PRINTER_NAME, QQQ_PRINT_DEVICE_NAME names shown in QQQ
|
||||
#
|
||||
# Then, from the CLI: qqq printer list; qqq print person 1 --printer "Virtual PDF printer"
|
||||
@@ -31,7 +32,7 @@ agent="$agent_dir/tools/virtual-agent/virtual-agent.mjs"
|
||||
port="$(node -e 'const u=new URL(process.argv[1]); console.log(u.port || (u.protocol === "https:" ? 443 : 80))' "$server")"
|
||||
tmp_root="${TMPDIR:-/tmp}"; state_dir="${QQQ_PRINT_STATE:-${tmp_root%/}/qqq-print-agent-$port}"
|
||||
state_dir="${state_dir%/}"
|
||||
out_dir="${QQQ_PRINT_OUT:-$state_dir/printed}"
|
||||
out_dir="${QQQ_PRINT_OUT:-$HOME/Downloads}"
|
||||
pid_file="$state_dir/agent.pid"
|
||||
log_file="$state_dir/agent.log"
|
||||
identity="$state_dir/device.json"
|
||||
|
||||
Reference in new issue
Block a user