forked from ogham/rust-ansi-term
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Helsley
committed
Jun 27, 2023
1 parent
8ba9dfb
commit b8a2f80
Showing
5 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
use nu_ansi_term::AnsiGenericString; | ||
mod may_sleep; | ||
use may_sleep::{parse_cmd_args, sleep}; | ||
|
||
fn main() { | ||
#[cfg(windows)] | ||
nu_ansi_term::enable_ansi_support().unwrap(); | ||
|
||
let sleep_ms = parse_cmd_args(); | ||
let path = std::path::Path::new("./for_cwd/").to_str().unwrap(); | ||
let cwd = AnsiGenericString::cwd(path); | ||
println!( | ||
"{}Terminal working directory set for the next 5 seconds.", | ||
cwd | ||
"{}Terminal working directory set for the next {:?} milliseconds", | ||
cwd, sleep_ms | ||
); | ||
|
||
// sleep because often prompts change this before you can see | ||
// the results | ||
let delay_ms = std::time::Duration::from_millis(5000); | ||
std::thread::sleep(delay_ms); | ||
sleep(sleep_ms); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
use nu_ansi_term::Color; | ||
mod may_sleep; | ||
use may_sleep::{parse_cmd_args, sleep}; | ||
|
||
fn main() { | ||
#[cfg(windows)] | ||
nu_ansi_term::enable_ansi_support().unwrap(); | ||
|
||
let sleep_ms = parse_cmd_args(); | ||
let mut link = Color::Blue.underline().paint("Link to example.com"); | ||
link.hyperlink("https://example.com"); | ||
|
||
println!("{}", link); | ||
sleep(sleep_ms); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
use nu_ansi_term::AnsiGenericString; | ||
mod may_sleep; | ||
use may_sleep::{parse_cmd_args, sleep}; | ||
|
||
fn main() { | ||
#[cfg(windows)] | ||
nu_ansi_term::enable_ansi_support().unwrap(); | ||
|
||
let sleep_ms = parse_cmd_args(); | ||
// TODO add foo.icn foo.bmp or whatever is most portable | ||
let path = std::path::Path::new("./foo.icn").to_str().unwrap(); | ||
let icon = AnsiGenericString::icon(path); | ||
println!("{}Terminal icon title set for the next 5 seconds.", icon); | ||
println!( | ||
"{}Terminal icon title set for the next {:?} milliseconds", | ||
icon, sleep_ms | ||
); | ||
|
||
// sleep because often prompts change this before you can see | ||
// the results | ||
let delay_ms = std::time::Duration::from_millis(5000); | ||
std::thread::sleep(delay_ms); | ||
sleep(sleep_ms); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
pub fn parse_cmd_args() -> Option<u16> { | ||
let mut sleep_ms: Option<u16> = None; | ||
let mut skip_next = false; | ||
|
||
for (i, arg) in std::env::args().skip(1).enumerate() { | ||
if skip_next { | ||
skip_next = false; | ||
continue; | ||
} | ||
|
||
match &arg[..] { | ||
"-s" | "--sleep" => { | ||
sleep_ms = std::env::args() | ||
.nth(i + 2) // next is +2 because .skip(1) | ||
.unwrap_or(String::from("5000u16")) | ||
.parse::<u16>() | ||
.ok() | ||
.and_then(|parsed| { | ||
skip_next = true; | ||
Some(parsed) | ||
}); | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
sleep_ms | ||
} | ||
|
||
pub fn sleep(sleep_ms: Option<u16>) { | ||
if let Some(sleep_ms) = sleep_ms { | ||
let sleep_ms = std::time::Duration::from_millis(sleep_ms as u64); | ||
std::thread::sleep(sleep_ms); | ||
} | ||
} | ||
|
||
/*#[allow(unused)] | ||
fn main() -> Result<(),()> { | ||
Err(()) | ||
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
use nu_ansi_term::AnsiGenericString; | ||
mod may_sleep; | ||
use may_sleep::{parse_cmd_args, sleep}; | ||
|
||
fn main() { | ||
#[cfg(windows)] | ||
nu_ansi_term::enable_ansi_support().unwrap(); | ||
|
||
let sleep_ms = parse_cmd_args(); | ||
let title = AnsiGenericString::title("My Title"); | ||
println!("{}Terminal title set for the next 5 seconds.", title); | ||
println!( | ||
"{}Terminal title set for the next {:?} milliseconds", | ||
title, sleep_ms | ||
); | ||
|
||
// sleep because often prompts change this before you can see | ||
// the results | ||
let delay_ms = std::time::Duration::from_millis(5000); | ||
std::thread::sleep(delay_ms); | ||
sleep(sleep_ms); | ||
} |