Agents
Draw for a presenter
Use this page to draw annotations on the code that a presenter has open in Tiza. The person who writes the instructions of an agent can use it too.
Tiza is a terminal tool that draws annotations on code. To install it, see Install. To connect your client, see Connect an agent. Ask the presenter to run tiza FILE in a terminal. This starts the live instance that you need.
A presenter can start with a prompt like this one:
Use Tiza to explain the code that I have open in it.Draw one step for each idea, with short labels.Then go back to step 0 and tell me how many steps there are.
Draw the annotations
- Call
status. It tells you that an instance listens, and it givescolsandrows. It also giveswarningswhen there are some. - Call
get_code. Read the line numbers, and pick exact texts for the anchors.- The code can hold characters that you cannot see, for example a zero-width space. The presenter sees
⬚for each one. After the code, a note names them, for example# line 3: U+200B zero width space, col 5. - For a text with such a character, put the real character in the
find, for example"ad\u200bmin"in JSON. To point at the character itself, uselineand thecolof the note. Afindwith only the joiner ofadU+200Dminfails, because the joiner is part of the characterd.
- The code can hold characters that you cannot see, for example a zero-width space. The presenter sees
- Add the annotations in the order of the explanation. Give each one the same
stepas the one before, or a higher one. - Call
set_stepwith0. Step 0 shows only the code, so the take can start there. - Call
check. Fix each error. The presenter decides about each warning. - Call
render_text. It gives the take as the audience sees it. - Let the presenter go through the steps with
nandp, or callnext_step.
The instance holds the document. Do not edit the .tiza file while the instance has it open. status can give these warnings:
| Warning | What to do |
|---|---|
N labels cut at C columns: IDS | Make those labels shorter, or ask the presenter for a wider terminal. |
labels go under the lines at C columns | Keep the labels short. |
code needs N columns at C columns | Ask the presenter to widen the terminal to N columns, or to open only the lines that you need. |
- When
Nis 1, the first warning sayslabel. - In
IDS,(not drawn)follows the id of a label that Tiza does not draw. The list gives at most 5 ids, then…. warningsalso has the problems of the named steps.
Give the anchors
- Give an anchor as
{"find": "exact text"}. Addlineoroccurrencewhen the text occurs more than once. See Anchor. - When a tool fails with
text_not_found, read the code again. Do not guess a column. - For a range of lines, give
find_startandfind_end, or give the lines. Use a marker that occurs only where you mean it. See Range.
Pick the tool
| To | Use |
|---|---|
| Put a border around a function or a block | add_box |
| Add a short sentence to one line | add_note |
| Explain a range of lines in two or three sentences | add_callout |
| Show where a value goes | add_arrow |
Give a span a meaning, such as move or read | add_mark |
| Color a span that has no special meaning | highlight |
| Dim the code and the annotations outside the lines that you name | add_spotlight |
| Point at a line while you talk | point_at |
list_kindsgives the kinds of a mark. For a style that many marks use, calldefine_styleonce. For one mark only, givestyle.list_kindsalso gives the personal styles of the presenter, inpersonal. Use one askind, as any other kind. The first mark that uses it copies the style into the document, soscene.getthen shows it instyles.- Do not read the config file of the presenter.
statusgives the values that apply, for examplenumbersandautosave. - Give each variable its own
color. Use the same color for every annotation about that variable. - For arrows, use
solidfor a move of ownership,dashedfor a shared borrow andthickfor a mutable borrow. - Use the
underlineemphasis to show a span and keep its syntax colors. Usestrikefor a line that goes away. - When the margin has no room, Tiza draws a callout with
placementmarginorautobelow its last line.
Example
This example is for examples/ownership.rs, with no annotations. The tools give the ids a1 to a6 in order. The last call changes the arrow a2. On line 3, the first s is the last letter of takes. Thus the anchor of the mark has "occurrence": 2.
{"name":"add_mark","arguments":{"kind":"move","at":{"line":3,"find":"s","occurrence":2},"label":"s moves into takes","step":1}}
{"name":"add_arrow","arguments":{"from":{"line":2,"find":"s"},"to":{"line":15,"find":"s: String"},"label":"move","step":1,"color":"orange"}}
{"name":"add_note","arguments":{"line":4,"text":"s no longer owns it: using it here does not compile","step":2}}
{"name":"add_box","arguments":{"from_line":15,"to_line":17,"label":"takes owns s and frees it at the end","step":2}}
{"name":"add_arrow","arguments":{"from":{"line":7,"find":"&t"},"to":{"line":19,"find":"s: &String"},"label":"shared borrow","stroke":"dashed","step":3}}
{"name":"add_callout","arguments":{"from_line":15,"to_line":25,"title":"three ways to pass a value","text":"takes(s) moves the String. len(&s) borrows it read-only. push(&mut s) borrows it mutably.","placement":"auto","step":3,"color":"cyan"}}
{"name":"update_annotation","arguments":{"id":"a2","stroke":"thick","head_end":"bar"}}Check that the annotation shows
Each add tool and update_annotation reply with the place of the annotation on the screen of the presenter. The fields and the messages are in Reply of an annotation tool.
- When
visibleisfalse,hiddentells why. The annotation is in the document. Do not add it again. - The status bar tells the presenter that the annotation is hidden. Do not repeat this in the chat, unless the presenter asks. See Changes that you cannot see.
- Do not change the step on screen to show it, unless the presenter asks.
- For a label that Tiza cuts, and for the width of the reply, see Reply of an annotation tool.
Check the document
check gives the report of tiza check --json for the live document. See Check a live instance.
min_clean_widthis the narrowest width with no cut label. It does not look at the code lines. Aclipped_codewarning gives the code lines that are cut at the width of the check, and the width from which every code line fits. Before you export at another width, callcheckwith thatwidth. Or make the labels that the report names shorter.checkonly reads.- The report is about the
revisionin its reply. When a later change returns a newerrevision, callcheckagain. - At most one
checkruns and one waits. Afterbusy, callcheckagain. See Error codes.
Fix or clear annotations
To change an annotation and keep its id, call update_annotation. See update_annotation.
- For a callout,
labelchanges the title. No tool changes the text of a callout. clear_annotationsdeletes all the annotations, or the annotations of onestep.
Point while you talk
point_at puts the live pointer on a line or on a range of lines. The other code dims. The view scrolls to the line, and the cursor of the presenter goes there too. clear_pointer or the f key of the presenter turns it off.
- The presenter and you share one pointer. The rules are in The live pointer and in Fields of
status. - Use
point_atto show a line for a short time. Useadd_spotlightwhen the line belongs to a step of the take.
When the presenter edits the file
set_followwith"enabled": truereloads the code each time that the presenter saves the file. The presenter can also type:follow on.- When a
code.patchis applied at the step on the screen, follow mode is paused and a save waits. Thefollowfield ofstatusgivespaused,pendingandresume_step. The reply ofset_followalso gives thereason. Tiza follows only the main file, not a file that acode.linkshows. - When you save the file yourself, compare
hashin thefollowfield ofstatuswith the sha256 of the file. When they are the same, Tiza read your save. See Agents and follow mode. - Tiza keeps each annotation on its text, and drops it when its text is gone. See What happens to annotations.
- After a reload, call
list_annotations, and add the annotations that you need again. - A move can become stale after a reload. See When the presenter edits the file.
- The rules are in Agents and follow mode. The messages are in Messages.
The screen and the exports
- To change the theme, see Agents and themes.
status.marginis the limit of the right margin, when the document sets one. A long note wraps at it, and takes the rows of the lines under it.status.numberstells you whether the line numbers show. Give the real line numbers in your anchors, even when the numbers do not show.render_textandexport_imageuse one layout for all the steps. See One layout for the take.- During a typing animation,
render_textgives the step as it is after the typing. - The extension of the
pathofexport_imageselects the format. See Where each format works. - No tool writes an MP4. Tell the presenter to run
tiza render --out demo.mp4, which needsffmpeg. - When an export takes too long, export fewer steps, a smaller image or one step. See Errors of
export_image.
Secrets and saving
Warning: The audience sees the same code as
get_codegives, in every export. Only control and invisible characters look different. When the code holds a real secret, tell the presenter before the recording starts. Do not put the secret in a label. See Checklist.
- An error does not repeat a wrong value of
color,borderor another field with a fixed set of values. An error repeats a value of the wrong type, cut at 40 characters. See Errors. - No tool publishes or uploads a file. See Agents.
- Tiza saves each change to the
.tizafile at once. In no-save mode, with autosave off or with a read-only document, the changes stay in memory. See When changes are not saved. status.autosaveisfalsein no-save mode and with autosave off. With a read-only document, it staystruewhile the saves fail.- A
scene.putof another document, or of changed code of the open document, stops autosave. See Agents and saving.
Retries and errors
- Give your own
id, for example"id": "move-s". Then a second try of the same call fails withduplicate_id, and adds no copy. See Arguments of all the add tools. - After
internal, tell the presenter. Do not try again in a loop. Tiza undid all of the request. - After
rejected, see For the agent. The other codes are in Error codes. - When a tool is not in your list, search for what you want to draw. See Find the tools.
- When
statusgivesbinary_rebuilt, see After you rebuild Tiza.