Dagger
Search

termcast

The termcast module provides a complete API for simulating interactive terminal sessions,
and sharing them as GIFs.
It can also replay recordings live in the caller's terminal.

Termcast can simulate human keystrokes; execute commands in containers;
ask an AI to imagine a scenario; and more.

Installation

dagger install github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f

Entrypoint

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
widthInteger -Terminal width
heightInteger -Terminal height
keySecret -OpenAI auth key, for AI features
containerContainer -Containerized environment for executing commands
shell[String ! ] -Shell to use when executing commands
promptString -The prompt shown by the interactive shell
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
func (m *myModule) example() *Termcast  {
	return dag.
			Termcast()
}
@function
def example() -> dag.Termcast:
	return (
		dag.termcast()
	)
@func()
example(): Termcast {
	return dag
		.termcast()
}

Types

Termcast 🔗

height() 🔗

The height of the terminal

Return Type
Integer !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 height
func (m *myModule) example(ctx context.Context) int  {
	return dag.
			Termcast().
			Height(ctx)
}
@function
async def example() -> int:
	return await (
		dag.termcast()
		.height()
	)
@func()
async example(): Promise<number> {
	return dag
		.termcast()
		.height()
}

width() 🔗

The width of the terminal

Return Type
Integer !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 width
func (m *myModule) example(ctx context.Context) int  {
	return dag.
			Termcast().
			Width(ctx)
}
@function
async def example() -> int:
	return await (
		dag.termcast()
		.width()
	)
@func()
async example(): Promise<number> {
	return dag
		.termcast()
		.width()
}

clock() 🔗

Time elapsed since beginning of the session, in milliseconds

Return Type
Integer !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 clock
func (m *myModule) example(ctx context.Context) int  {
	return dag.
			Termcast().
			Clock(ctx)
}
@function
async def example() -> int:
	return await (
		dag.termcast()
		.clock()
	)
@func()
async example(): Promise<number> {
	return dag
		.termcast()
		.clock()
}

container() 🔗

The containerized environment where commands are executed See Exec()

Return Type
Container !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 container
func (m *myModule) example() *Container  {
	return dag.
			Termcast().
			Container()
}
@function
def example() -> dagger.Container:
	return (
		dag.termcast()
		.container()
	)
@func()
example(): Container {
	return dag
		.termcast()
		.container()
}

withContainer() 🔗

Customize the container used by ‘exec’

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
ctrContainer !-No description provided
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 with-container --ctr IMAGE:TAG
func (m *myModule) example(ctr *Container) *Termcast  {
	return dag.
			Termcast().
			WithContainer(ctr)
}
@function
def example(ctr: dagger.Container) -> dag.Termcast:
	return (
		dag.termcast()
		.with_container(ctr)
	)
@func()
example(ctr: Container): Termcast {
	return dag
		.termcast()
		.withContainer(ctr)
}

print() 🔗

Simulate data being printed to the terminal, all at once

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
dataString !-No description provided
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 print --data string
func (m *myModule) example(data string) *Termcast  {
	return dag.
			Termcast().
			Print(data)
}
@function
def example(data: str) -> dag.Termcast:
	return (
		dag.termcast()
		.print(data)
	)
@func()
example(data: string): Termcast {
	return dag
		.termcast()
		.print(data)
}

append() 🔗

Append a recording to the end of this recording

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
otherTermcast !-No description provided
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(other *Termcast) *Termcast  {
	return dag.
			Termcast().
			Append(other)
}
@function
def example(other: dag.Termcast) -> dag.Termcast:
	return (
		dag.termcast()
		.append(other)
	)
@func()
example(other: Termcast): Termcast {
	return dag
		.termcast()
		.append(other)
}

waitRandom() 🔗

Simulate the user waiting for a random amount of time, with no input or output

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
minInteger !-The minimum wait time, in milliseconds
maxInteger !-The maximum wait time, in milliseconds
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 wait-random --min integer --max integer
func (m *myModule) example(min int, max int) *Termcast  {
	return dag.
			Termcast().
			WaitRandom(min, max)
}
@function
def example(min: int, max: int) -> dag.Termcast:
	return (
		dag.termcast()
		.wait_random(min, max)
	)
@func()
example(min: number, max: number): Termcast {
	return dag
		.termcast()
		.waitRandom(min, max)
}

wait() 🔗

Simulate waiting for a certain amount of time, with no input or output on the temrinal

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
msInteger !-wait time, in milliseconds
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 wait --ms integer
func (m *myModule) example(ms int) *Termcast  {
	return dag.
			Termcast().
			Wait(ms)
}
@function
def example(ms: int) -> dag.Termcast:
	return (
		dag.termcast()
		.wait(ms)
	)
@func()
example(ms: number): Termcast {
	return dag
		.termcast()
		.wait(ms)
}

exec() 🔗

Simulate a human running an interactive command in a container

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
cmdString !-The command to execute
simpleBoolean falseToggle simple mode. Enabling simple mode is faster and more reliable, but also less realistic: the recording will print the final output all at once, without preserving timing information. Disabling mode is more realistic: the timing of each byte is preserved in the recording; this requires building a binary (which is slow) and injecting it into the target container (which could break).
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 exec --cmd string
func (m *myModule) example(cmd string) *Termcast  {
	return dag.
			Termcast().
			Exec(cmd)
}
@function
def example(cmd: str) -> dag.Termcast:
	return (
		dag.termcast()
		.exec(cmd)
	)
