Compare commits
No commits in common. "4eea9bce6fe8ee57d3bf6573fb504470c122b37f" and "b2d1a6e9586cddaeeddcf211d8b54d465bfd3c2d" have entirely different histories.
4eea9bce6f
...
b2d1a6e958
@ -6,13 +6,8 @@ import {
|
||||
type PainterTask,
|
||||
task as TASK,
|
||||
} from '../painter/lifecycle'
|
||||
import {
|
||||
type AnsiBufferKey,
|
||||
ansiText,
|
||||
emptyBytes,
|
||||
writeAnsiU,
|
||||
} from '../util/ansi'
|
||||
import { DoEither, type Either, left, right } from '../util/basic/either'
|
||||
import { type AnsiBufferKey } from '../util/ansi'
|
||||
import { DoEither, type Either, right } from '../util/basic/either'
|
||||
import { some } from '../util/basic/option'
|
||||
import type { Tag } from '../util/basic/utility'
|
||||
|
||||
@ -21,10 +16,9 @@ interface SelectOptions {
|
||||
keydown: Array<Key>
|
||||
exit: Array<Key>
|
||||
accept: Array<Key>
|
||||
selector: {selected: string, default: string}
|
||||
selected: number
|
||||
selector: string
|
||||
options: Array<string>
|
||||
header?: {text: string, format: Array<AnsiBufferKey | Uint8Array>}
|
||||
header: {text: string, format: Array<AnsiBufferKey | Uint8Array>}
|
||||
format: {
|
||||
text: {
|
||||
default: Array<AnsiBufferKey | Uint8Array>,
|
||||
@ -49,36 +43,22 @@ const EVENT: Record<string, Event | ((...args: any[]) => Event)> = {
|
||||
|
||||
type RenderText =
|
||||
(x: SelectOptions & Tag<'PainterState'>) => Promise<Either<number, Error>>
|
||||
const renderText: RenderText = async (x) => {
|
||||
try {
|
||||
return right(
|
||||
await writeAnsiU([
|
||||
...(!x.header ? [emptyBytes]
|
||||
: [...x.header.format, ansiText(x.header.text)]),
|
||||
...x.options.flatMap(i =>
|
||||
(x.options[x.selected] === i)
|
||||
? [
|
||||
...x.format.selector.defaultSelected,
|
||||
ansiText(x.selector.selected),
|
||||
'RESET' as AnsiBufferKey,
|
||||
...x.format.text.defaultSelected,
|
||||
ansiText(i),
|
||||
'RESET' as AnsiBufferKey,
|
||||
] : [
|
||||
...x.format.selector.default,
|
||||
ansiText(x.selector.default),
|
||||
'RESET' as AnsiBufferKey,
|
||||
...x.format.text.default,
|
||||
ansiText(i),
|
||||
'RESET' as AnsiBufferKey,
|
||||
]
|
||||
),
|
||||
]),
|
||||
)
|
||||
} catch (e) {
|
||||
return left(e as Error)
|
||||
}
|
||||
// const renderText: RenderText = x =>
|
||||
//
|
||||
// const selectOptions: PainterEffect<SelectOptions> = x =>
|
||||
// DoEither(right(x)).start()
|
||||
// .bind('')
|
||||
|
||||
const test = async () => {
|
||||
const myPromise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('First')
|
||||
}, 300)
|
||||
})
|
||||
|
||||
console.log('Second')
|
||||
console.log(await myPromise)
|
||||
return some(await myPromise + 'Third')
|
||||
}
|
||||
|
||||
const selectOptions: PainterEffect<SelectOptions> = x => {
|
||||
}
|
||||
console.log(await test())
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { nanoseconds } from 'bun'
|
||||
|
||||
const encoder = new TextEncoder()
|
||||
const emptyBytes = encoder.encode('')
|
||||
type Writer = (x: Uint8Array | Array<Uint8Array>) => Promise<number>
|
||||
@ -140,8 +142,6 @@ export {
|
||||
ANSI_DYNAMIC,
|
||||
type AnsiBufferKey,
|
||||
ansiText,
|
||||
emptyBytes,
|
||||
writeAnsi,
|
||||
writeAnsiU,
|
||||
writer,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user