Skip to content

Commit

Permalink
Merge pull request #134 from blacknon/0.3.15
Browse files Browse the repository at this point in the history
version 0.3.15
  • Loading branch information
blacknon authored Jun 18, 2024
2 parents e8d0db8 + cf22e13 commit aae6789
Show file tree
Hide file tree
Showing 13 changed files with 1,066 additions and 549 deletions.
922 changes: 539 additions & 383 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords = ["watch", "command", "monitoring"]
license-file = "LICENSE"
name = "hwatch"
repository = "https://github.com/blacknon/hwatch"
version = "0.3.14"
version = "0.3.15"

[dependencies]
ansi-parser = "0.9.0"
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ hwatch -n 3 -s 'bash -c "source ~/.bashrc"; {COMMAND}' command...
hwatch -n 3 -s 'zsh -c "source ~/.zshrc"; {COMMAND}' command...
```

<p align="center">
<img src="./img/shell_function.gif" />
</p>

### ANSI Color code

If you want to see output colored with ANSI color code, enable color mode.
Expand All @@ -244,10 +240,6 @@ Alternatively, you can enable / disable the color mode with the <kbd>C</kbd> key
hwatch -n 3 -c command...
```

<p align="center">
<img src="./img/ansi_color.gif" />
</p>

### diff view

To enable color mode, run hwatch with the `-d` option.
Expand Down
29 changes: 29 additions & 0 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,32 @@ pub fn get_ansi_strip_str(text: &str) -> String {

line_str
}

///
pub fn escape_ansi(input: &str) -> String {
let mut result = String::new();
let mut chars = input.chars().peekable();

while let Some(ch) = chars.next() {
if ch == '\x1b' {
if let Some('[') = chars.peek() {
result.push_str("\\x1b[");
chars.next(); // Consume '['
while let Some(ch) = chars.peek() {
result.push(*ch);
if ch.is_alphabetic() {
chars.next(); // Consume the letter
break;
}
chars.next(); // Consume the number or ';'
}
} else {
result.push(ch);
}
} else {
result.push(ch);
}
}

result
}
Loading

0 comments on commit aae6789

Please sign in to comment.