@@ -11,6 +11,7 @@ use crate::event::AppEvent;
1111use crate :: exec:: { exec_after_command, CommandResult } ;
1212use crate :: output;
1313use crate :: DiffModeRef ;
14+ use crate :: DiffModeRef ;
1415
1516use hwatch_diffmode:: text_eq_ignoring_space_blocks;
1617
@@ -32,67 +33,89 @@ impl DecodedCommandResult {
3233
3334/// Struct at watch view window.
3435pub struct Batch {
36+ // Command executed after a change is detected.
3537 // Command executed after a change is detected.
3638 after_command : String ,
3739
40+ // Shell used to execute the after-command hook.
3841 // Shell used to execute the after-command hook.
3942 after_command_shell_command : String ,
4043
44+ // Whether hook payloads are written to a temp file first.
4145 // Whether hook payloads are written to a temp file first.
4246 after_command_result_write_file : bool ,
4347
48+ // Whether to print line numbers in diff output.
4449 // Whether to print line numbers in diff output.
4550 line_number : bool ,
4651
52+ // Whether ANSI color output should be preserved.
4753 // Whether ANSI color output should be preserved.
4854 is_color : bool ,
4955
56+ // Whether to beep when output changes.
5057 // Whether to beep when output changes.
5158 is_beep : bool ,
5259
60+ // Remaining change count before exiting, if enabled.
5361 // Remaining change count before exiting, if enabled.
5462 exit_on_change : Option < u32 > ,
5563
64+ // Prevents the first observed result from counting as a change.
5665 // Prevents the first observed result from counting as a change.
5766 exit_on_change_armed : bool ,
5867
68+ // Whether batch output should be reversed.
5969 // Whether batch output should be reversed.
6070 is_reverse : bool ,
6171
72+ // Accumulated command history for batch mode.
6273 // Accumulated command history for batch mode.
6374 results : HashMap < usize , CommandResult > ,
6475
76+ // Selected output stream to compare and print.
6577 // Selected output stream to compare and print.
6678 output_mode : OutputMode ,
6779
80+ // Selected diff mode index.
6881 // Selected diff mode index.
6982 diff_mode : usize ,
7083
84+ // Available diff mode implementations.
85+ diff_modes : Vec < DiffModeRef > ,
7186 // Available diff mode implementations.
7287 diff_modes : Vec < DiffModeRef > ,
7388
89+ // Whether only changed lines should be shown.
7490 // Whether only changed lines should be shown.
7591 is_only_diffline : bool ,
7692
93+ // Whether whitespace-only block changes should be ignored.
7794 // Whether whitespace-only block changes should be ignored.
7895 ignore_spaceblock : bool ,
7996
97+ // Optional logfile path for persisted history.
8098 // Optional logfile path for persisted history.
8199 logfile : String ,
82100
101+ // Shared rendering helper for batch output.
83102 // Shared rendering helper for batch output.
84103 printer : output:: Printer ,
85104
105+ // Receives command execution events from the runner thread.
86106 // Receives command execution events from the runner thread.
87107 pub rx : Receiver < AppEvent > ,
88108}
89109
90110impl Batch {
111+ // Creates batch-mode application state.
112+ pub fn new ( rx : Receiver < AppEvent > , diff_modes : Vec < DiffModeRef > ) -> Self {
91113 // Creates batch-mode application state.
92114 pub fn new ( rx : Receiver < AppEvent > , diff_modes : Vec < DiffModeRef > ) -> Self {
93115 // Create Default DiffMode
94116 let diff_mode_counter = 0 ;
95117 let diff_mode_ref = diff_modes[ diff_mode_counter] . clone ( ) ;
118+ let diff_mode_ref = diff_modes[ diff_mode_counter] . clone ( ) ;
96119
97120 Self {
98121 after_command : "" . to_string ( ) ,
@@ -112,6 +135,7 @@ impl Batch {
112135 ignore_spaceblock : false ,
113136 logfile : "" . to_string ( ) ,
114137 printer : output:: Printer :: new ( diff_mode_ref) ,
138+ printer : output:: Printer :: new ( diff_mode_ref) ,
115139 rx,
116140 }
117141 }
@@ -155,6 +179,7 @@ impl Batch {
155179 }
156180 }
157181
182+ // Processes a new command result and prints when the selected stream changes.
158183 // Processes a new command result and prints when the selected stream changes.
159184 fn update_result ( & mut self , _result : CommandResult ) -> bool {
160185 // check results size.
@@ -332,12 +357,14 @@ impl Batch {
332357 self
333358 }
334359
360+ // Enables or disables whitespace-block normalization in comparisons.
335361 // Enables or disables whitespace-block normalization in comparisons.
336362 pub fn set_ignore_spaceblock ( mut self , ignore_spaceblock : bool ) -> Self {
337363 self . ignore_spaceblock = ignore_spaceblock;
338364 self
339365 }
340366
367+ // Sets the logfile path used for persisted history.
341368 // Sets the logfile path used for persisted history.
342369 pub fn set_logfile ( mut self , logfile : String ) -> Self {
343370 self . logfile = logfile;
@@ -364,6 +391,9 @@ impl Batch {
364391 * remaining -= 1 ;
365392 }
366393 * remaining == 0
394+ } else {
395+ false
396+ * remaining == 0
367397 } else {
368398 false
369399 }
@@ -410,6 +440,9 @@ mod tests {
410440 let diff_modes: Vec < DiffModeRef > = vec ! [ std:: rc:: Rc :: new( std:: cell:: RefCell :: new(
411441 Box :: new( DiffModeAtPlane :: new( ) ) ,
412442 ) ) ] ;
443+ let diff_modes: Vec < DiffModeRef > = vec ! [ std:: rc:: Rc :: new( std:: cell:: RefCell :: new(
444+ Box :: new( DiffModeAtPlane :: new( ) ) ,
445+ ) ) ] ;
413446
414447 Batch :: new ( rx, diff_modes) . set_output_mode ( output_mode)
415448 }
0 commit comments