@gjermundgaraba/clankermux 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
+ // Generated from the catalog by `cargo xtask protocol`; do not edit.
1
2
  export const VERSION = 1;
@@ -1,4 +1,5 @@
1
- import { type Frame } from "../engine/index.ts";
1
+ import { type Cell, type Frame, type PackedCells } from "../engine/render.ts";
2
+ type Cells = Cell[] | PackedCells;
2
3
  /** The cell grid in CSS pixels and the fonts to draw with. */
3
4
  export interface Metrics {
4
5
  cellWidth: number;
@@ -40,7 +41,7 @@ export declare class CanvasRenderer {
40
41
  private background;
41
42
  private foreground;
42
43
  constructor(ctx: Context2D, metrics: Metrics, palette: Palette);
43
- draw(frame: Frame): void;
44
+ draw(frame: Frame<Cells>): void;
44
45
  /** The scrollback mark for `frame`: the viewport's share of the history
45
46
  * at the right edge, while the view is scrolled back. */
46
47
  private markOf;
@@ -48,3 +49,4 @@ export declare class CanvasRenderer {
48
49
  private font;
49
50
  private drawCursor;
50
51
  }
52
+ export {};
@@ -1,4 +1,4 @@
1
- import { FLAG, NO_COLOR } from "../engine/index.js";
1
+ import { FLAG, NO_COLOR, PACKED_STRIDE, packedText } from "../engine/render.js";
2
2
  const hex = (color) => `#${color.toString(16).padStart(6, "0")}`;
3
3
  /** A cell or cursor colour, or `fallback` when it has none. */
4
4
  const css = (color, fallback) => (color === NO_COLOR ? fallback : hex(color));
@@ -101,33 +101,46 @@ export class CanvasRenderer {
101
101
  this.ctx.globalAlpha = 1;
102
102
  this.ctx.fillStyle = this.background;
103
103
  this.ctx.fillRect(0, y, this.cols * cellWidth, cellHeight);
104
- for (let x = 0; x < row.cells.length; x++) {
105
- const cell = row.cells[x];
106
- if (cell.flags & FLAG.SPACER)
104
+ const cells = row.cells;
105
+ const count = Array.isArray(cells) ? cells.length : cells.data.length / PACKED_STRIDE;
106
+ for (let x = 0; x < count; x++) {
107
+ let text, foreground, background, flags, underline;
108
+ if (Array.isArray(cells)) {
109
+ ({ text, fg: foreground, bg: background, flags, underline } = cells[x]);
110
+ }
111
+ else {
112
+ const at = x * PACKED_STRIDE;
113
+ text = packedText(cells, x);
114
+ foreground = cells.data[at + 1];
115
+ background = cells.data[at + 2];
116
+ flags = cells.data[at + 3] & 0xffff;
117
+ underline = cells.data[at + 3] >>> 16;
118
+ }
119
+ if (flags & FLAG.SPACER)
107
120
  continue;
108
- const width = cell.flags & FLAG.WIDE ? 2 : 1;
109
- let fg = css(cell.fg, this.foreground);
110
- let bg = css(cell.bg, this.background);
121
+ const width = flags & FLAG.WIDE ? 2 : 1;
122
+ let fg = css(foreground, this.foreground);
123
+ let bg = css(background, this.background);
111
124
  // A selected cell is drawn inverted, an inverse one the other way.
112
125
  const selected = row.selection !== undefined && x >= row.selection[0] && x <= row.selection[1];
113
- if (((cell.flags & FLAG.INVERSE) !== 0) !== selected)
126
+ if (((flags & FLAG.INVERSE) !== 0) !== selected)
114
127
  [fg, bg] = [bg, fg];
115
128
  if (bg !== this.background) {
116
129
  this.ctx.fillStyle = bg;
117
130
  this.ctx.fillRect(x * cellWidth, y, width * cellWidth, cellHeight);
118
131
  }
119
- if (cell.flags & FLAG.INVISIBLE)
132
+ if (flags & FLAG.INVISIBLE)
120
133
  continue;
121
- this.ctx.globalAlpha = cell.flags & FLAG.FAINT ? 0.6 : 1;
134
+ this.ctx.globalAlpha = flags & FLAG.FAINT ? 0.6 : 1;
122
135
  this.ctx.fillStyle = fg;
123
- if (cell.text !== "" && cell.text !== " ") {
124
- this.ctx.font = this.font(cell.flags);
125
- this.ctx.fillText(cell.text, x * cellWidth, y + baseline);
136
+ if (text !== "" && text !== " ") {
137
+ this.ctx.font = this.font(flags);
138
+ this.ctx.fillText(text, x * cellWidth, y + baseline);
126
139
  }
127
- if (cell.underline !== 0) {
140
+ if (underline !== 0) {
128
141
  this.ctx.fillRect(x * cellWidth, y + cellHeight - 2, width * cellWidth, 1);
129
142
  }
130
- if (cell.flags & FLAG.STRIKETHROUGH) {
143
+ if (flags & FLAG.STRIKETHROUGH) {
131
144
  this.ctx.fillRect(x * cellWidth, y + Math.floor(cellHeight / 2), width * cellWidth, 1);
132
145
  }
133
146
  }
@@ -167,11 +180,21 @@ export class CanvasRenderer {
167
180
  default: {
168
181
  this.ctx.fillRect(x, y, cellWidth, cellHeight);
169
182
  // The cell's text in the background colour, over the block.
170
- const cell = this.rows.get(cursor.y)?.cells[cursor.x];
171
- if (cell && cell.text !== "" && cell.text !== " ") {
183
+ const cells = this.rows.get(cursor.y)?.cells;
184
+ let text = "", flags = 0;
185
+ if (Array.isArray(cells)) {
186
+ const cell = cells[cursor.x];
187
+ if (cell)
188
+ ({ text, flags } = cell);
189
+ }
190
+ else if (cells && cursor.x < cells.data.length / PACKED_STRIDE) {
191
+ text = packedText(cells, cursor.x);
192
+ flags = cells.data[cursor.x * PACKED_STRIDE + 3] & 0xffff;
193
+ }
194
+ if (text !== "" && text !== " ") {
172
195
  this.ctx.fillStyle = this.background;
173
- this.ctx.font = this.font(cell.flags);
174
- this.ctx.fillText(cell.text, x, y + baseline);
196
+ this.ctx.font = this.font(flags);
197
+ this.ctx.fillText(text, x, y + baseline);
175
198
  }
176
199
  }
177
200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjermundgaraba/clankermux",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",