Skip to content

Commit

Permalink
dirty hack to ensure we remove ansi escape codes after parsing all parts
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Aug 10, 2024
1 parent c2acbc4 commit 77ff862
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/iwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn parse_iwd_networks(
networks: Vec<String>,
) -> Result<(), Box<dyn Error>> {
let ansi_escape = Regex::new(r"\x1B\[[0-9;]*m.*?\x1B\[0m")?;
let full_ansi_escape = Regex::new(r"\x1B\[[0-?]*[ -/]*[@-~]")?;

networks.into_iter().for_each(|network| {
let line = ansi_escape.replace_all(&network, "").to_string();
Expand All @@ -67,6 +68,7 @@ fn parse_iwd_networks(
let signal = parts.pop().unwrap().trim();
let security = parts.pop().unwrap().trim();
let ssid = line[..line.find(security).unwrap()].trim();
let ssid = full_ansi_escape.replace_all(ssid, "").to_string();
let display = format!(
"{} {:<25}\t{:<11}\t{}",
if connected { "✅" } else { "📶" },
Expand Down

0 comments on commit 77ff862

Please sign in to comment.