# caique/raw

> Every export of caique/raw, with its signature and doc comment: keyOf, canRender, renderList, askList, plus 3 types.

Source: https://caique.interlace.tools/docs/api/raw

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

```ts
import { keyOf, canRender, renderList, … } from 'caique/raw';
```

## Functions

### askList

Drive a list prompt with the arrow keys, repainting in place.

Returns the same `Asked` shape `ask()` does, so a caller can swap the two without
knowing which ran — and cancels the same way, because `Ctrl-C` in raw mode is a byte and
not a signal, and a person who presses it means to leave.

The cursor is hidden through `closeout`: the byte path resolves and `restore()` runs in
the `finally`; every path that never reaches the `finally` is the exit hook's.

```ts
function askList(spec: PromptSpec, io: RawIo, multi?: boolean): Promise<Asked>;
```

| Parameter | Type |
| :-- | :-- |
| `spec` | `PromptSpec` |
| `io` | `RawIo` |
| `multi` (optional) | `boolean` |

**Returns** `Promise<Asked>`

### canRender

Whether this runtime can drive the raw renderer at all.

```ts
function canRender(keys: KeyStream): boolean;
```

| Parameter | Type |
| :-- | :-- |
| `keys` | `KeyStream` |

**Returns** `boolean`

### keyOf

What a keypress means. Only the six that drive a list — everything else is `other`, and
a widget that does not know what to do with a key does nothing, which is what a person
expects from a key they pressed by accident.

```ts
function keyOf(data: string): Key;
```

| Parameter | Type |
| :-- | :-- |
| `data` | `string` |

**Returns** `Key`

### renderList

One frame of the list. Exported so a test asserts the drawing rather than a screenshot.

```ts
function renderList(spec: PromptSpec, choices: Choice[], state: ListState, multi: boolean): string;
```

| Parameter | Type |
| :-- | :-- |
| `spec` | `PromptSpec` |
| `choices` | `Choice[]` |
| `state` | `ListState` |
| `multi` | `boolean` |

**Returns** `string`

## Interfaces

### KeyStream

A stream that can be put into raw mode and read a key at a time.

```ts
interface KeyStream {
    isTTY?: boolean;
    /**
     * Node's record of the mode. Read so that a stream somebody else already put into raw
     * mode — a prompt library, the program itself — is left raw when this prompt ends.
     */
    isRaw?: boolean;
    setRawMode?(raw: boolean): unknown;
    on(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
    off(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
    resume?(): unknown;
    pause?(): unknown;
}
```

### RawIo

```ts
interface RawIo extends Io {
    keys: KeyStream;
}
```

## Types

### Key

```ts
type Key = 'up' | 'down' | 'space' | 'enter' | 'cancel' | 'other';
```
