Skip to content

Commit eac7319

Browse files
committed
[Feat] add more examples for library
1 parent 799a7a4 commit eac7319

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

core/examples/ascii.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use codesnap::config::{BreadcrumbsBuilder, CodeBuilder, CodeConfigBuilder, CodeSnap, Content};
2+
3+
pub fn main() -> anyhow::Result<()> {
4+
let code_content = Content::Code(
5+
CodeBuilder::default()
6+
.content(
7+
r#"pub fn main() {
8+
println!("Hello, world!");
9+
}"#,
10+
)
11+
.language("rust")
12+
.start_line_number(10u32)
13+
.file_path("core/examples/breadcrumbs.rs")
14+
.build()?,
15+
);
16+
17+
let breadcrumbs = BreadcrumbsBuilder::default()
18+
.enable(true)
19+
.separator(" > ")
20+
.build()?;
21+
let code_config = CodeConfigBuilder::default()
22+
.breadcrumbs(breadcrumbs)
23+
.build()?;
24+
25+
let snapshot = CodeSnap::from_default_theme()?
26+
.code_config(code_config)
27+
.content(code_content)
28+
.build()?
29+
.create_ascii_snapshot()?;
30+
31+
// Copy the snapshot data to the clipboard
32+
snapshot.raw_data()?.copy()
33+
}

core/examples/breadcrumbs.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use codesnap::config::{BreadcrumbsBuilder, CodeBuilder, CodeConfigBuilder, CodeSnap, Content};
2+
3+
pub fn main() -> anyhow::Result<()> {
4+
let code_content = Content::Code(
5+
CodeBuilder::default()
6+
.content(r#"pub fn main() {}"#)
7+
.language("rust")
8+
.file_path("core/examples/breadcrumbs.rs")
9+
.build()?,
10+
);
11+
12+
let breadcrumbs = BreadcrumbsBuilder::default()
13+
.enable(true)
14+
.separator(" > ")
15+
.build()?;
16+
let code_config = CodeConfigBuilder::default()
17+
.breadcrumbs(breadcrumbs)
18+
.build()?;
19+
20+
let snapshot = CodeSnap::from_default_theme()?
21+
.content(code_content)
22+
.code_config(code_config)
23+
.build()?
24+
.create_snapshot()?;
25+
26+
// Copy the snapshot data to the clipboard
27+
snapshot.raw_data()?.copy()
28+
}

core/examples/highlight.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use codesnap::config::{CodeBuilder, CodeSnap, Content, HighlightLine};
2+
3+
pub fn main() -> anyhow::Result<()> {
4+
let code_content = Content::Code(
5+
CodeBuilder::default()
6+
.content(
7+
r##"pub fn main() {
8+
println!("Hello, world!");
9+
println!("Hello, CodeSnap!");
10+
}"##,
11+
)
12+
.language("rust")
13+
.highlight_lines(vec![
14+
HighlightLine::Single(2, "#ff6b6b30".to_string()),
15+
HighlightLine::Single(3, "#2ecc7130".to_string()),
16+
])
17+
.build()?,
18+
);
19+
20+
let snapshot = CodeSnap::from_default_theme()?
21+
.content(code_content)
22+
.build()?
23+
.create_snapshot()?;
24+
25+
// Copy the snapshot data to the clipboard
26+
snapshot.raw_data()?.copy()
27+
}

core/examples/line_number.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use codesnap::config::{CodeBuilder, CodeSnap, Content};
2+
3+
pub fn main() -> anyhow::Result<()> {
4+
let code_content = Content::Code(
5+
CodeBuilder::default()
6+
.content(
7+
r#"pub fn main() {
8+
println!("Hello, world!");
9+
}"#,
10+
)
11+
.language("rust")
12+
.start_line_number(10u32)
13+
.build()?,
14+
);
15+
16+
let snapshot = CodeSnap::from_default_theme()?
17+
.content(code_content)
18+
.build()?
19+
.create_snapshot()?;
20+
21+
// Copy the snapshot data to the clipboard
22+
snapshot.raw_data()?.copy()
23+
}

0 commit comments

Comments
 (0)