Skip to content

Support hyperlinks in search output #401

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion hoogle.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license-file: LICENSE
category: Development
author: Neil Mitchell <[email protected]>
maintainer: Neil Mitchell <[email protected]>
copyright: Neil Mitchell 2004-2022
copyright: Neil Mitchell 2004-2023
synopsis: Haskell API Search
description:
Hoogle is a Haskell API search engine, which allows you to
Expand Down
2 changes: 2 additions & 0 deletions src/Action/CmdLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data CmdLine
,json :: Bool
,jsonl :: Bool
,link :: Bool
,hyperlink :: Bool
,numbers :: Bool
,info :: Bool
,database :: FilePath
Expand Down Expand Up @@ -114,6 +115,7 @@ search_ = Search
,json = def &= name "json" &= help "Get result as JSON"
,jsonl = def &= name "jsonl" &= help "Get result as JSONL (JSON Lines)"
,link = def &= help "Give URL's for each result"
,hyperlink = def &= help "Hyperlink results with ANSI escape sequences"
,numbers = def &= help "Give counter for each result"
,info = def &= help "Give extended information about the first result"
,database = def &= typFile &= help "Name of database to use (use .hoo extension)"
Expand Down
10 changes: 6 additions & 4 deletions src/Action/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ actionSearch Search{..} = replicateM_ repeat_ $ -- deliberately reopen the datab
count' <- pure $ fromMaybe 10 count
(q, res) <- pure $ search store $ parseQuery $ unwords query
whenLoud $ putStrLn $ "Query: " ++ unescapeHTML (LBS.unpack $ renderMarkup $ renderQuery q)
let (shown, hidden) = splitAt count' $ nubOrd $ map (targetResultDisplay link) res
let (shown, hidden) = splitAt count' $ nubOrd $ map (targetResultDisplay link hyperlink) res
if null res then
putStrLn "No results found"
else if info then do
Expand Down Expand Up @@ -71,11 +71,13 @@ targetInfo Target{..} =

-- | Returns the Target formatted as an item to display in the results
-- | Bool argument decides whether links are shown
targetResultDisplay :: Bool -> Target -> String
targetResultDisplay link Target{..} = unHTML $ unwords $
targetResultDisplay :: Bool -> Bool -> Target -> String
targetResultDisplay link hyperlink Target{..} = unHTML $ unwords $
map fst (maybeToList targetModule) ++
[targetItem] ++
[if hyperlink then targetItemHyperlink else targetItem] ++
["-- " ++ targetURL | link]
where
targetItemHyperlink = "\ESC]8;;" ++ targetURL ++ "\BEL" ++ targetItem ++ "\ESC]8;;\BEL"

unHTMLtargetItem :: Target -> Target
unHTMLtargetItem target = target {targetItem = unHTML $ targetItem target}
Expand Down