Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --instant to show only the instant answer #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ddgr
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ class DdgCmd:
if self.colors:
print(self.colors.reset, end='')

if self._opts.reverse:
if self._opts.reverse or self._opts.instant:
print('')

@require_keywords
Expand Down Expand Up @@ -2025,6 +2025,7 @@ def parse_args(args=None, namespace=None):
addarg('--colors', dest='colorstr', type=argparser.is_colorstr, default=colorstr_env if colorstr_env else 'oCdgxy', metavar='COLORS',
help='set output colors (see man page for details)')
addarg('-j', '--ducky', action='store_true', help='open the first result in a web browser; implies --np')
addarg('-i', '--instant', action='store_true', help='show only the instant answer')
addarg('-t', '--time', dest='duration', metavar='SPAN', default='', choices=('d', 'w', 'm', 'y'), help='time limit search '
'[d (1 day), w (1 wk), m (1 month), y (1 year)]')
addarg('-w', '--site', dest='sites', action='append', metavar='SITE', help='search sites using DuckDuckGo')
Expand Down Expand Up @@ -2094,7 +2095,7 @@ def main():
try:
repl = DdgCmd(opts, '' if opts.noua else USER_AGENT)

if opts.json or opts.ducky or opts.noninteractive:
if opts.json or opts.ducky or opts.noninteractive or opts.instant:
# Non-interactive mode
if repl.keywords and (
repl.keywords[0][0] == '!' or
Expand All @@ -2109,6 +2110,8 @@ def main():
open_url(repl.results[0].url)
else:
print('No results.', file=sys.stderr)
elif opts.instant:
repl.display_instant_answer(json_output=opts.json)
else:
if not opts.reverse:
repl.display_instant_answer(json_output=opts.json)
Expand Down