summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-01-07 05:43:01 +0100
committertv <tv@shackspace.de>2015-01-07 05:43:01 +0100
commit054fdedefe623817668ee689e7eac9de3d74f540 (patch)
tree989b9a62e3cf743c8bdc7eef7c6b774f8ec89578
parent893720cd7111828b65c66e0051c4c91e4405a740 (diff)
change search term with <M-q>
-rw-r--r--TreeView.hs7
-rw-r--r--test5.hs29
2 files changed, 36 insertions, 0 deletions
diff --git a/TreeView.hs b/TreeView.hs
index 26b04bd..218d167 100644
--- a/TreeView.hs
+++ b/TreeView.hs
@@ -6,6 +6,7 @@
module TreeView
( TreeView (..)
, getMessage
+ , getSearchTerm
, isTVMessage
, isTVSearchResult
, fromSearchResults
@@ -93,6 +94,12 @@ getMessage = \case
_ -> Nothing
+getSearchTerm :: TreeView -> Maybe String
+getSearchTerm = \case
+ TVSearch term -> Just term
+ _ -> Nothing
+
+
isTVMessage :: TreeView -> Bool
isTVMessage = \case
TVMessage _ -> True
diff --git a/test5.hs b/test5.hs
index c7bb314..b72850a 100644
--- a/test5.hs
+++ b/test5.hs
@@ -237,6 +237,17 @@ keymap "\ESC[Z" = moveCursorUpToPrevUnread -- S-Tab
keymap "\t" = moveCursorDownToNextUnread
keymap "\DEL" = moveToParent -- backspace
+keymap "\ESCq" = \q@State{..} ->
+ let parse = filter (/='\n') -- TODO proper parse
+ draft = fromMaybe "" $ getSearchTerm $ Z.label $ Z.root cursor
+ in editString q draft >>= \case
+ Left err -> return q { flashMessage = Plain err }
+ Right s' -> Notmuch.search s' >>= \case
+ Left err ->
+ return q { flashMessage = Plain err }
+ Right result ->
+ return q { cursor = Z.fromTree $ fromSearchResults (parse s') result }
+
keymap "\ESC[11~" = \q@State{..} ->
return q { flashMessage = Plain $ show $ treeViewId $ Z.label cursor }
@@ -546,6 +557,24 @@ editTags q@State{..} = case Z.label cursor of
in fromMaybe root $ findTree p root
+editString :: State -> String -> IO (Either String String)
+editString q s =
+ withTempFile' ".string" $ \(path, h) -> do
+ hPutStr stdout "\ESC[?1049h" -- TODO geht besser
+ hPutStr stdout "\ESC[?25l" -- TODO war mal besser
+ setFileMode path 0o600
+
+ hPutStr h s
+
+ hClose h
+
+ runEditor' path q >>= \case
+ ExitFailure code ->
+ return . Left $ "error exit code = " <> show code
+ ExitSuccess ->
+ Right <$> readFile path
+
+
runEditor :: FilePath -> State -> IO State
runEditor path q@State{..} =
runEditor' path q >>= \case