Add dynamic ANSI buffer codes
This commit is contained in:
parent
2eb65f7c55
commit
9ea2787ba2
@ -88,6 +88,8 @@ export const ANSI_BUFFERS = {
|
|||||||
GET_CURSOR_POSITION: encoder.encode(ANSI.GET_CURSOR_POSITION),
|
GET_CURSOR_POSITION: encoder.encode(ANSI.GET_CURSOR_POSITION),
|
||||||
SAVE_CURSOR: encoder.encode(ANSI.SAVE_CURSOR),
|
SAVE_CURSOR: encoder.encode(ANSI.SAVE_CURSOR),
|
||||||
RESTORE_CURSOR: encoder.encode(ANSI.RESTORE_CURSOR),
|
RESTORE_CURSOR: encoder.encode(ANSI.RESTORE_CURSOR),
|
||||||
|
|
||||||
|
// Screen Control
|
||||||
CLEAR_SCREEN: encoder.encode(ANSI.CLEAR_SCREEN),
|
CLEAR_SCREEN: encoder.encode(ANSI.CLEAR_SCREEN),
|
||||||
CLEAR_LINE: encoder.encode(ANSI.CLEAR_LINE),
|
CLEAR_LINE: encoder.encode(ANSI.CLEAR_LINE),
|
||||||
CLEAR_TO_END: encoder.encode(ANSI.CLEAR_TO_END),
|
CLEAR_TO_END: encoder.encode(ANSI.CLEAR_TO_END),
|
||||||
@ -95,10 +97,19 @@ export const ANSI_BUFFERS = {
|
|||||||
CLEAR_BELOW: encoder.encode(ANSI.CLEAR_BELOW),
|
CLEAR_BELOW: encoder.encode(ANSI.CLEAR_BELOW),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ANSI_DYNAMIC = {
|
||||||
|
// Cursor Control
|
||||||
|
CURSOR_TO: (x: number, y: number) => encoder.encode(ANSI.CURSOR_TO(x, y)),
|
||||||
|
CURSOR_UP: (x = 1) => encoder.encode(ANSI.CURSOR_UP(x)),
|
||||||
|
CURSOR_DOWN: (x = 1) => encoder.encode(ANSI.CURSOR_DOWN(x)),
|
||||||
|
CURSOR_FORWARD: (x = 1) => encoder.encode(ANSI.CURSOR_FORWARD(x)),
|
||||||
|
CURSOR_BACK: (x = 1) => encoder.encode(ANSI.CURSOR_BACK(x)),
|
||||||
|
};
|
||||||
|
|
||||||
type AnsiBufferKey = keyof typeof ANSI_BUFFERS;
|
type AnsiBufferKey = keyof typeof ANSI_BUFFERS;
|
||||||
|
|
||||||
export async function writeAnsi(
|
export async function writeAnsi(
|
||||||
codes: AnsiBufferKey[],
|
codes: (AnsiBufferKey | Uint8Array)[],
|
||||||
text?: string,
|
text?: string,
|
||||||
autoReset: boolean = true
|
autoReset: boolean = true
|
||||||
): Promise<Result<number, Error>> {
|
): Promise<Result<number, Error>> {
|
||||||
@ -106,8 +117,12 @@ export async function writeAnsi(
|
|||||||
|
|
||||||
// Add requested ANSI codes
|
// Add requested ANSI codes
|
||||||
for (const code of codes) {
|
for (const code of codes) {
|
||||||
|
if (code instanceof Uint8Array) {
|
||||||
|
buffers.push(code);
|
||||||
|
} else {
|
||||||
buffers.push(ANSI_BUFFERS[code]);
|
buffers.push(ANSI_BUFFERS[code]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add optional text
|
// Add optional text
|
||||||
if (text) {
|
if (text) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user