Skip to content

Commit 174def4

Browse files
committed
[Feat] add command output example
1 parent a3031ab commit 174def4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/examples/command_output.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use codesnap::config::{CodeSnap, CommandLineContentBuilder, Content};
2+
use std::process::Command;
3+
4+
pub fn main() -> anyhow::Result<()> {
5+
let command = "echo \"Hello, World!\"";
6+
let output = Command::new("sh")
7+
.arg("-c")
8+
.arg(command)
9+
.output()
10+
.expect("failed to execute process");
11+
12+
let command_line_content = CommandLineContentBuilder::default()
13+
.full_command(command)
14+
.content(String::from_utf8_lossy(&output.stdout).into_owned())
15+
.build()
16+
.unwrap();
17+
18+
let command_content = Content::CommandOutput(vec![command_line_content]);
19+
let snapshot = CodeSnap::from_default_theme()?
20+
.content(command_content)
21+
.build()?
22+
.create_snapshot()?;
23+
24+
// Copy the snapshot data to the clipboard
25+
snapshot.raw_data()?.copy()
26+
}

0 commit comments

Comments
 (0)