# `Ascii.Pieces.Typewriter`
[🔗](https://github.com/houllette/ascii_art/blob/main/lib/ascii/pieces/typewriter.ex#L1)

Phrases typed and deleted in turn behind a blinking cursor.

Types each phrase a key at a time at an uneven human pace, now and then
fixing a typo, holds it under a blinking cursor, deletes it, types the
next. Give it your own: a hero line's "we make …", a list of features.

## Options

Give them to `Ascii.new/2` as `options:`, and new ones while it plays
with `Ascii.put_options/2` (or a Phoenix player's `options`): it
starts afresh with them.

  * `prefix` - the text before every phrase, which stays as the phrases
    come and go. Default `"i make "`.
  * `phrases` - typed in turn, each held finished for about two seconds,
    then deleted; after the last comes the first again. Each is cut to
    what fits after the prefix in the line's 40 characters, and the line
    is centred on its longest. A typo now and then is a key beside the
    right one on the keyboard, typed and taken back. An empty list types
    nothing. Default `["small tools.", "quiet websites.", "things that
    last.", "notes for later."]`.

The line is always 44 by 3.

## Colours

In one ink, or a gradient, with `:ink` and `:gradient` (see
`Ascii.Ink`); part by part with `:parts` (see `Ascii.Parts`),
`parts: true` taking the colours suggested here:

  * `prefix` - the prefix.
  * `phrase` - the phrase as typed so far, slips and all, blue.
  * `cursor` - the blinking cursor, yellow.

## Keys and clicks

It takes none: it types for itself, and `Ascii.handle_event/2`
ignores every event. A Phoenix player given `interactive` and `notify`
still tells your LiveView where it was clicked, and on which part
(`Ascii.part_at/4`): the phrase, say, and the text typed so far.

## Screen readers

`Ascii.describe/1` reads each phrase after the prefix, four at most,
their closing stops dropped: "typewriter: we ship on fridays; we ship
with tests". With no phrase, it gives the piece's name and note.

## Example

```elixir
line = Ascii.new!("typewriter", options: %{prefix: "we ship ", phrases: ["on fridays.", "with tests."]}, parts: true)
{frame, line} = Ascii.frame(line, 0.0)
frame.text =~ "we ship on fridays."
#=> true

Ascii.describe(line)
#=> "typewriter: we ship on fridays; we ship with tests"
```

```heex
<Ascii.Phoenix.live_player id="hero" piece="typewriter" options={%{prefix: "we make ", phrases: @things}} parts />
```

Ported from `src/pieces/typewriter.ts` in bas3line/ascii (MIT).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