@func()
example(cmd: string): Termcast {
	return dag
		.termcast()
		.exec(cmd)
}

execEnv() 🔗

Build the execution environment for debugging purposes

Return Type
Container !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 exec-env
func (m *myModule) example() *Container  {
	return dag.
			Termcast().
			ExecEnv()
}
@function
def example() -> dagger.Container:
	return (
		dag.termcast()
		.exec_env()
	)
@func()
example(): Container {
	return dag
		.termcast()
		.execEnv()
}

keystrokes() 🔗

Simulate a human typing text

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
dataString !-Data to input as keystrokes
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 keystrokes --data string
func (m *myModule) example(data string) *Termcast  {
	return dag.
			Termcast().
			Keystrokes(data)
}
@function
def example(data: str) -> dag.Termcast:
	return (
		dag.termcast()
		.keystrokes(data)
	)
@func()
example(data: string): Termcast {
	return dag
		.termcast()
		.keystrokes(data)
}

enter() 🔗

Simulate pressing the enter key

Return Type
Termcast !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 enter
func (m *myModule) example() *Termcast  {
	return dag.
			Termcast().
			Enter()
}
@function
def example() -> dag.Termcast:
	return (
		dag.termcast()
		.enter()
	)
@func()
example(): Termcast {
	return dag
		.termcast()
		.enter()
}

backspace() 🔗

Simulate pressing the backspace key

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
repeatInteger !1Number of backspaces
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 backspace --repeat integer
func (m *myModule) example(repeat int) *Termcast  {
	return dag.
			Termcast().
			Backspace(repeat)
}
@function
def example(repeat: int) -> dag.Termcast:
	return (
		dag.termcast()
		.backspace(repeat)
	)
@func()
example(repeat: number): Termcast {
	return dag
		.termcast()
		.backspace(repeat)
}

file() 🔗

Encode the recording to a file in the asciicast v2 format

Return Type
File !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 file
func (m *myModule) example() *File  {
	return dag.
			Termcast().
			File()
}
@function
def example() -> dagger.File:
	return (
		dag.termcast()
		.file()
	)
@func()
example(): File {
	return dag
		.termcast()
		.file()
}

encode() 🔗

Encode the recording to a string in the asciicast v2 format

Return Type
String !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 encode
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			Termcast().
			Encode(ctx)
}
@function
async def example() -> str:
	return await (
		dag.termcast()
		.encode()
	)
@func()
async example(): Promise<string> {
	return dag
		.termcast()
		.encode()
}

play() 🔗

Return an interactive terminal that will play the recording, read-only.

Return Type
Void !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 play
func (m *myModule) example(ctx context.Context)   {
	return dag.
			Termcast().
			Play(ctx)
}
@function
async def example() -> None:
	return await (
		dag.termcast()
		.play()
	)
@func()
async example(): Promise<void> {
	return dag
		.termcast()
		.play()
}

gif() 🔗

Encode the recording into an animated GIF files

Return Type
File !
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 gif
func (m *myModule) example() *File  {
	return dag.
			Termcast().
			Gif()
}
@function
def example() -> dagger.File:
	return (
		dag.termcast()
		.gif()
	)
@func()
example(): File {
	return dag
		.termcast()
		.gif()
}

decode() 🔗

Decode an asciicast v2 file, and add its contents to the end of the recording.

See https://docs.asciinema.org/manual/asciicast/v2/
Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
dataString !-The data to decode, in asciicast format
expectHeaderBoolean !trueIndicate whether the decoder should expect an asciicast header. If true, the decoder will parse (and discrd) the header, the load the events If false, the decoder will look for events directly
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 decode --data string --expect-header boolean
func (m *myModule) example(data string, expectHeader bool) *Termcast  {
	return dag.
			Termcast().
			Decode(data, expectHeader)
}
@function
def example(data: str, expect_header: bool) -> dag.Termcast:
	return (
		dag.termcast()
		.decode(data, expect_header)
	)
@func()
example(data: string, expectHeader: boolean): Termcast {
	return dag
		.termcast()
		.decode(data, expectHeader)
}

imagine() 🔗

Ask an AI to imagine a terminal session, and add it to the recording

Return Type
Termcast !
Arguments
NameTypeDefault ValueDescription
promptString !"surprise me! an epic interactive session with a shell, language repl or database repl of your choice. the more exotic the better. Not python!"A description of the terminal session
Example
dagger -m github.com/shykes/x/termcast@b6da9888ed078e1573e9561b936dd1e5244f0a9f call \
 imagine --prompt string
func (m *myModule) example(prompt string) *Termcast  {
	return dag.
			Termcast().
			Imagine(prompt)
}
@function
def example(prompt: str) -> dag.Termcast:
	return (
		dag.termcast()
		.imagine(prompt)
	)
@func()
example(prompt: string): Termcast {
	return dag
		.termcast()
		.imagine(prompt)
}