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.
Fix Re-enabling manual Style creation (#47)
* Fix Style breakage Move OSControl out of Style PR #43 created a regression where code that manually instantiated a Style could no longer be created without using the update operator and Default trait on Style. Rather than place non-public functions and data in Style move it all into AnsiGenericString. This has the added benefit of greatly simplifying the code. Fixes #46 * testing: Add manual instance test for Style PR #43 introduced a pub(crate) field in Style which broke the intended API (See: Issue #46). Introduce a new test which will fail in those cases since it won't be able to initialize pub(crate) fields. Inspired by: #46 (comment) * Add examples of OSC usage * CI: Run OSC examples --------- Co-authored-by: Matt Helsley <[email protected]>
- Loading branch information
Showing
9 changed files
with
247 additions
and
349 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
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,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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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); | ||
} | ||
} |
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,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 {:?} milliseconds", | ||
title, sleep_ms | ||
); | ||
|
||
// sleep because often prompts change this before you can see | ||
// the results | ||
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
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
Oops, something went wrong.