Skip to content

Commit

Permalink
add !title command and more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vim-zz committed Sep 17, 2022
1 parent 4edc296 commit 30b8fa1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "swordfish-rs"
version = "0.5.2"
version = "0.6.0"
edition = "2021"
license-file = "LICENSE"
description = "Cli tool for typing effect in Termainl for screencasts"
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.rs → examples/intro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use swordfishlib;
use std::fs;

fn main() {
let data = fs::read_to_string("examples/screenplay.yaml").expect("Unable to read screenplay file");
let data = fs::read_to_string("examples/intro.yaml").expect("Unable to read screenplay file");
let commands = swordfishlib::from_yaml(&data).expect("Parsing errors in screenplay file");
swordfishlib::execute(commands).unwrap();
}
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/set_title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use swordfishlib;
use std::fs;

fn main() {
let data = fs::read_to_string("examples/set_title.yaml").expect("Unable to read screenplay file");
let commands = swordfishlib::from_yaml(&data).expect("Parsing errors in screenplay file");
swordfishlib::execute(commands).unwrap();
}
12 changes: 12 additions & 0 deletions examples/set_title.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- !clear
- !prompt {text: "$", color: green}
- !write {msec: 20, text: "swordfish can set the terminal title, look up..."}
- !wait {msec: 2000}
- !new_line
- !title {text: "swordfish demo"}
- !write {msec: 20, text: "nice!"}
- !wait {msec: 2000}
- !erase {msec: 20, amount: 100}
- !wait {msec: 1000}
- !write {msec: 20, text: "super nice!"}
- !wait {msec: 3000}
16 changes: 16 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum Command<'a> {
Pause(Pause),
#[serde(borrow)]
Prompt(Prompt<'a>),
#[serde(borrow)]
Title(Title<'a>),
Turbo(Turbo),
Wait(Wait),
#[serde(borrow)]
Expand Down Expand Up @@ -136,6 +138,20 @@ impl Runnable for Prompt<'_> {
}
}

/// `!title`
/// Title specify a constant text that is shown after every `execute` and cis not affected by `erase`.
#[derive(Debug, Deserialize)]
pub struct Title<'a> {
pub text: &'a str,
}

impl Runnable for Title<'_> {
fn run(&self, _state: &mut State) -> Result<()> {
functions::show_title(self.text)?;
Ok(())
}
}

/// `!turbo`
/// Speed everything, useful when iterating over the screenplay.
#[derive(Debug, Deserialize)]
Expand Down
5 changes: 5 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ pub fn show_prompt(prompt: &Option<String>) -> Result<()> {
stdout().flush()?;
}
Ok(())
}

pub fn show_title(text: &str) -> Result<()> {
write!(stdout(), "\x1B]0;{text}\x07")?;
Ok(())
}
1 change: 1 addition & 0 deletions tests/screenplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use swordfishlib;
fn play_commands() {
let screenplay = r###"
- !clear
- !title {text: "title here"}
- !prompt {color: bright_green, text: "$"}
- !write {msec: 0, color: blue, text: "$ "}
- !write {msec: 0, text: "i am going to list this dir"}
Expand Down

0 comments on commit 30b8fa1

Please sign in to comment.