summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2019-02-18 12:05:36 +0300
committerdefanor <defanor@uberspace.net>2019-02-18 12:05:36 +0300
commit637f52294ef1a7ee6bbaf3fa8eda8e35472d316e (patch)
treee6c21981cb328d4c1986b3eba9ad74cd42c9210c
parente198647ea5e12c6d80b74b615d382de9beb5d6b6 (diff)
downloadpancake-637f52294ef1a7ee6bbaf3fa8eda8e35472d316e.zip
pancake-637f52294ef1a7ee6bbaf3fa8eda8e35472d316e.tar.gz
pancake-637f52294ef1a7ee6bbaf3fa8eda8e35472d316e.tar.bz2
Add the "gs" command for Gopher search
-rw-r--r--Pancake.hs10
-rw-r--r--Pancake/Command.hs12
-rw-r--r--README1
-rw-r--r--pancake.12
4 files changed, 25 insertions, 0 deletions
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[ <columns>]: set terminal/window width manually
:set position[ <line>]: set current terminal/window line
:redisplay: redisplay current document
+:gs [,]<number> <query>: 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"