hoogle icon indicating copy to clipboard operation
hoogle copied to clipboard

Support hyperlinks in search output

Open avdv opened this issue 3 years ago • 2 comments

Add --hyperlink flag to search sub command which outputs ANSI escape sequences that supporting terminal emulators can leverage to show hyperlinked text.

Rendered help text:

cabal-install -- run -- hoogle search --help
Up to date
Hoogle 5.0.18.3, https://hoogle.haskell.org/

hoogle [search] [OPTIONS] [QUERY]
  Perform a search

Flags:
     --colour --color   Use colored output (requires ANSI terminal)
     --json             Get result as JSON
     --jsonl            Get result as JSONL (JSON Lines)
  -l --link             Give URL's for each result
  -h --hyperlink        Hyperlink results with ANSI escape sequences
...

The effect depends on the terminal emulator used; I am using kitty and it underlines hyperlinked text with a squiggly line. A simple left click opens the default application for the link: 2023-03-12_15-59

See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda for more info.

avdv avatar Mar 12 '23 15:03 avdv

Thanks for the diff. What does this flag do on terminals that don't support it? I'm wondering if the answer is there is nothing harmful, we could just always emit the hyperlink if we are emitting ANSI codes anyway and not even have a flag?

ndmitchell avatar Mar 13 '23 10:03 ndmitchell

Yes, a terminal emulator should just ignore ANSI escape sequences it does not recognize / support.

But when does hoogle emit ANSI codes? From a quick look, it never does that. E.g. the --color / --colour flag seems to have no effect (I couldn't find any usage of color in the code base except in CmdLine.hs).

And the CI seems to fail for an unrelated reason. Or do I have to update copyright years maybe?

avdv avatar Mar 13 '23 14:03 avdv