Partially fix search lockup for Bun
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
8d2ba868b0
commit
0148561240
@ -48,14 +48,7 @@ const BunTerminalIO: ITerminal = {
|
|||||||
// to have consistent argument lists
|
// to have consistent argument lists
|
||||||
argv: (Bun.argv.length > 2) ? Bun.argv.slice(2) : [],
|
argv: (Bun.argv.length > 2) ? Bun.argv.slice(2) : [],
|
||||||
inputLoop: async function* inputLoop() {
|
inputLoop: async function* inputLoop() {
|
||||||
// for await (const chunk of Bun.stdin.stream()) {
|
yield (await BunTerminalIO.readStdinRaw()) ?? new Uint8Array(0);
|
||||||
// yield chunk;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return null;
|
|
||||||
for await (const chunk of process.stdin) {
|
|
||||||
yield encoder.encode(chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
@ -75,9 +68,12 @@ const BunTerminalIO: ITerminal = {
|
|||||||
const raw = await BunTerminalIO.readStdinRaw();
|
const raw = await BunTerminalIO.readStdinRaw();
|
||||||
return readKey(raw ?? new Uint8Array(0));
|
return readKey(raw ?? new Uint8Array(0));
|
||||||
},
|
},
|
||||||
readStdinRaw: async function (): Promise<Uint8Array | null> {
|
readStdinRaw: function (): Promise<Uint8Array | null> {
|
||||||
const chunk = await BunTerminalIO.inputLoop().next();
|
return new Promise((resolve) => {
|
||||||
return chunk.value ?? null;
|
process.stdin.resume().once('data', (buffer: Uint8Array) => {
|
||||||
|
resolve(buffer);
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
writeStdout: async function write(s: string): Promise<void> {
|
writeStdout: async function write(s: string): Promise<void> {
|
||||||
const buffer = encoder.encode(s);
|
const buffer = encoder.encode(s);
|
||||||
|
@ -255,7 +255,7 @@ class Editor {
|
|||||||
await this.refreshScreen();
|
await this.refreshScreen();
|
||||||
for await (const chunk of term.inputLoop()) {
|
for await (const chunk of term.inputLoop()) {
|
||||||
const char = readKey(chunk);
|
const char = readKey(chunk);
|
||||||
if (char.length === 0) {
|
if (chunk.length === 0 || char.length === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ class Editor {
|
|||||||
|
|
||||||
const query = await this.prompt(
|
const query = await this.prompt(
|
||||||
'Search: %s (Use ESC/Arrows/Enter)',
|
'Search: %s (Use ESC/Arrows/Enter)',
|
||||||
(query: string, key: string) => {
|
(q: string, key: string) => {
|
||||||
if (key === KeyCommand.Enter || key === KeyCommand.Escape) {
|
if (key === KeyCommand.Enter || key === KeyCommand.Escape) {
|
||||||
if (key === KeyCommand.Escape) {
|
if (key === KeyCommand.Escape) {
|
||||||
this.#document.resetFind();
|
this.#document.resetFind();
|
||||||
@ -313,8 +313,8 @@ class Editor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.length > 0) {
|
if (q.length > 0) {
|
||||||
const pos = this.#document.find(query, key);
|
const pos = this.#document.find(q, key);
|
||||||
if (pos.isSome()) {
|
if (pos.isSome()) {
|
||||||
// We have a match here
|
// We have a match here
|
||||||
this.#cursor = pos.unwrap();
|
this.#cursor = pos.unwrap();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Ansi from './ansi.ts';
|
import Ansi from './ansi.ts';
|
||||||
|
|
||||||
import { SCROLL_TAB_SIZE } from './config.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 { highlightToColor, HighlightType } from './highlight.ts';
|
||||||
import Option, { None, Some } from './option.ts';
|
import Option, { None, Some } from './option.ts';
|
||||||
|
|
||||||
@ -114,11 +114,11 @@ export class Row {
|
|||||||
// equal the number of characters. So
|
// equal the number of characters. So
|
||||||
// searching is fairly easy
|
// searching is fairly easy
|
||||||
if (thisStr.length === this.chars.length) {
|
if (thisStr.length === this.chars.length) {
|
||||||
return Some(byteIndex);
|
return Some(this.cxToRx(byteIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emoji/Extended Unicode-friendly search
|
// Emoji/Extended Unicode-friendly search
|
||||||
return Some(this.byteIndexToCharIndex(byteIndex));
|
return Some(this.cxToRx(this.byteIndexToCharIndex(byteIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,11 +24,10 @@ const TsxTerminalIO: ITerminal = {
|
|||||||
},
|
},
|
||||||
readStdinRaw: function (): Promise<Uint8Array | null> {
|
readStdinRaw: function (): Promise<Uint8Array | null> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.stdin.setRawMode(true).resume().once(
|
process.stdin.resume().once(
|
||||||
'data',
|
'data',
|
||||||
(buffer: Uint8Array) => {
|
(buffer: Uint8Array) => {
|
||||||
resolve(buffer);
|
resolve(buffer);
|
||||||
process.stdin.setRawMode(false);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user