5
5
import sys
6
6
from typing import Iterable , Iterator , List , Optional , Text , Tuple
7
7
8
+ from rich .console import Console # type: ignore
9
+
8
10
from . import __version__
9
11
from .color import color_unified_diff_line
10
12
from .diff import external_diff , u_diff
@@ -105,6 +107,9 @@ def run(argv: List[Text]) -> None:
105
107
#
106
108
# /////////////////////////////////////////////////////////
107
109
110
+ # instantiate a rich Console
111
+ console = Console ()
112
+
108
113
# parse explicitly included or excluded tables in
109
114
# the command line arguments
110
115
# set as a Python list if it was defined on the command line
@@ -137,24 +142,25 @@ def run(argv: List[Text]) -> None:
137
142
sys .exit (1 )
138
143
139
144
try :
140
- ext_diff : Iterable [Tuple [Text , Optional [int ]]] = external_diff (
141
- args .external ,
142
- args .PREFILE ,
143
- args .POSTFILE ,
144
- include_tables = include_list ,
145
- exclude_tables = exclude_list ,
146
- use_multiprocess = use_mp ,
147
- )
148
-
149
- # write stdout from external tool
150
- for line , exit_code in ext_diff :
151
- # format with color if color flag is entered on command line
152
- if args .color :
153
- sys .stdout .write (color_unified_diff_line (line ))
154
- else :
155
- sys .stdout .write (line )
156
- if exit_code is not None :
157
- sys .exit (exit_code )
145
+ with console .status ("Processing..." , spinner = "dots10" ):
146
+ ext_diff : Iterable [Tuple [Text , Optional [int ]]] = external_diff (
147
+ args .external ,
148
+ args .PREFILE ,
149
+ args .POSTFILE ,
150
+ include_tables = include_list ,
151
+ exclude_tables = exclude_list ,
152
+ use_multiprocess = use_mp ,
153
+ )
154
+
155
+ # write stdout from external tool
156
+ for line , exit_code in ext_diff :
157
+ # format with color if color flag is entered on command line
158
+ if args .color :
159
+ sys .stdout .write (color_unified_diff_line (line ))
160
+ else :
161
+ sys .stdout .write (line )
162
+ if exit_code is not None :
163
+ sys .exit (exit_code )
158
164
except Exception as e :
159
165
sys .stderr .write (f"[*] ERROR: { e } { os .linesep } " )
160
166
sys .exit (1 )
@@ -163,38 +169,39 @@ def run(argv: List[Text]) -> None:
163
169
# Unified diff
164
170
# ---------------
165
171
# perform the unified diff analysis
166
- try :
167
- uni_diff : Iterator [Text ] = u_diff (
168
- args .PREFILE ,
169
- args .POSTFILE ,
170
- context_lines = args .lines ,
171
- include_tables = include_list ,
172
- exclude_tables = exclude_list ,
173
- use_multiprocess = use_mp ,
174
- )
175
- except Exception as e :
176
- sys .stderr .write (f"[*] ERROR: { e } { os .linesep } " )
177
- sys .exit (1 )
178
-
179
- # re-define the line contents of the diff iterable
180
- # if head or tail is requested
181
- if args .head :
182
- iterable = head (uni_diff , args .head )
183
- elif args .tail :
184
- iterable = tail (uni_diff , args .tail )
185
- else :
186
- iterable = uni_diff
187
-
188
- # print unified diff results to standard output stream
189
- has_diff = False
190
- if args .color :
191
- for line in iterable :
192
- has_diff = True
193
- sys .stdout .write (color_unified_diff_line (line ))
194
- else :
195
- for line in iterable :
196
- has_diff = True
197
- sys .stdout .write (line )
172
+ with console .status ("Processing..." , spinner = "dots10" ):
173
+ try :
174
+ uni_diff : Iterator [Text ] = u_diff (
175
+ args .PREFILE ,
176
+ args .POSTFILE ,
177
+ context_lines = args .lines ,
178
+ include_tables = include_list ,
179
+ exclude_tables = exclude_list ,
180
+ use_multiprocess = use_mp ,
181
+ )
182
+ except Exception as e :
183
+ sys .stderr .write (f"[*] ERROR: { e } { os .linesep } " )
184
+ sys .exit (1 )
185
+
186
+ # re-define the line contents of the diff iterable
187
+ # if head or tail is requested
188
+ if args .head :
189
+ iterable = head (uni_diff , args .head )
190
+ elif args .tail :
191
+ iterable = tail (uni_diff , args .tail )
192
+ else :
193
+ iterable = uni_diff
194
+
195
+ # print unified diff results to standard output stream
196
+ has_diff = False
197
+ if args .color :
198
+ for line in iterable :
199
+ has_diff = True
200
+ sys .stdout .write (color_unified_diff_line (line ))
201
+ else :
202
+ for line in iterable :
203
+ has_diff = True
204
+ sys .stdout .write (line )
198
205
199
206
# if no difference was found, tell the user instead of
200
207
# simply closing with zero exit status code.
0 commit comments