pub struct CastWright { /* private fields */ }Expand description
The CastWright struct represents the main entry point for the CastWright library.
An instance of CastWright can be configured. It parses and executes CastWright scripts, and writes the resulting asciicast to a writer.
§Instantiation
To instantiate a CastWright instance, use the CastWright::new method.
§Configuration
You can then configure the instance using the following methods:
execute: Set whether to execute and capture the output of shell commands.timestamp: Set whether to include timestamp information in the output.preview: Set whether to preview the asciicast.
§Running
To parse and execute a CastWright script and write the resulting asciicast, use the run method, which takes mutable references to a reader and a writer. For better performance, a buffered writer is recommended.
§Example
use castwright::CastWright;
use std::io::BufReader;
// Input & output
let text = r#"
$ echo "Hello, World!"
"#;
let text = text.trim();
let mut reader = BufReader::new(text.as_bytes());
let mut writer = Vec::new();
// CastWright
let castwright = CastWright::new() // Instantiation & configuration
.execute(true)
.preview(true);
castwright.run(&mut reader, &mut writer).unwrap(); // Running
let asciicast = String::from_utf8_lossy(&writer); // OutputIf you prefer to use the default configuration:
CastWright::new().run(&mut reader, &mut writer).unwrap();
let asciicast = String::from_utf8_lossy(&writer);Implementations§
Source§impl CastWright
impl CastWright
Sourcepub const fn execute(self, execute: bool) -> Self
pub const fn execute(self, execute: bool) -> Self
Set whether to execute and capture the output of shell commands.
Sourcepub const fn timestamp(self, timestamp: bool) -> Self
pub const fn timestamp(self, timestamp: bool) -> Self
Set whether to include timestamp information in the output.
Sourcepub fn run(
&self,
reader: &mut impl BufRead,
writer: &mut impl Write,
) -> Result<(), Error>
pub fn run( &self, reader: &mut impl BufRead, writer: &mut impl Write, ) -> Result<(), Error>
Interpret and run a CastWright script from a reader, writing the asciicast to a writer.
§Errors
This method returns an error if the script contains any syntax errors, or any errors occur during execution.