Skip to content

Commit a909742

Browse files
committed
new_line command
1 parent 3474821 commit a909742

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.3.2"
3+
version = "0.4.0"
44
edition = "2021"
55
license-file = "LICENSE"
66
description = "Cli tool for typing effect in Termainl for screencasts"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ Prompt specify a constant text that is shown after every `execute` and cis not a
110110
| - | - | - |
111111
|`text`| String | the prompt text |
112112
|`color` (optional)| String | text's color: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white` or a brighter variant, for example `bright_red` |
113+
114+
#### `new_line`
115+
116+
Simulate user's `ENTER`.

examples/screenplay.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- !clear
22
- !prompt {text: "$", color: green}
33
- !write {msec: 20, text: "i am going to list this dir"}
4+
- !new_line
45
- !wait {msec: 1000}
56
- !erase {msec: 20, amount: 100}
67
- !wait {msec: 1000}

src/commands.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use serde::{Deserialize};
33
#[derive(Debug, Deserialize)]
44
#[serde(rename_all = "snake_case")]
55
pub enum Command<'a> {
6-
Write {msec: u32, color: Option<&'a str>, text: &'a str},
6+
Clear,
77
Erase {msec: u32, by_chars: Option<&'a str>, amount: Option<u32>},
88
Execute {line: &'a str},
9-
Wait {msec: u32},
10-
Clear,
9+
NewLine,
1110
Pause,
12-
Prompt {text: &'a str, color: Option<&'a str>}
11+
Prompt {text: &'a str, color: Option<&'a str>},
12+
Wait {msec: u32},
13+
Write {msec: u32, color: Option<&'a str>, text: &'a str},
1314
}

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ pub fn execute(commands: Vec<Command>) -> Result<()> {
7070
show_prompt(&prompt)?;
7171
cursor = 0;
7272
},
73+
Command::NewLine => {
74+
print!("\n");
75+
show_prompt(&prompt)?;
76+
cursor = 0;
77+
}
7378
}
7479
}
7580

tests/screenplay.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
use swordfishlib;
22

33
#[test]
4-
fn it_adds_two() {
4+
fn play_commands() {
55
let screenplay = r###"
66
- !clear
7-
- !write {msec: 0, color: green, text: "$ "}
7+
- !prompt {color: green, text: "$"}
8+
- !write {msec: 0, color: blue, text: "$ "}
89
- !write {msec: 0, text: "i am going to list this dir"}
910
- !wait {msec: 0}
10-
- !erase {msec: 0, by_chars: xxxxxxxxxxxxxxxxxxxxxxxxxxx }
11+
- !erase {msec: 0, by_chars: xxxxxxxxxxxxxxxxxxxxxxxxxxx, amount: 5 }
1112
- !wait {msec: 0}
1213
- !write {msec: 0, text: "echo swordfish"}
1314
- !wait {msec: 0}
1415
- !execute {line: echo swordfish}
1516
- !wait {msec: 0}
16-
- !write {msec: 0, color: green, text: "$ "}
17+
- !new_line
1718
- !write {msec: 0, text: "bye, press any key..."}
1819
"###;
1920

2021
let commands = swordfishlib::from_yaml(&screenplay).unwrap();
22+
assert_eq!(commands.len(), 13);
2123
swordfishlib::execute(commands).unwrap();
2224
}

0 commit comments

Comments
 (0)