Skip to content

Commit 30b8fa1

Browse files
committed
add !title command and more examples
1 parent 4edc296 commit 30b8fa1

File tree

8 files changed

+44
-2
lines changed

8 files changed

+44
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "swordfish-rs"
3-
version = "0.5.2"
3+
version = "0.6.0"
44
edition = "2021"
55
license-file = "LICENSE"
66
description = "Cli tool for typing effect in Termainl for screencasts"

examples/demo.rs renamed to examples/intro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use swordfishlib;
22
use std::fs;
33

44
fn main() {
5-
let data = fs::read_to_string("examples/screenplay.yaml").expect("Unable to read screenplay file");
5+
let data = fs::read_to_string("examples/intro.yaml").expect("Unable to read screenplay file");
66
let commands = swordfishlib::from_yaml(&data).expect("Parsing errors in screenplay file");
77
swordfishlib::execute(commands).unwrap();
88
}
File renamed without changes.

examples/set_title.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use swordfishlib;
2+
use std::fs;
3+
4+
fn main() {
5+
let data = fs::read_to_string("examples/set_title.yaml").expect("Unable to read screenplay file");
6+
let commands = swordfishlib::from_yaml(&data).expect("Parsing errors in screenplay file");
7+
swordfishlib::execute(commands).unwrap();
8+
}

examples/set_title.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- !clear
2+
- !prompt {text: "$", color: green}
3+
- !write {msec: 20, text: "swordfish can set the terminal title, look up..."}
4+
- !wait {msec: 2000}
5+
- !new_line
6+
- !title {text: "swordfish demo"}
7+
- !write {msec: 20, text: "nice!"}
8+
- !wait {msec: 2000}
9+
- !erase {msec: 20, amount: 100}
10+
- !wait {msec: 1000}
11+
- !write {msec: 20, text: "super nice!"}
12+
- !wait {msec: 3000}

src/commands.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum Command<'a> {
1818
Pause(Pause),
1919
#[serde(borrow)]
2020
Prompt(Prompt<'a>),
21+
#[serde(borrow)]
22+
Title(Title<'a>),
2123
Turbo(Turbo),
2224
Wait(Wait),
2325
#[serde(borrow)]
@@ -136,6 +138,20 @@ impl Runnable for Prompt<'_> {
136138
}
137139
}
138140

141+
/// `!title`
142+
/// Title specify a constant text that is shown after every `execute` and cis not affected by `erase`.
143+
#[derive(Debug, Deserialize)]
144+
pub struct Title<'a> {
145+
pub text: &'a str,
146+
}
147+
148+
impl Runnable for Title<'_> {
149+
fn run(&self, _state: &mut State) -> Result<()> {
150+
functions::show_title(self.text)?;
151+
Ok(())
152+
}
153+
}
154+
139155
/// `!turbo`
140156
/// Speed everything, useful when iterating over the screenplay.
141157
#[derive(Debug, Deserialize)]

src/functions.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ pub fn show_prompt(prompt: &Option<String>) -> Result<()> {
2323
stdout().flush()?;
2424
}
2525
Ok(())
26+
}
27+
28+
pub fn show_title(text: &str) -> Result<()> {
29+
write!(stdout(), "\x1B]0;{text}\x07")?;
30+
Ok(())
2631
}

tests/screenplay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use swordfishlib;
44
fn play_commands() {
55
let screenplay = r###"
66
- !clear
7+
- !title {text: "title here"}
78
- !prompt {color: bright_green, text: "$"}
89
- !write {msec: 0, color: blue, text: "$ "}
910
- !write {msec: 0, text: "i am going to list this dir"}

0 commit comments

Comments
 (0)