Partially fix search lockup for Bun
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-07-05 16:16:05 -04:00
parent 8d2ba868b0
commit 0148561240
4 changed files with 15 additions and 20 deletions

View File

@ -48,14 +48,7 @@ const BunTerminalIO: ITerminal = {
// to have consistent argument lists
argv: (Bun.argv.length > 2) ? Bun.argv.slice(2) : [],
inputLoop: async function* inputLoop() {
// for await (const chunk of Bun.stdin.stream()) {
// yield chunk;
// }
//
// return null;
for await (const chunk of process.stdin) {
yield encoder.encode(chunk);
}
yield (await BunTerminalIO.readStdinRaw()) ?? new Uint8Array(0);
return null;
},
@ -75,9 +68,12 @@ const BunTerminalIO: ITerminal = {
const raw = await BunTerminalIO.readStdinRaw();
return readKey(raw ?? new Uint8Array(0));
},
readStdinRaw: async function (): Promise<Uint8Array | null> {
const chunk = await BunTerminalIO.inputLoop().next();
return chunk.value ?? null;
readStdinRaw: function (): Promise<Uint8Array | null> {
return new Promise((resolve) => {
process.stdin.resume().once('data', (buffer: Uint8Array) => {
resolve(buffer);
});
});
},
writeStdout: async function write(s: string): Promise<void> {
const buffer = encoder.encode(s);

View File

@ -255,7 +255,7 @@ class Editor {
await this.refreshScreen();
for await (const chunk of term.inputLoop()) {
const char = readKey(chunk);
if (char.length === 0) {
if (chunk.length === 0 || char.length === 0) {
continue;
}
@ -305,7 +305,7 @@ class Editor {
const query = await this.prompt(
'Search: %s (Use ESC/Arrows/Enter)',
(query: string, key: string) => {
(q: string, key: string) => {
if (key === KeyCommand.Enter || key === KeyCommand.Escape) {
if (key === KeyCommand.Escape) {
this.#document.resetFind();
@ -313,8 +313,8 @@ class Editor {
return null;
}
if (query.length > 0) {
const pos = this.#document.find(query, key);
if (q.length > 0) {
const pos = this.#document.find(q, key);
if (pos.isSome()) {
// We have a match here
this.#cursor = pos.unwrap();

View File

@ -1,7 +1,7 @@
import Ansi from './ansi.ts';
import { SCROLL_TAB_SIZE } from './config.ts';
import { arrayInsert, isAsciiDigit, strChars } from './fns.ts';
import { arrayInsert, isAsciiDigit, strChars, strlen } from './fns.ts';
import { highlightToColor, HighlightType } from './highlight.ts';
import Option, { None, Some } from './option.ts';
@ -114,11 +114,11 @@ export class Row {
// equal the number of characters. So
// searching is fairly easy
if (thisStr.length === this.chars.length) {
return Some(byteIndex);
return Some(this.cxToRx(byteIndex));
}
// Emoji/Extended Unicode-friendly search
return Some(this.byteIndexToCharIndex(byteIndex));
return Some(this.cxToRx(this.byteIndexToCharIndex(byteIndex)));
}
/**

View File

@ -24,11 +24,10 @@ const TsxTerminalIO: ITerminal = {
},
readStdinRaw: function (): Promise<Uint8Array | null> {
return new Promise((resolve) => {
process.stdin.setRawMode(true).resume().once(
process.stdin.resume().once(
'data',
(buffer: Uint8Array) => {
resolve(buffer);
process.stdin.setRawMode(false);
},
);
});