From 637f52294ef1a7ee6bbaf3fa8eda8e35472d316e Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 18 Feb 2019 12:05:36 +0300 Subject: Add the "gs" command for Gopher search --- Pancake.hs | 10 ++++++++++ Pancake/Command.hs | 12 ++++++++++++ README | 1 + pancake.1 | 2 ++ 4 files changed, 25 insertions(+) diff --git a/Pancake.hs b/Pancake.hs index 5420530..45fef50 100644 --- a/Pancake.hs +++ b/Pancake.hs @@ -283,6 +283,16 @@ command (GoTo t (RNumber i)) = do if length (rLinks $ rendered st) > i then command (GoTo t $ RURI $ rLinks (rendered st) !! i) else putErrLn "No such link" +command (GopherSearch i q) = do + st <- get + if length (rLinks $ rendered st) > i + then + let refURIString = uriToString id (rLinks (rendered st) !! i) "" + searchString = refURIString ++ "%09" ++ escapeURIString isUnreserved q + in maybe (putErrLn "Failed to compose a valid search URI") + (command . GoTo Nothing . RURI) + (parseURI searchString) + else putErrLn "No such link" command Back = do st <- get case history st of diff --git a/Pancake/Command.hs b/Pancake/Command.hs index 4686924..297a438 100644 --- a/Pancake/Command.hs +++ b/Pancake/Command.hs @@ -52,6 +52,7 @@ data Command = Quit | More | GoTo (Maybe String) Reference -- ^ Document type, reference + | GopherSearch Int String | Save Reference (Maybe FilePath) | Back | Forward @@ -166,6 +167,16 @@ loadConf = string "load config" *> (LoadConfig <$> optionMaybe (space *> many1 anyChar)) <* eof +gopherSearch :: String -> Parser Command +gopherSearch digits = do + string "gs" + space + ref <- pNumber digits + _ <- space + query <- many1 anyChar + _ <- eof + pure $ GopherSearch ref query + -- | Command parser. command :: Config -> Parser Command command c = @@ -181,4 +192,5 @@ command c = , setPos "set position" , loadConf "load config" , goTo "follow uri" + , gopherSearch (referenceDigits c) "gopher search" ]) diff --git a/README b/README index a7ecec9..8725879 100644 --- a/README +++ b/README @@ -77,6 +77,7 @@ Commands :set width[ ]: set terminal/window width manually :set position[ ]: set current terminal/window line :redisplay: redisplay current document +:gs [,] : Gopher search, using a given reference and query pancake-mode provides additional aliases and commands, see built-in emacs documentation (``C-h m``) for those. diff --git a/pancake.1 b/pancake.1 index 09cdcc6..38656bc 100644 --- a/pancake.1 +++ b/pancake.1 @@ -70,6 +70,8 @@ set terminal/window width manually set current terminal/window line .IP "\fBredisplay\fR" redisplay current document +.IP "\fBgs\fR [\fB,\fR]\fInumber\fR \fIquery\fR" +Gopher search, using a given reference and query .SH DEFAULT SHORTCUTS .IP "\fBg\fR" -- cgit v1.2.3