ndmitchell / hoogle

Haskell API search engine
http://hoogle.haskell.org/
Other
731 stars 131 forks source link

Support hyperlinks in search output #401

Open avdv opened 1 year ago

avdv commented 1 year ago

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.

ndmitchell commented 1 year ago

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?

avdv commented 1 year ago

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?