Progress on canvasses
This commit is contained in:
parent
987e79c592
commit
a8f8bdda99
@ -1,6 +1,47 @@
|
|||||||
|
import { tryCatch } from '@maxmorozoff/try-catch-tuple';
|
||||||
|
import type { CursorPosition } from '../util/terminal';
|
||||||
|
|
||||||
|
const setInitialEnd = (pos: {
|
||||||
|
origin: CursorPosition;
|
||||||
|
end?: CursorPosition;
|
||||||
|
lines?: number;
|
||||||
|
}) => {
|
||||||
|
if (!pos.end || !pos.lines)
|
||||||
|
throw TypeError("One of 'end' or 'lines' must be set");
|
||||||
|
if (Object.keys(pos).includes('end') || Object.keys(pos).includes('end'))
|
||||||
|
throw TypeError("Cannot set both 'end' and 'lines'");
|
||||||
|
if (pos.end) return pos.end;
|
||||||
|
return {
|
||||||
|
row: pos.origin.row + pos.lines,
|
||||||
|
col: pos.origin.col,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const createCanvas = (
|
export const createCanvas = (
|
||||||
paint: () => Promise<number, Error>,
|
pos: { origin: CursorPosition; end?: CursorPosition; lines?: number },
|
||||||
cleanup?: () => Promise<number, Error>
|
paint: () => Promise<number>,
|
||||||
|
cleanup?: () => Promise<number>
|
||||||
) => {
|
) => {
|
||||||
|
let currentOrigin = pos.origin;
|
||||||
|
|
||||||
|
let currentEnd;
|
||||||
|
const [endVal, endError] = tryCatch(() => setInitialEnd(pos));
|
||||||
|
if (endError) throw endError;
|
||||||
|
currentEnd = endVal;
|
||||||
|
|
||||||
|
paint();
|
||||||
|
//
|
||||||
|
// Paint function
|
||||||
|
//
|
||||||
|
// Restore origin position
|
||||||
|
// Clear to cursor end position
|
||||||
|
//
|
||||||
|
// API
|
||||||
|
// ---
|
||||||
|
// get origin
|
||||||
|
// get end
|
||||||
|
// move end
|
||||||
|
// get line count
|
||||||
|
// clear canvas
|
||||||
return [1];
|
return [1];
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user