Skip to content

Commit

Permalink
shell: Fix pager support
Browse files Browse the repository at this point in the history
Change the "pager" setting to a boolean enabling or disabling pager
support. If the $PAGER environment variable is set, output to be paged
is piped to the specified program. Otherwise "more" is used. The pager
is used only for interactive invocations of bean-query.

Fixes #198.
  • Loading branch information
dnicolodi committed Oct 5, 2024
1 parent c95133a commit 3992294
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions beanquery/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Settings:
narrow: bool = True
nullvalue: str = ''
numberify: bool = False
pager: str = ''
pager: bool = True
spaced: bool = False
unicode: bool = False

Expand Down Expand Up @@ -207,17 +207,6 @@ def add_help(self):
lambda _, fun=func: print(textwrap.dedent(fun.__doc__).strip(),
file=self.outfile))

def get_pager(self):
"""Create and return a context manager to write to, a pager subprocess if required.
Returns:
A context manager.
"""
if self.interactive:
return pager.ConditionalPager(self.settings.pager, minlines=get_screen_height())
return pager.flush_only(sys.stdout)

@property
def output(self):
"""Where to direct command output.
Expand All @@ -232,7 +221,9 @@ def output(self):
"""
if self.outfile is sys.stdout:
return self.get_pager()
if self.interactive and self.settings.pager:
return pager.ConditionalPager(None, minlines=get_screen_height())
return pager.flush_only(sys.stdout)
return nullcontext(self.outfile)

def cmdloop(self, intro=None):
Expand Down

0 comments on commit 3992294

Please sign in to comment.