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@755259c418d259f0f4b44d1808815e75392da898
Entrypoint
Return Type
Termcast !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
width | Integer | - | Terminal width |
height | Integer | - | Terminal height |
key | Secret | - | OpenAI auth key, for AI features |
container | Container | - | Containerized environment for executing commands |
shell | [String ! ] | - | Shell to use when executing commands |
prompt | String | - | The prompt shown by the interactive shell |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
ctr | Container ! | - | No description provided |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
data | String ! | - | No description provided |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
other | Termcast ! | - | 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
Name | Type | Default Value | Description |
---|---|---|---|
min | Integer ! | - | The minimum wait time, in milliseconds |
max | Integer ! | - | The maximum wait time, in milliseconds |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
ms | Integer ! | - | wait time, in milliseconds |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
cmd | String ! | - | The command to execute |
simple | Boolean | false | Toggle 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). |
fast | Boolean | - | Make simulated keystrokes faster |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
data | String ! | - | Data to input as keystrokes |
fast | Boolean | - | Make the simulating typing faster |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
repeat | Integer ! | 1 | Number of backspaces |
fast | Boolean | - | Make simulated keystrokes faster |
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 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)
}
encode() 🔗
Encode the recording to a string in the asciicast v2 format
Return Type
File !
Example
dagger -m github.com/shykes/x/termcast@755259c418d259f0f4b44d1808815e75392da898 call \
encode
func (m *myModule) example() *File {
return dag.
Termcast().
Encode()
}
@function
def example() -> dagger.File:
return (
dag.termcast()
.encode()
)
@func()
example(): File {
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@755259c418d259f0f4b44d1808815e75392da898 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@755259c418d259f0f4b44d1808815e75392da898 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
Name | Type | Default Value | Description |
---|---|---|---|
data | File ! | - | The data to decode, in asciicast format |
expectHeader | Boolean ! | true | Indicate 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@755259c418d259f0f4b44d1808815e75392da898 call \
decode --data file:path --expect-header boolean
func (m *myModule) example(data *File, expectHeader bool) *Termcast {
return dag.
Termcast().
Decode(data, expectHeader)
}
@function
def example(data: dagger.File, expect_header: bool) -> dag.Termcast:
return (
dag.termcast()
.decode(data, expect_header)
)
@func()
example(data: File, 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
Name | Type | Default Value | Description |
---|---|---|---|
prompt | String ! | "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@755259c418d259f0f4b44d1808815e75392da898 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)
}