@amritk/nish-x86_64-linux 0.26.0 → 0.28.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.
package/std/term-io.ts CHANGED
@@ -148,6 +148,13 @@ export class TerminalOptions {
148
148
  framebufferHeight: i32
149
149
  /** The corner (`CORNER_*` from `nish/term-rate`) to draw the stats overlay in, or -1 for none (-1). */
150
150
  overlay: i32
151
+ /**
152
+ * The backend to use, as `NISH_TERM_GRAPHICS` names one ("kitty", "sixel",
153
+ * "halfblock" or "ascii"), or "" to take the best the terminal has (""). The
154
+ * variable, when it is set, wins; the probe refuses a backend the terminal
155
+ * did not answer for, as it does the variable's.
156
+ */
157
+ graphics: string
151
158
 
152
159
  constructor() {
153
160
  this.stepsPerSecond = 60
@@ -165,6 +172,7 @@ export class TerminalOptions {
165
172
  this.framebufferWidth = 0
166
173
  this.framebufferHeight = 0
167
174
  this.overlay = -1
175
+ this.graphics = ""
168
176
  }
169
177
  }
170
178
 
@@ -180,8 +188,8 @@ const termIoGetenv = (name: string): string => {
180
188
  return v === null ? "" : v
181
189
  }
182
190
 
183
- /** The variables `nish/term-probe` reads. */
184
- const termIoEnv = (): TermEnv => {
191
+ /** The variables `nish/term-probe` reads, with `graphics` standing for `NISH_TERM_GRAPHICS` when it is unset. */
192
+ const termIoEnv = (graphics: string): TermEnv => {
185
193
  const env: TermEnv = new TermEnv()
186
194
  env.term = termIoGetenv("TERM")
187
195
  env.colorterm = termIoGetenv("COLORTERM")
@@ -192,7 +200,8 @@ const termIoEnv = (): TermEnv => {
192
200
  env.sshClient = termIoGetenv("SSH_CLIENT")
193
201
  env.sshTty = termIoGetenv("SSH_TTY")
194
202
  env.noColor = termIoGetenv("NO_COLOR")
195
- env.nishTermGraphics = termIoGetenv("NISH_TERM_GRAPHICS")
203
+ const forced: string = termIoGetenv("NISH_TERM_GRAPHICS")
204
+ env.nishTermGraphics = forced === "" ? graphics : forced
196
205
  env.nishTermFps = termIoGetenv("NISH_TERM_FPS")
197
206
  return env
198
207
  }
@@ -279,10 +288,12 @@ export class Terminal {
279
288
  workNs: f64
280
289
  /** When the last frame's write began, on the monotonic clock. */
281
290
  sendStartNs: i64
282
- /** The cells `rect` was fitted to. */
291
+ /** The cells, backend and framebuffer size `rect` was fitted to. */
283
292
  rectCols: i32
284
293
  rectRows: i32
285
294
  rectBackend: i32
295
+ rectWidth: i32
296
+ rectHeight: i32
286
297
  /** The best backend the terminal has, a `GRAPHICS_*`. */
287
298
  graphics: i32
288
299
  /** The backend the last frame used. */
@@ -304,6 +315,8 @@ export class Terminal {
304
315
  focusOn: boolean
305
316
  /** Whether a kitty image may be on the screen, so closing deletes it. */
306
317
  kittyImage: boolean
318
+ /** Whether the last frame sent pixels, so a framebuffer emptied since takes them off the screen. */
319
+ pixelsShown: boolean
307
320
  /** Whether `screen` was drawn in 256 colours last frame. */
308
321
  palette256: boolean
309
322
 
@@ -350,6 +363,9 @@ export class Terminal {
350
363
  this.rectCols = -1
351
364
  this.rectRows = -1
352
365
  this.rectBackend = -1
366
+ this.rectWidth = -1
367
+ this.rectHeight = -1
368
+ this.pixelsShown = false
353
369
  this.graphics = termIoGraphics(caps.graphics)
354
370
  this.backend = this.graphics
355
371
  this.cellWidthPx = termIoCellPx(caps.cellWidthPx)
@@ -676,19 +692,23 @@ export class Terminal {
676
692
  return !ended
677
693
  }
678
694
 
679
- /** Fit the framebuffer to the screen for `backend`, unless the size and backend are those of the last fit. */
695
+ /** Fit the framebuffer to the screen for `backend`, unless the sizes and backend are those of the last fit. */
680
696
  fit(backend: i32): void {
697
+ const fb: Framebuffer = this.framebuffer
681
698
  if (
682
699
  this.rectCols === this.screen.width &&
683
700
  this.rectRows === this.screen.height &&
684
- this.rectBackend === backend
701
+ this.rectBackend === backend &&
702
+ this.rectWidth === fb.width &&
703
+ this.rectHeight === fb.height
685
704
  ) {
686
705
  return
687
706
  }
688
707
  this.rectCols = this.screen.width
689
708
  this.rectRows = this.screen.height
690
709
  this.rectBackend = backend
691
- const fb: Framebuffer = this.framebuffer
710
+ this.rectWidth = fb.width
711
+ this.rectHeight = fb.height
692
712
  this.rect = fitFramebuffer(
693
713
  fb.width,
694
714
  fb.height,
@@ -768,7 +788,14 @@ export class Terminal {
768
788
  } else {
769
789
  drawAscii(src, this.screen, this.rect, this.caps.colors)
770
790
  }
791
+ } else if (this.pixelsShown) {
792
+ // The framebuffer was emptied: take the last image off, which the screen's cells do not cover.
793
+ if (backend === GRAPHICS_KITTY && this.kittyImage) {
794
+ write(kittyDelete(TERM_IO_IMAGE_ID))
795
+ }
796
+ this.screen.invalidate()
771
797
  }
798
+ this.pixelsShown = withPixels
772
799
  if (this.options.overlay >= 0) {
773
800
  drawStatsOverlay(this.screen, this.stats(), this.options.overlay)
774
801
  }
@@ -803,7 +830,7 @@ export const openTerminal = (options: TerminalOptions): Result<Terminal, string>
803
830
  if (setRawMode(true) !== 0) {
804
831
  return Err("the terminal refused raw mode")
805
832
  }
806
- const env: TermEnv = termIoEnv()
833
+ const env: TermEnv = termIoEnv(options.graphics)
807
834
  const size: i32[] = terminalSize()
808
835
  const sized: boolean = toI32(size.length) >= 2 && size[0] > 0 && size[1] > 0
809
836
  const cols: i32 = sized ? size[0] : TERM_IO_COLS