forked from Blendman974/faceclaw
Use TTF fonts throughout the UI; also add some more functions to app extension API
This commit is contained in:
1 parent
5abbe2a405
commit
96842ceb23
82 files changed
+2666
-288
No files matched your search
@@ -31,10 +31,10 @@
|
||||
* re-attach snapshot resyncs contents and scrollback only once it's needed.
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
|
||||
import { TERMINAL_ICON_GLYPHS } from "../../graphics/icons";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
@@ -77,19 +77,25 @@ import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
|
||||
declare const global: any;
|
||||
declare const com: any;
|
||||
|
||||
// Terminus-12 has a 6x12 cell; each window derives its grid from the
|
||||
// viewport in its open-window message (the hub is min-height, session views
|
||||
// full-height). The websocket init handshake declares the view grid.
|
||||
const terminalFont = getFont("terminus12");
|
||||
const CELL_WIDTH = 6;
|
||||
const CELL_HEIGHT = 12;
|
||||
// Cell geometry comes from the terminal font setting (Settings > Terminal >
|
||||
// Font; the default is Terminus-12's 6x12). Each window derives its grid from
|
||||
// the viewport in its open-window message (the hub is min-height, session
|
||||
// views full-height). Grid dimensions are baked into each session's websocket
|
||||
// handshake, so windows and control connections capture the cell size at
|
||||
// creation — a font change applies to ones (re)opened afterwards.
|
||||
function chromeFont(): UiFont {
|
||||
return getDefaultSmallFont();
|
||||
}
|
||||
// Grid of a session view window (full-height); also declared on the control
|
||||
// connections so sessions launched from presets come up at view size.
|
||||
const VIEW_VIEWPORT = appViewportSize("max");
|
||||
const VIEW_GRID = {
|
||||
cols: Math.floor(VIEW_VIEWPORT.width / CELL_WIDTH),
|
||||
rows: Math.floor(VIEW_VIEWPORT.height / CELL_HEIGHT),
|
||||
};
|
||||
function viewGrid(): { cols: number; rows: number } {
|
||||
const { cellWidth, cellHeight } = getTerminalFontConfig();
|
||||
return {
|
||||
cols: Math.floor(VIEW_VIEWPORT.width / cellWidth),
|
||||
rows: Math.floor(VIEW_VIEWPORT.height / cellHeight),
|
||||
};
|
||||
}
|
||||
const DEVICE_NAME = "Faceclaw G2";
|
||||
const HUB_ROW_HEIGHT = 20;
|
||||
const RENDER_COALESCE_MS = 33;
|
||||
@@ -148,6 +154,10 @@ type HubWindow = BaseWindow & {
|
||||
|
||||
type ViewWindow = BaseWindow & {
|
||||
kind: "view";
|
||||
/** Grid font and integer cell pitch, captured at window creation. */
|
||||
font: UiFont;
|
||||
cellWidth: number;
|
||||
cellHeight: number;
|
||||
connectionId: string;
|
||||
socket: string;
|
||||
label: string;
|
||||
@@ -427,14 +437,15 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb
|
||||
renderHubWindows();
|
||||
return;
|
||||
}
|
||||
const hubCell = getTerminalFontConfig();
|
||||
windows.set(windowId, {
|
||||
kind: "hub",
|
||||
windowId,
|
||||
surfaceId,
|
||||
viewportWidth: viewport.width,
|
||||
viewportHeight: viewport.height,
|
||||
gridCols: Math.floor(viewport.width / CELL_WIDTH),
|
||||
gridRows: Math.floor(viewport.height / CELL_HEIGHT),
|
||||
gridCols: Math.floor(viewport.width / hubCell.cellWidth),
|
||||
gridRows: Math.floor(viewport.height / hubCell.cellHeight),
|
||||
foreground: false,
|
||||
focused: false,
|
||||
renderScheduled: false,
|
||||
@@ -490,8 +501,7 @@ function clientOptionsFor(connection: TerminalConnection): G2MirrorClientOptions
|
||||
return {
|
||||
...parsed,
|
||||
deviceName: DEVICE_NAME,
|
||||
cols: VIEW_GRID.cols,
|
||||
rows: VIEW_GRID.rows,
|
||||
...viewGrid(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -686,8 +696,12 @@ function createViewWindow(
|
||||
view: PendingView,
|
||||
): ViewWindow {
|
||||
const { connectionId, socket, label, glyph } = view;
|
||||
const gridCols = Math.floor(viewport.width / CELL_WIDTH);
|
||||
const gridRows = Math.floor(viewport.height / CELL_HEIGHT);
|
||||
// Capture the terminal font at open time: the grid dims go into the
|
||||
// websocket handshake and the emulator, so they must not change under a
|
||||
// live window (a font-setting change applies to the next window).
|
||||
const cell = getTerminalFontConfig();
|
||||
const gridCols = Math.floor(viewport.width / cell.cellWidth);
|
||||
const gridRows = Math.floor(viewport.height / cell.cellHeight);
|
||||
const client = new G2MirrorClient({ ...view.options, cols: gridCols, rows: gridRows });
|
||||
const window: ViewWindow = {
|
||||
kind: "view",
|
||||
@@ -697,6 +711,9 @@ function createViewWindow(
|
||||
viewportHeight: viewport.height,
|
||||
gridCols,
|
||||
gridRows,
|
||||
font: cell.font,
|
||||
cellWidth: cell.cellWidth,
|
||||
cellHeight: cell.cellHeight,
|
||||
foreground: false,
|
||||
focused: false,
|
||||
renderScheduled: false,
|
||||
@@ -1386,13 +1403,13 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
}
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
// No border box: the shell chrome (top bar + sidebar) already frames the app.
|
||||
image.drawText(terminalFont, 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
image.drawText(terminalFont, 24, 30, hubStatusLine(window), 170);
|
||||
image.drawText(chromeFont(), 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
image.drawText(chromeFont(), 24, 30, hubStatusLine(window), 170);
|
||||
|
||||
let listTop = 52;
|
||||
if (window.mode === "sessions" && controls.size === 0) {
|
||||
image.drawText(terminalFont, 24, 46, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(terminalFont, 24, 60, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
image.drawText(chromeFont(), 24, 46, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(chromeFont(), 24, 60, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
listTop += 28;
|
||||
}
|
||||
|
||||
@@ -1405,7 +1422,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
const y = listTop + (index - window.scrollRow) * HUB_ROW_HEIGHT;
|
||||
const item = items[index]!;
|
||||
if (item.heading) {
|
||||
image.drawText(terminalFont, 20, y + 2, item.label, 140);
|
||||
image.drawText(chromeFont(), 20, y + 2, item.label, 140);
|
||||
continue;
|
||||
}
|
||||
const selected = index === window.selectedIndex;
|
||||
@@ -1414,7 +1431,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
// an outline-only selection signals the sidebar owns input.
|
||||
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, HUB_ROW_HEIGHT - 1, window.focused, 8);
|
||||
}
|
||||
image.drawText(terminalFont, 32, y + 2, item.label, selected ? 255 : 200);
|
||||
image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200);
|
||||
}
|
||||
if (items.length > visibleRowCount) {
|
||||
drawListScrollbar(
|
||||
@@ -1428,21 +1445,21 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
);
|
||||
}
|
||||
|
||||
image.drawText(terminalFont, 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
function paintAddConnection(window: HubWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
image.drawText(terminalFont, 18, 10, "Add connection", 220);
|
||||
image.drawText(terminalFont, 24, 34, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(terminalFont, 24, 48, "phone app (or use voice input from the menu).", 170);
|
||||
image.drawText(chromeFont(), 18, 10, "Add connection", 220);
|
||||
image.drawText(chromeFont(), 24, 34, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(chromeFont(), 24, 48, "phone app (or use voice input from the menu).", 170);
|
||||
const draft = terminalNewConnectionSetting.get();
|
||||
image.drawText(terminalFont, 24, 76, truncateLabel(draft || "(empty)", 52), 220);
|
||||
image.drawText(chromeFont(), 24, 76, truncateLabel(draft || "(empty)", 52), 220);
|
||||
if (window.addError) {
|
||||
image.drawText(terminalFont, 24, 96, window.addError, 150);
|
||||
image.drawText(chromeFont(), 24, 96, window.addError, 150);
|
||||
}
|
||||
image.drawText(terminalFont, 24, window.viewportHeight - 24, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1467,11 +1484,37 @@ function hubStatusLine(window: HubWindow): string {
|
||||
return anyRetrying ? `${summary} Retrying...` : summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw one terminal row at a fixed integer cell pitch, so glyph columns stay
|
||||
* aligned with the emulator's grid arithmetic even when a TTF face has
|
||||
* fractional advances. Identical to drawText for the 6px bitmap default.
|
||||
*/
|
||||
function drawGridRow(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
cellWidth: number,
|
||||
rowY: number,
|
||||
text: string,
|
||||
value: number,
|
||||
): void {
|
||||
let col = 0;
|
||||
for (const char of text) {
|
||||
const codePoint = char.codePointAt(0) ?? 32;
|
||||
if (codePoint !== 32) {
|
||||
const glyph = font.getGlyph(codePoint);
|
||||
if (glyph && glyph.bbxWidth > 0) {
|
||||
image.drawGlyph(font, glyph, col * cellWidth, rowY, value);
|
||||
}
|
||||
}
|
||||
col++;
|
||||
}
|
||||
}
|
||||
|
||||
function paintView(window: ViewWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
if (!window.receivedData) {
|
||||
image.drawText(terminalFont, 24, 110, window.status, 170);
|
||||
image.drawText(terminalFont, 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(chromeFont(), 24, 110, window.status, 170);
|
||||
image.drawText(chromeFont(), 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1485,7 +1528,7 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
// Draw the cursor only if its line is within the visible window.
|
||||
const cursorScreenRow = historyNext + window.emulator.cursorRow() - top;
|
||||
if (cursorScreenRow >= 0 && cursorScreenRow < rows) {
|
||||
image.fillRect(window.emulator.cursorCol() * CELL_WIDTH, cursorScreenRow * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT, 70);
|
||||
image.fillRect(window.emulator.cursorCol() * window.cellWidth, cursorScreenRow * window.cellHeight, window.cellWidth, window.cellHeight, 70);
|
||||
}
|
||||
|
||||
// Stale content stays visible across a disconnect, so flag it: a status
|
||||
@@ -1493,12 +1536,12 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
// Text is deferred glyphs (always on top of raster), so the covered rows
|
||||
// must be suppressed rather than painted over.
|
||||
const statusBannerY = window.client.state().phase !== "attached"
|
||||
? window.viewportHeight - CELL_HEIGHT
|
||||
? window.viewportHeight - window.cellHeight
|
||||
: null;
|
||||
|
||||
for (let row = 0; row < rows; row++) {
|
||||
const rowY = row * CELL_HEIGHT;
|
||||
if (statusBannerY !== null && rowY + CELL_HEIGHT > statusBannerY) continue;
|
||||
const rowY = row * window.cellHeight;
|
||||
if (statusBannerY !== null && rowY + window.cellHeight > statusBannerY) continue;
|
||||
const absolute = top + row;
|
||||
let text = "";
|
||||
if (absolute >= historyNext) {
|
||||
@@ -1507,15 +1550,15 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
} else if (absolute >= window.archiveStart) {
|
||||
text = window.archive[absolute - window.archiveStart] ?? "";
|
||||
}
|
||||
if (text.length) image.drawText(terminalFont, 0, rowY, text, 200);
|
||||
if (text.length) drawGridRow(image, window.font, window.cellWidth, rowY, text, 200);
|
||||
}
|
||||
|
||||
if (!following) {
|
||||
drawScrollIndicator(image, top, window.archiveStart, bottomTop);
|
||||
}
|
||||
if (statusBannerY !== null) {
|
||||
image.fillRect(0, statusBannerY, window.viewportWidth, CELL_HEIGHT, 0);
|
||||
image.drawText(terminalFont, 0, statusBannerY, window.status, 170);
|
||||
image.fillRect(0, statusBannerY, window.viewportWidth, window.cellHeight, 0);
|
||||
image.drawText(chromeFont(), 0, statusBannerY, window.status, 170);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user