diff --git a/Cargo.lock b/Cargo.lock
index e9f6ed2..9c78e02 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"once_cell",
- "version_check 0.9.4",
+ "version_check",
"zerocopy",
]
@@ -44,6 +44,16 @@ dependencies = [
"libc",
]
+[[package]]
+name = "ansi-parser"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fad5bd94a775101bd68c2de2bb28ca2eccd69f395ae3aec4ac4f6da3c1cd2c6a"
+dependencies = [
+ "heapless",
+ "nom",
+]
+
[[package]]
name = "ansi_term"
version = "0.12.1"
@@ -758,7 +768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
dependencies = [
"typenum",
- "version_check 0.9.4",
+ "version_check",
]
[[package]]
@@ -829,8 +839,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hwatch"
-version = "0.3.12"
+version = "0.3.13"
dependencies = [
+ "ansi-parser",
"ansi_term",
"async-std",
"chrono",
@@ -841,7 +852,6 @@ dependencies = [
"difference",
"futures",
"heapless",
- "hwatch-ansi-parser",
"question",
"ratatui",
"regex",
@@ -852,16 +862,6 @@ dependencies = [
"termwiz",
]
-[[package]]
-name = "hwatch-ansi-parser"
-version = "0.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f79b25b14f15196ed2543a380d24eb102b6292855bb36f475a959b015f4882a2"
-dependencies = [
- "heapless",
- "nom 4.2.3",
-]
-
[[package]]
name = "iana-time-zone"
version = "0.1.60"
@@ -1092,16 +1092,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "nom"
-version = "4.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
-dependencies = [
- "memchr",
- "version_check 0.1.5",
-]
-
[[package]]
name = "nom"
version = "7.1.3"
@@ -1674,7 +1664,7 @@ checksum = "666cd3a6681775d22b200409aad3b089c5b99fb11ecdd8a204d9d62f8148498f"
dependencies = [
"dirs",
"fnv",
- "nom 7.1.3",
+ "nom",
"phf",
"phf_codegen",
]
@@ -1805,15 +1795,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55"
dependencies = [
"ctor",
- "version_check 0.9.4",
+ "version_check",
]
-[[package]]
-name = "version_check"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
-
[[package]]
name = "version_check"
version = "0.9.4"
diff --git a/Cargo.toml b/Cargo.toml
index 9aa2272..ffd6410 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,12 +6,11 @@ keywords = ["watch", "command", "monitoring"]
license-file = "LICENSE"
name = "hwatch"
repository = "https://github.com/blacknon/hwatch"
-version = "0.3.12"
+version = "0.3.13"
[dependencies]
-# TODO: ansi-parserが正式にバージョンアップしたらそちらに切り替える
+ansi-parser = "0.9.0"
heapless = "0.6.1"
-hwatch-ansi-parser = "0.9.0"
ansi_term = "0.12.1"
async-std = {version = "1.12"}
diff --git a/README.md b/README.md
index 847926c..9273e2a 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,7 @@ That records the result of command execution and can display it history and diff
-B, --beep beep if command has a change result
--mouse enable mouse wheel support. With this option, copying text with your terminal may be harder. Try holding the Shift key.
-c, --color interpret ANSI color and style sequences
+ -r, --reverse display text upside down.
-t, --no-title hide the UI on start. Use `t` to toggle it.
-N, --line-number show line number
--no-help-banner hide the "Display help with h key" message
@@ -71,8 +72,6 @@ That records the result of command execution and can display it history and diff
-V, --version Print version
-
-
watch window keybind
| Key | Action |
@@ -82,6 +81,7 @@ watch window keybind
| → | select history screen. |
| H | show help window. |
| C | toggle color. |
+| R | toggle reverse mode. |
| D | switch diff mode. |
| N | switch line number display. |
| T | toggle the UI (history pane and header). |
@@ -103,7 +103,6 @@ watch window keybind
| * | filter history by regex. |
| Esc | unfiltering. |
-
## Configuration
If you always want to use some command-line options, you can set them in the
@@ -154,7 +153,6 @@ hwatch -n 3 -s 'zsh -c "source ~/.zshrc"; {COMMAND}' command...
-
### ANSI Color code
If you want to see output colored with ANSI color code, enable color mode.
@@ -170,7 +168,6 @@ hwatch -n 3 -c command...
-
### diff view
To enable color mode, run hwatch with the `-d` option.
@@ -200,12 +197,10 @@ hwatch -n 3 -d command...
-
### history filtering
You can filter history as a string with / key and as a regular expression with * key.
-
### run batch mode
You can have command diffs output directly to stdout instead with `-b` option of getting them as a TUI app.
diff --git a/examples/version.rs b/examples/version.rs
deleted file mode 100644
index 845fb34..0000000
--- a/examples/version.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright (c) 2021 Blacknon. All rights reserved.
-// Use of this source code is governed by an MIT license
-// that can be found in the LICENSE file.
-
-fn main() {
- println!("{}", env!("CARGO_PKG_VERSION"));
-}
diff --git a/man/hwatch.1 b/man/hwatch.1
index 6c3bf2d..fffb607 100644
--- a/man/hwatch.1
+++ b/man/hwatch.1
@@ -1,17 +1,14 @@
-.\" Automatically generated by Pandoc 2.9.1.1
+.\" Automatically generated by Pandoc 3.1.13
.\"
-.TH "hwatch" "1" "" "Version 0.3.1" "A modern alternative to the watch command, records the differences in execution results and can check this differences at after."
-.hy
+.TH "hwatch" "1" "" "Version 0.3.13" "A modern alternative to the watch command, records the differences in execution results and can check this differences at after."
.SH NAME
-.PP
-\f[B]hwatch\f[R] - A modern alternative to the watch command, records
+\f[B]hwatch\f[R] \- A modern alternative to the watch command, records
the differences in execution results and can check this differences at
after.
.SH SYNOPSIS
.PP
\f[B]hwatch\f[R] [\f[I]options\f[R]] \f[I]command\f[R]
.SH DESCRIPTION
-.PP
\f[B]hwatch\f[R] is like \f[I]watch\f[R] command, repeatedly executes a
\f[I]command\f[R] and displays its output.
However, the output results can be scrolled and displayed.
@@ -24,38 +21,108 @@ If you specify it with options, the execution result can be recorded as
a log with json.
.SS Flags
.TP
--h, \[en]help
+\-h, \-\-help
Prints help information
.TP
--V, \[en]version
+\-V, \-\-version
Prints version information
.TP
--c, \[en]color
+\-b, \-\-batch
+Output exection results to stdout.
+NOTE: Operations with TUI are not possible in batch mode.
+.TP
+\-B, \-\-beep
+beep if command has a change result.
+.TP
+\-\-mouse
+enable mouse wheel support.
+With this option, copying text with your terminal may be harder.
+Try holding the Shift key.
+.TP
+\-c, \-\-color
Interpret ANSI colors and style sequences and display in color.
It can be changed later by key binding.
.TP
--d, \[en]differences
-Highlight changes between updates.
-The diff specified by this flag is similar to the \f[I]watch\f[R]
-command.
-It can be changed later by key binding.
+\-r, \-\-reverse
+Display text upside down.
.TP
--N, \[en]line-number
+\-t, \-\-no\-title
+Hide the UI on start.
+Use \f[CR]t\f[R] to toggle it.
+.TP
+\-N, \-\-line\-number
Show line number.
+.TP
+\-\-no\-help\-banner
+Hide the \[lq]Display help with h key\[rq] message
+.TP
+\-e, \-\-exec
+Run the command directly, not through the shell.
+Much like the \f[CR]\-x\f[R] option of the watch command.
+.TP
+\-O, \-\-diff\-output\-only
+Display only the lines with differences during \f[CR]line\f[R] diff and
+\f[CR]word\f[R] diff.
.SS Options
.TP
--n, \[en]interval \f[I]seconds\f[R]
+\-A, \-\-aftercommand \f[I]command to execute after difference occurs\f[R]
+Executes the specified command if the output changes.
+Information about changes is stored in json format in environment
+variable \f[CR]${HWATCH_DATA}\f[R].
+.TP
+\-l, \-\-logfile \f[I]logfile\f[R]
+Output the command execution result and its time as a log in json.
+The execution results that are recorded are only those that differ from
+the previous execution results.
+.TP
+\-s, \-\-shell \f[I]shell command\f[R]
+shell to use at runtime.
+can also insert the command to the location specified by {COMMAND}.
+.TP
+\-n, \-\-interval \f[I]seconds\f[R]
Specify update interval.
The command will not allow quicker than \f[B]0.001\f[R] second interval,
in which the smaller values are converted.
Both `.' and `,' work for any locales.
.TP
--l, \[en]logfile \f[I]logfile\f[R]
-Output the command execution result and its time as a log in json.
-The execution results that are recorded are only those that differ from
-the previous execution results.
-.SH KEYBINDS
+\-\-tab\-size \f[I]num\f[R]
+Specifying tab display size.
+default 4 char.
+.TP
+\-d, \-\-differences \f[I][none, watch, line, word]\f[R]
+set diff mode.
+highlight changes between updates.
+If only \f[CR]\-d\f[R] is specified, it will be a watch diff.
+.RS
+.PP
+\f[I]plane\f[R] \&...
+Do not show diff (default).
+.PP
+\f[I]watch\f[R] \&...
+Diff like watch command.
+Specifying the \f[I]\-d\f[R] option applies this mode.
.PP
+\f[I]line\f[R] \&...
+Can be done diff in line units.
+.PP
+\f[I]word\f[R] \&...
+Can be done diff in line word units.
+.RE
+.TP
+\-o, \-\-output
+set output mode.
+If you specify the output mode, the history pane will also display only
+the history where the specified output mode has changed.
+.SS Configuration
+If you always want to use some command\-line options, you can set them
+in the \f[CR]HWATCH\f[R] environment variable.
+For example, if you use \f[CR]bash\f[R], you can add the following to
+your \f[CR].bashrc\f[R]:
+.IP
+.EX
+export HWATCH=\[dq]\-\-no\-title \-\-color \-\-no\-help\-banner\[dq]
+.EE
+.SH KEYBINDS
\f[B]hwatch\f[R] uses \f[I]Keybind\f[R] for operations on the command
execution screen.
.TP
@@ -68,30 +135,60 @@ Exit hwatch.
.TP
c
Interprets ANSI colors and style sequences and displays them in color.
-This is the same as the \f[I]-c(\[en]color)\f[R] option.
+This is the same as the \f[I]\-c(\[en]color)\f[R] option.
Press the \f[I]c\f[R] key again to return to the original.
.TP
+n
+Outputs the line number at the beginning of the line.
+.TP
+r
+Displays the output of the watch pane in reverse order.
+.TP
d
Highlight changes between updates.
The diff specified by this flag is similar to the \f[I]watch\f[R]
command.
-This is the same as the \f[I]-d(\[en]differences)\f[R] option.
+This is the same as the \f[I]\-d(\[en]differences)\f[R] option.
You can switch the diff mode by pressing the \f[I]d\f[R] key.
The \f[I]d\f[R] key toggles these in order.
Use the \f[I]0\f[R], \f[I]1\f[R], and \f[I]2\f[R] keys to switch
directly to each mode.
.RS
.PP
-\f[I]plane\f[R] \&... Do not show diff (default).
+\f[I]plane\f[R] \&...
+Do not show diff (default).
.PP
-\f[I]watch\f[R] \&... Diff like watch command.
-Specifying the \f[I]-d\f[R] option applies this mode.
+\f[I]watch\f[R] \&...
+Diff like watch command.
+Specifying the \f[I]\-d\f[R] option applies this mode.
.PP
-\f[I]line\f[R] \&... Can be done diff in line units.
+\f[I]line\f[R] \&...
+Can be done diff in line units.
.PP
-\f[I]word\f[R] \&... Can be done diff in line word units.
+\f[I]word\f[R] \&...
+Can be done diff in line word units.
.RE
.TP
+o
+Switch output mode at stdout, stderr, and output.
+If you specify the output mode, the history pane will also display only
+the history where the specified output mode has changed.
+.TP
+O
+Display only the lines with differences during \f[CR]line\f[R] diff and
+\f[CR]word\f[R] diff.
+.TP
+t
+Switch display of header and history pane.
+.TP
+Backspace
+Switch display of history pane.
+.TP
+m
+Switch Mouse wheel support mode.
+With this option, copying text with your terminal may be harder.
+Try holding the Shift key.
+.TP
0
Switch diff mode to \f[I]plane\f[R].
.TP
@@ -113,6 +210,12 @@ Display only \f[I]Stderr\f[R].
F3
Display \f[I]Stdout\f[R] and \f[I]Stderr\f[R].
.TP
++
+Increase interval by 0.5 seconds.
+.TP
+\-
+Decrease interval by 0.5 seconds (As long as it\[cq]s positive).
+.TP
Tab
Switch the target(\f[I]history\f[R] or \f[I]watch\f[R] pad).
The target is operated with the \f[I]up\f[R] and \f[I]down\f[R] keys.
@@ -123,8 +226,10 @@ Filter diffs by keyword.
*
Filter diffs by regex.
.SH BUGS
-.PP
-See GitHub Issues:
+See GitHub Issues: \c
+.UR https://github.com/blacknon/hwatch/issues
+.UE \c
.SH AUTHOR
-.PP
-Blacknon
+Blacknon \c
+.MT blacknon@orebibou.com
+.ME \c
diff --git a/man/man.md b/man/man.md
index 74f83d1..45b8557 100644
--- a/man/man.md
+++ b/man/man.md
@@ -1,4 +1,4 @@
-% hwatch(1) Version 0.3.5 | A modern alternative to the watch command, records the differences in execution results and can check this differences at after.
+% hwatch(1) Version 0.3.13 | A modern alternative to the watch command, records the differences in execution results and can check this differences at after.
NAME
====
@@ -24,45 +24,125 @@ If you specify it with options, the execution result can be recorded as a log wi
Flags
-----
--h, --help
+-h, \--help
: Prints help information
--V, --version
+-V, \--version
: Prints version information
--c, --color
+-b, \--batch
+
+: Output exection results to stdout. NOTE: Operations with TUI are not possible in batch mode.
+
+
+-B, \--beep
+
+: beep if command has a change result.
+
+
+\--mouse
+
+: enable mouse wheel support. With this option, copying text with your terminal may be harder. Try holding the Shift key.
+
+
+-c, \--color
: Interpret ANSI colors and style sequences and display in color. It can be changed later by key binding.
--d, --differences
+-r, \--reverse
-: Highlight changes between updates. The diff specified by this flag is similar to the *watch* command. It can be changed later by key binding.
+: Display text upside down.
--N, --line-number
+-t, \--no-title
+
+: Hide the UI on start. Use `t` to toggle it.
+
+
+-N, \--line-number
: Show line number.
+\--no-help-banner
+
+: Hide the "Display help with h key" message
+
+
+-e, \--exec
+
+: Run the command directly, not through the shell. Much like the `-x` option of the watch command.
+
+
+-O, \--diff-output-only
+
+: Display only the lines with differences during `line` diff and `word` diff.
+
Options
-------
--n, --interval *seconds*
+-A, \--aftercommand *command to execute after difference occurs*
-: Specify update interval. The command will not allow quicker than **0.001** second interval, in which the smaller values are converted. Both '.' and ',' work for any locales.
+: Executes the specified command if the output changes. Information about changes is stored in json format in environment variable `${HWATCH_DATA}`.
--l, --logfile *logfile*
+-l, \--logfile *logfile*
: Output the command execution result and its time as a log in json. The execution results that are recorded are only those that differ from the previous execution results.
+-s, \--shell *shell command*
+
+: shell to use at runtime. can also insert the command to the location specified by {COMMAND}.
+
+
+-n, \--interval *seconds*
+
+: Specify update interval. The command will not allow quicker than **0.001** second interval, in which the smaller values are converted. Both '.' and ',' work for any locales.
+
+
+\--tab-size *num*
+
+: Specifying tab display size. default 4 char.
+
+
+-d, \--differences *[none, watch, line, word]*
+
+: set diff mode. highlight changes between updates. If only `-d` is specified, it will be a watch diff.
+
+ *plane* ... Do not show diff (default).
+
+ *watch* ... Diff like watch command. Specifying the *-d* option applies this mode.
+
+ *line* ... Can be done diff in line units.
+
+ *word* ... Can be done diff in line word units.
+
+
+
+-o, \--output *[output, stdout, stderr]*
+
+: set output mode. If you specify the output mode, the history pane will also display only the history where the specified output mode has changed.
+
+
+Configuration
+-------
+
+If you always want to use some command-line options, you can set them in the
+`HWATCH` environment variable. For example, if you use `bash`, you can add
+the following to your `.bashrc`:
+
+```bash
+export HWATCH="--no-title --color --no-help-banner"
+```
+
+
KEYBINDS
========
@@ -83,6 +163,16 @@ c
: Interprets ANSI colors and style sequences and displays them in color. This is the same as the *-c(--color)* option. Press the *c* key again to return to the original.
+n
+
+: Outputs the line number at the beginning of the line.
+
+
+r
+
+: Displays the output of the watch pane in reverse order.
+
+
d
: Highlight changes between updates. The diff specified by this flag is similar to the *watch* command. This is the same as the *-d(--differences)* option. You can switch the diff mode by pressing the *d* key. The *d* key toggles these in order. Use the *0*, *1*, and *2* keys to switch directly to each mode.
@@ -96,6 +186,31 @@ d
*word* ... Can be done diff in line word units.
+o
+
+: Switch output mode at stdout, stderr, and output. If you specify the output mode, the history pane will also display only the history where the specified output mode has changed.
+
+
+O
+
+: Display only the lines with differences during `line` diff and `word` diff.
+
+
+t
+
+: Switch display of header and history pane.
+
+
+Backspace
+
+: Switch display of history pane.
+
+
+m
+
+: Switch Mouse wheel support mode. With this option, copying text with your terminal may be harder. Try holding the Shift key.
+
+
0
: Switch diff mode to *plane*.
@@ -130,13 +245,13 @@ F3
: Display *Stdout* and *Stderr*.
-+
+\+
-: Increase interval by .5 seconds.
+: Increase interval by 0.5 seconds.
--
+\-
-: Decrease interval by .5 seconds (As long as it's positive).
+: Decrease interval by 0.5 seconds (As long as it's positive).
Tab
diff --git a/src/app.rs b/src/app.rs
index 4512092..0ce695e 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -2,8 +2,6 @@
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
-// TODO: そろそろリファクタしたほうが良さそう(2024/03/26)
-
use crossbeam_channel::{Receiver, Sender};
// module
use crossterm::{
@@ -79,6 +77,9 @@ pub struct App<'a> {
///
line_number: bool,
+ ///
+ reverse: bool,
+
///
is_beep: bool,
@@ -176,6 +177,7 @@ impl<'a> App<'a> {
after_command: "".to_string(),
ansi_color: false,
line_number: false,
+ reverse: false,
show_history: true,
show_header: true,
@@ -473,6 +475,19 @@ impl<'a> App<'a> {
self.set_output_data(selected);
}
+ ///
+ pub fn set_reverse(&mut self, reverse: bool) {
+ self.reverse = reverse;
+
+ self.header_area.set_reverse(reverse);
+ self.header_area.update();
+
+ self.printer.set_reverse(reverse);
+
+ let selected = self.history_area.get_state_select();
+ self.set_output_data(selected);
+ }
+
///
pub fn set_tab_size(&mut self, tab_size: u16) {
self.tab_size = tab_size;
@@ -572,20 +587,6 @@ impl<'a> App<'a> {
let mut is_push = true;
if self.is_filtered {
- // @TODO: filterがうまく動いてないかも(ouput mode切り替えのやつ)
- // @TODO: 重複しているからあとでリファクタしたほうが良さそう
- // let result_text = &result.1.output.clone();
-
- // if is_regex {
- // let re = Regex::new(&self.filtered_text.clone()).unwrap();
- // let regex_match = re.is_match(result_text);
- // if !regex_match {
- // is_push = false;
- // }
- // } else if !result_text.contains(&self.filtered_text) {
- // is_push = false;
- // }
-
let result_text = match self.output_mode {
OutputMode::Output => result.1.output.clone(),
OutputMode::Stdout => result.1.stdout.clone(),
@@ -892,7 +893,7 @@ impl<'a> App<'a> {
state: KeyEventState::NONE,
}) => self.set_ansi_color(!self.ansi_color),
- // d
+ // d ... toggle diff mode.
Event::Key(KeyEvent {
code: KeyCode::Char('d'),
modifiers: KeyModifiers::NONE,
@@ -908,6 +909,14 @@ impl<'a> App<'a> {
state: KeyEventState::NONE,
}) => self.set_line_number(!self.line_number),
+ // r
+ Event::Key(KeyEvent {
+ code: KeyCode::Char('r'),
+ modifiers: KeyModifiers::NONE,
+ kind: KeyEventKind::Press,
+ state: KeyEventState::NONE,
+ }) => self.set_reverse(!self.reverse),
+
// o(lower o)
Event::Key(KeyEvent {
code: KeyCode::Char('o'),
@@ -1012,7 +1021,7 @@ impl<'a> App<'a> {
state: KeyEventState::NONE,
}) => self.set_input_mode(InputMode::Filter),
- // / ... Change Filter Mode(regex text).
+ // * ... Change Filter Mode(regex text).
Event::Key(KeyEvent {
code: KeyCode::Char('*'),
modifiers: KeyModifiers::NONE,
diff --git a/src/batch.rs b/src/batch.rs
index 28e11cd..bf8656c 100644
--- a/src/batch.rs
+++ b/src/batch.rs
@@ -25,6 +25,9 @@ pub struct Batch {
///
is_beep: bool,
+ ///
+ is_reverse: bool,
+
///
results: HashMap,
@@ -54,8 +57,8 @@ impl Batch {
after_command: "".to_string(),
line_number: false,
is_color: true,
- // is_color: false,
is_beep: false,
+ is_reverse: false,
results: HashMap::new(),
output_mode: OutputMode::Output,
diff_mode: DiffMode::Disable,
@@ -72,6 +75,7 @@ impl Batch {
.set_color(self.is_color)
.set_diff_mode(self.diff_mode)
.set_line_number(self.line_number)
+ .set_reverse(self.is_reverse)
.set_only_diffline(self.is_only_diffline)
.set_output_mode(self.output_mode);
@@ -187,6 +191,12 @@ impl Batch {
self
}
+ ///
+ pub fn set_reverse(mut self, is_reverse: bool) -> Self {
+ self.is_reverse = is_reverse;
+ self
+ }
+
///
pub fn set_output_mode(mut self, output_mode: OutputMode) -> Self {
self.output_mode = output_mode;
diff --git a/src/header.rs b/src/header.rs
index 3aea75f..92a0f0e 100644
--- a/src/header.rs
+++ b/src/header.rs
@@ -47,6 +47,9 @@ pub struct HeaderArea<'a> {
///
line_number: bool,
+ ///
+ reverse: bool,
+
///
ansi_color: bool,
@@ -90,6 +93,7 @@ impl<'a> HeaderArea<'a> {
data: vec![Line::from("")],
ansi_color: false,
line_number: false,
+ reverse: false,
banner: "".to_string(),
active_area: ActiveArea::History,
@@ -121,6 +125,10 @@ impl<'a> HeaderArea<'a> {
self.line_number = line_number;
}
+ pub fn set_reverse(&mut self, reverse: bool) {
+ self.reverse = reverse;
+ }
+
pub fn set_banner(&mut self, banner: String) {
self.banner = banner;
}
@@ -151,6 +159,7 @@ impl<'a> HeaderArea<'a> {
self.input_mode = input_mode;
}
+ ///
pub fn update(&mut self) {
// init data
self.data = vec![];
@@ -171,7 +180,10 @@ impl<'a> HeaderArea<'a> {
// filter keyword.
let filter_keyword_width = if width > (POSITION_X_HELP_TEXT + 2 + 14) {
- width - POSITION_X_HELP_TEXT - 2 - 14
+ // width - POSITION_X_HELP_TEXT - 2 - 14
+ // length("[Number] [Color] [Output] [history] [Line(Only)]") = 48
+ // length("[Number] [Color] [Reverse] [Output] [history] [Line(Only)]") = 58
+ width - 58
} else {
0
};
@@ -196,7 +208,7 @@ impl<'a> HeaderArea<'a> {
// Get the data to display at header.
let interval = format!("{:.3}", self.interval);
- // Set number flag value
+ // Set Number flag value
let value_number: Span = match self.line_number {
true => Span::styled(
"Number".to_string(),
@@ -220,7 +232,19 @@ impl<'a> HeaderArea<'a> {
false => Span::styled("Color".to_string(), Style::default().fg(Color::Reset)),
};
- // Set output type value
+ // Set Reverse flag value
+ let value_reverse: Span = match self.reverse {
+ true => Span::styled(
+ "Reverse".to_string(),
+ Style::default()
+ .fg(Color::Green)
+ .add_modifier(Modifier::REVERSED)
+ .add_modifier(Modifier::BOLD),
+ ),
+ false => Span::styled("Reverse".to_string(), Style::default().fg(Color::Reset)),
+ };
+
+ // Set Output type value
let value_output = match self.output_mode {
OutputMode::Output => "Output".to_string(),
OutputMode::Stdout => "Stdout".to_string(),
@@ -229,8 +253,8 @@ impl<'a> HeaderArea<'a> {
// Set Active Area value
let value_active = match self.active_area {
- ActiveArea::History => "history".to_string(),
- ActiveArea::Watch => "watch".to_string(),
+ ActiveArea::History => "History".to_string(),
+ ActiveArea::Watch => "Watch".to_string(),
};
// Set IsOnlyDiffline value
@@ -287,9 +311,14 @@ impl<'a> HeaderArea<'a> {
value_color,
Span::raw("]"),
Span::raw(" "),
+ // Reverse flag
+ Span::raw("["),
+ value_reverse,
+ Span::raw("]"),
+ Span::raw(" "),
// Output Type
Span::raw("["),
- Span::styled("Output:", Style::default().add_modifier(Modifier::BOLD)),
+ // Span::styled("Output:", Style::default().add_modifier(Modifier::BOLD)),
Span::styled(
format!("{:wid$}", value_output, wid = 6),
Style::default()
@@ -300,7 +329,7 @@ impl<'a> HeaderArea<'a> {
Span::raw(" "),
// Active Area
Span::raw("["),
- Span::styled("Active: ", Style::default().add_modifier(Modifier::BOLD)),
+ // Span::styled("Active:", Style::default().add_modifier(Modifier::BOLD)),
Span::styled(
format!("{:wid$}", value_active, wid = 7),
Style::default()
@@ -311,7 +340,7 @@ impl<'a> HeaderArea<'a> {
Span::raw(" "),
// Diff Type
Span::raw("["),
- Span::styled("Diff: ", Style::default().add_modifier(Modifier::BOLD)),
+ // Span::styled("Diff: ", Style::default().add_modifier(Modifier::BOLD)),
Span::styled(
format!("{:wid$}", value_diff, wid = 10),
Style::default()
@@ -322,6 +351,7 @@ impl<'a> HeaderArea<'a> {
]));
}
+ ///
pub fn draw(&mut self, frame: &mut Frame) {
let block = Paragraph::new(self.data.clone());
frame.render_widget(block, self.area);
diff --git a/src/help.rs b/src/help.rs
index fb7cf98..1aa3a53 100644
--- a/src/help.rs
+++ b/src/help.rs
@@ -127,10 +127,14 @@ fn gen_help_text_from_key_data<'a>(data: Vec) -> Vec> {
fn gen_help_text<'a>() -> Vec> {
let keydata_list = vec![
KeyData { key: "h".to_string(), description: "show this help message.".to_string() },
+ KeyData { key: "q".to_string(), description: "exit.".to_string() },
// toggle
KeyData { key: "c".to_string(), description: "toggle color mode.".to_string() },
KeyData { key: "n".to_string(), description: "toggle line number.".to_string() },
+ KeyData { key: "r".to_string(), description: "toggle reverse mode.".to_string() },
KeyData { key: "d".to_string(), description: "switch diff mode at None, Watch, Line, and Word mode.".to_string() },
+ KeyData { key: "o".to_string(), description: "switch output mode at stdout, stderr, and output.".to_string() },
+ KeyData { key: "O".to_string(), description: "toggle change only the lines with differences during `line` diff and `word` diff.".to_string() },
KeyData { key: "t".to_string(), description: "toggle ui (history pane & header both on/off).".to_string() },
KeyData { key: "Bkspace".to_string(), description: "toggle history pane.".to_string() },
KeyData { key: "m".to_string(), description: "toggle mouse wheel support. With this option, copying text with your terminal may be harder. Try holding the Shift key.".to_string() },
diff --git a/src/main.rs b/src/main.rs
index 14b9de0..6663292 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,34 +2,36 @@
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
-// v0.3.12
-// TODO(blakcnon): batch modeの実装.(clapのバージョンをあげてから、diff等のオプションを指定できるようにしたほうがいいのかも??)
-// TODO(blacknon): word diffでremove行のワードがハイライト表示されないので、原因を調べる.
+// v0.3.14
+// TODO(blacknon): キー入力のカスタマイズが行えるようにする(custom keymap)
-// v0.3.13
-// TODO(blacknon): 任意時点間のdiffが行えるようにする.
-// TODO(blacknon): filtering時に、`指定したキーワードで差分が発生した場合のみ`を対象にするような機能にする
+// v0.3.15
+// TODO(blacknon): 終了時にYes/Noで確認を取る機能を実装する(オプションで無効化させる)
// TODO(blacknon): コマンドが終了していなくても、インターバル間隔でコマンドを実行する
// (パラレルで実行してもよいコマンドじゃないといけないよ、という機能か。投げっぱなしにしてintervalで待つようにするオプションを付ける)
+
+// v0.3.16
+// TODO(blacknon): https://github.com/blacknon/hwatch/issues/101
+// - ログを読み込ませて、そのまま続きの処理を行わせる機能の追加
+
+// v1.0.0
+// TODO(blacknon): vimのように内部コマンドを利用した表示切り替え・出力結果の編集機能を追加する
+// TODO(blacknon): 任意時点間のdiffが行えるようにする.
+// TODO(blacknon): filtering時に、`指定したキーワードで差分が発生した場合のみ`を対象にするような機能にする
// TODO(blacknon): Rustのドキュメンテーションコメントを追加していく
// TODO(blacknon): マニュアル(manのデータ)を自動作成させる
// https://github.com/rust-cli/man
-// TODO(blacknon): errorとの比較を行わない(正常終了時のみを比較対象とし、errorの履歴をスキップしてdiffする)キーバインドの追加(なんかのmode?)
-// => outputごとに分離して比較できる仕組みにする方式で対処?
// TODO(blacknon): ライフタイムの名称をちゃんと命名する。
// TODO(blacknon): エラーなどのメッセージ表示領域の作成
// TODO(blacknon): diffのライブラリをsimilarに切り替える?
// - https://github.com/mitsuhiko/similar
// - 目的としては、複数文字を区切り文字指定して差分のある箇所をもっとうまく抽出できるようにしてやりたい、というもの
// - diffのとき、スペースの増減は無視するようなオプションがほしい(あるか?というのは置いといて…)
-// TODO(blacknon): diffのとき、stdout/stderrでの比較時におけるdiffでhistoryも変化させる?
-// - データの扱いが変わってきそう?
-// - どっちにしてもデータがあるなら、stdout/stderrのとこだけで比較するような何かがあればいい???
-// TODO(blacknon): キー入力のカスタマイズが行えるようにする
+
// crate
// extern crate ansi_parser;
-extern crate hwatch_ansi_parser as ansi_parser;
+extern crate ansi_parser;
extern crate ansi_term;
extern crate async_std;
extern crate chrono;
@@ -162,6 +164,15 @@ fn build_app() -> clap::Command {
.short('c')
.action(ArgAction::SetTrue)
.long("color"),
+ )
+ // Enable Reverse mode option
+ // [-r,--reverse]
+ .arg(
+ Arg::new("reverse")
+ .help("display text upside down.")
+ .short('r')
+ .action(ArgAction::SetTrue)
+ .long("reverse"),
)
// exec flag.
// [--no-title]
@@ -203,7 +214,7 @@ fn build_app() -> clap::Command {
// [-O,--diff-output-only]
.arg(
Arg::new("diff_output_only")
- .help("Display only the lines with differences during line diff and word diff.")
+ .help("Display only the lines with differences during `line` diff and `word` diff.")
.short('O')
.long("diff-output-only")
.requires("differences")
@@ -427,6 +438,9 @@ fn main() {
// Set line number in view
.set_line_number(matcher.get_flag("line_number"))
+ // Set reverse mode in view
+ .set_reverse(matcher.get_flag("reverse"))
+
// Set output in view
.set_output_mode(output_mode)
@@ -456,6 +470,7 @@ fn main() {
.set_output_mode(output_mode)
.set_diff_mode(diff_mode)
.set_line_number(matcher.get_flag("line_number"))
+ .set_reverse(matcher.get_flag("reverse"))
.set_only_diffline(matcher.get_flag("diff_output_only"));
// Set after_command
diff --git a/src/output.rs b/src/output.rs
index 8929602..8aa0ebe 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -118,6 +118,9 @@ pub struct Printer {
// line number.
is_line_number: bool,
+ // is reverse text.
+ is_reverse: bool,
+
// is filtered text.
is_filter: bool,
@@ -142,6 +145,7 @@ impl Printer {
is_batch: false,
is_color: false,
is_line_number: false,
+ is_reverse: false,
is_filter: false,
is_regex_filter: false,
filter_text: "".to_string(),
@@ -173,7 +177,11 @@ impl Printer {
DiffMode::Word => self.gen_word_diff_output(&text_dest, &text_src),
};
- if let PrintData::Lines(result) = data {
+ if let PrintData::Lines(mut result) = data {
+ // if is_reverse enable, flip upside down to result.
+ if self.is_reverse {
+ result.reverse();
+ }
return result;
} else {
return vec![];
@@ -208,7 +216,11 @@ impl Printer {
DiffMode::Word => self.gen_word_diff_output(&text_dest, &text_src),
};
- if let PrintData::Strings(result) = data {
+ if let PrintData::Strings(mut result) = data {
+ // if is_reverse enable, flip upside down to result.
+ if self.is_reverse {
+ result.reverse();
+ }
return result;
} else {
return vec![];
@@ -1521,6 +1533,12 @@ impl Printer {
self
}
+ // set is reverse.
+ pub fn set_reverse(&mut self, is_reverse: bool) -> &mut Self {
+ self.is_reverse = is_reverse;
+ self
+ }
+
/// set is_filter.
pub fn set_filter(&mut self, is_filter: bool) -> &mut Self {
self.is_filter = is_filter;
diff --git a/src/view.rs b/src/view.rs
index 20c9b86..e7e6858 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -37,6 +37,7 @@ pub struct View {
show_ui: bool,
show_help_banner: bool,
line_number: bool,
+ reverse: bool,
output_mode: OutputMode,
diff_mode: DiffMode,
is_only_diffline: bool,
@@ -56,6 +57,7 @@ impl View {
show_ui: true,
show_help_banner: true,
line_number: false,
+ reverse: false,
output_mode: OutputMode::Output,
diff_mode: DiffMode::Disable,
is_only_diffline: false,
@@ -108,6 +110,11 @@ impl View {
self
}
+ pub fn set_reverse(mut self, reverse: bool) -> Self {
+ self.reverse = reverse;
+ self
+ }
+
pub fn set_output_mode(mut self, output_mode: OutputMode) -> Self {
self.output_mode = output_mode;
self
@@ -182,6 +189,9 @@ impl View {
// set line_number
app.set_line_number(self.line_number);
+ // set reverse
+ app.set_reverse(self.reverse);
+
// set output mode
app.set_output_mode(self.output_mode);