tape

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tape reads the input commands of VHS tape files (https://github.com/charmbracelet/vhs) and plays them as keystrokes, so a block that needs a terminal can run without a person typing.

Index

Constants

View Source
const (
	DefaultTypingSpeed = 50 * time.Millisecond
	DefaultWaitTimeout = 15 * time.Second
	DefaultWaitPattern = `>$`
)

Defaults match VHS.

Variables

This section is empty.

Functions

func Play

func Play(ctx context.Context, cmds []Command, keys io.Writer, screen func() string) error

Play types cmds into keys. screen returns the terminal's text, one line per row, for Wait. It stops early when ctx ends.

Types

type Command

type Command struct {
	Line int
	// Keys are written Count times, or Text is typed a character at a
	// time, Speed apart.
	Keys  string
	Count int
	Text  string
	// Literal is set when Text was in single quotes or backticks, which
	// mdsh types as they are, without filling in placeholders.
	Literal bool
	Speed   time.Duration // 0 means the tape's typing speed
	// Sleep pauses for this long.
	Sleep time.Duration
	// Wait pauses until the screen matches Pattern (nil means the tape's
	// wait pattern), or Timeout passes (0 means the tape's wait timeout).
	Wait       bool
	Pattern    *regexp.Regexp
	WaitScreen bool // match the whole screen, not the last line
	Timeout    time.Duration
	// Set changes a setting: TypingSpeed, WaitTimeout or WaitPattern.
	Set, Value string
}

Command is one line of a tape.

func Parse

func Parse(src string) ([]Command, error)

Parse reads a tape. Comments (#), blank lines and the VHS commands that only shape VHS's own recording (Output, Hide, Set Theme and so on) are skipped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL