Asynchronous function that captures a shell session and then renders it as an animated terminal screencast. A new shell session will be spawned and piped to process.stdout and process.stdin, then you interact with the shell until it is exited or you press Ctrl+D.
tip
The shell session recording can be stopped with Ctrl+D.
Returns a promise that resolves either a string if the output format option is 'svg', 'json', or 'yaml', or a Buffer if the output format is 'png'.
The shell to run. If unspecified, Unix will try to use the current shell (process.env.SHELL), falling back to /bin/sh if that fails. Windows will try to use process.env.ComSpec, falling back to cmd.exe if that fails.
Environment key-value pairs to be set for the shell process. Automatically extends from process.env, which can be changed by setting extendEnv to false. Default is undefined.
Option passed to node-pty concerning whether to use ConPTY over winpty. If set to undefined, ConPTY will be used over winpty when the Windows build number is >= 18309. Defaults to false.
Here is a basic example of a script that spawns and captures a new shell process. It will run powershell on windows or zsh in unix like environments, and the shell will start from the user's home directory. The rendered screencast svg is written to a file called capture.svg in the current working directory using the outputPath option.
Below is an example execution that captures a zsh shell process where the user runs the command echo Hello World! and then exits the shell.
capture.js
#!/usr/bin/env node import{ homedir }from'os'; import{ captureShell }from'cli-screencast'; captureShell({ // Use PowerShell on Windows, Zsh on Unix-based OS shell: process.platform==='win32'?'pwsh.exe':'zsh', // Start shell session from the user's home directory cwd:homedir(), columns:50, rows:10, // Customize cursor appearance theme:{cursorStyle:'underline',cursorBlink:true}, // Save output SVG to a file in the directory this script is run in outputPath:'./capture.svg', });