From 2af03a38122985ce116e0332362624d036000101 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sun, 12 Mar 2023 15:48:47 +0100 Subject: [PATCH 1/2] Support hyperlinks in search output Add `--hyperlink` flag to search sub command which outputs ANSI escape sequences that supporting terminal emulators can recognize. --- src/Action/CmdLine.hs | 2 ++ src/Action/Search.hs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Action/CmdLine.hs b/src/Action/CmdLine.hs index 30266573..8d033bdb 100644 --- a/src/Action/CmdLine.hs +++ b/src/Action/CmdLine.hs @@ -25,6 +25,7 @@ data CmdLine ,json :: Bool ,jsonl :: Bool ,link :: Bool + ,hyperlink :: Bool ,numbers :: Bool ,info :: Bool ,database :: FilePath @@ -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)" diff --git a/src/Action/Search.hs b/src/Action/Search.hs index e01de4a3..30bd70c3 100644 --- a/src/Action/Search.hs +++ b/src/Action/Search.hs @@ -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 @@ -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} From b68d32331c5798f17738d246fa61f159669f6075 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sat, 18 Mar 2023 21:32:22 +0100 Subject: [PATCH 2/2] Update copyright year --- hoogle.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hoogle.cabal b/hoogle.cabal index 0b0fe02d..bfd94006 100644 --- a/hoogle.cabal +++ b/hoogle.cabal @@ -7,7 +7,7 @@ license-file: LICENSE category: Development author: Neil Mitchell maintainer: Neil Mitchell -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