Skip to content

Commit

Permalink
aesthetic changes to the binref command
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Nov 26, 2024
1 parent b5def68 commit e53238e
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions refinery/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from refinery.lib.tools import documentation, terminalfit, get_terminal_size
from refinery.units import ArgparseError
from refinery.lib.argparser import LineWrapRawTextHelpFormatter
from refinery.lib.argparser import RawDescriptionHelpFormatter

import refinery

Expand Down Expand Up @@ -50,7 +50,8 @@ def get_help_string(unit, brief=False, width=None):
buffer = StringIO('w')
argp.print_help(buffer)
info = buffer.getvalue()
return info
info, _, _ = info.partition('\ngeneric options:\n')
return info.strip()
finally:
environment.term_size.value = _ts

Expand All @@ -76,11 +77,8 @@ def explorer(keyword_color='91', unit_color='93'):
R' binary refinery \/ full text search ' '\n'
)

headline = highlight_word(headline, 'keyword', keyword_color)
headline = highlight_word(headline, 'unit', unit_color)
print(headline)

argp = argparse.ArgumentParser(formatter_class=LineWrapRawTextHelpFormatter)
argp = argparse.ArgumentParser(
formatter_class=RawDescriptionHelpFormatter, description=headline)

argp.add_argument(
'keywords',
Expand All @@ -90,15 +88,6 @@ def explorer(keyword_color='91', unit_color='93'):
help='Provide keywords; if any of these keywords match the help description of '
'a unit, it will be listed.'
)
argp.add_argument(
'-T', '--columns',
dest='terminal_width',
metavar='N',
type=int,
default=80,
help='Set the terminal width to N characters, the default is 80 characters. '
'Setting the width to zero (-T0) will use the full terminal width.'
)
argp.add_argument(
'-I', '--conjunctive',
dest='quantifier',
Expand All @@ -108,9 +97,9 @@ def explorer(keyword_color='91', unit_color='93'):
help='All keywords must match rather than any of them.'
)
argp.add_argument(
'-b', '--brief',
'-a', '--all',
action='store_true',
help='Only search and display unit descriptions, not the full help output'
help='Search full help output (not just unit descriptions).'
)
argp.add_argument(
'-c', '--case-sensitive',
Expand All @@ -134,7 +123,7 @@ def explorer(keyword_color='91', unit_color='93'):
help='Do not allow wildcards in search string'
)
args = argp.parse_args()
width = args.terminal_width or get_terminal_size()
width = get_terminal_size()
separator = '-' * width
result = False

Expand Down Expand Up @@ -162,7 +151,7 @@ def pattern(keyword):
except TypeError:
continue

info = get_help_string(unit, args.brief, width)
info = get_help_string(unit, not args.all, width)

if not args.quantifier(k.search(name) or k.search(info) for k in args.keywords):
continue
Expand All @@ -172,7 +161,7 @@ def pattern(keyword):
for kw in args.keywords:
info = highlight(info, kw, keyword_color)

if args.brief:
if not args.all:
header = '{e:-<4}[{}]{e:-<{w}}'.format(name, w=width - len(name) - 6, e='')
header = highlight_word(header, name, unit_color)
else:
Expand Down

0 comments on commit e53238e

Please sign in to comment.