Skip to content

Commit

Permalink
ptig - errors in color
Browse files Browse the repository at this point in the history
  • Loading branch information
clach04 committed Dec 1, 2023
1 parent 189dc6e commit 1875f5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions puren_tonbo/tools/ptgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

if colorama:
# TODO options for these? These are close facimiles to ripgrep default
color_error = colorama.Fore.RED # Background instead?
color_filename = colorama.Fore.BLUE
color_linenum = colorama.Fore.GREEN
color_searchhit = colorama.Fore.RED
Expand All @@ -54,6 +55,7 @@
# might be linux (not Windows)
if not is_win:
# ansi color escape sequences
color_error = '\x1b[31m' # Fore.RED
color_filename = '\x1b[01;34m' # Fore.BLUE
color_linenum = '\x1b[01;32m' # Fore.GREEN
#color_searchhit = '\x1b[01;05;37;41m' # Background Red, foreground flasshing white
Expand Down
11 changes: 8 additions & 3 deletions puren_tonbo/tools/ptig.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,16 @@ def do_cat(self, line=None):
else:
print('%s' % data) # TODO bytes instead of string? -- or simply refactor ptcat and call that....
except (puren_tonbo.PurenTonboIO, puren_tonbo.UnsupportedFile) as info:
# TODO color support?
print('Error opening file %r' % info)
message = 'Error opening file %r' % info
if self.grep_options.use_color:
message = ptgrep.color_error + message + ptgrep.color_reset
print('%s' % message)
except KeyboardInterrupt:
# TODO color support?
print('search cancelled')
message = 'search cancelled'
if self.grep_options.use_color:
message = ptgrep.color_error + message + ptgrep.color_reset
print('%s' % message)

do_c = do_cat # shortcut to save typing
do_type = do_cat # Windows alias
Expand Down

0 comments on commit 1875f5c

Please sign in to comment.