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