From 054fdedefe623817668ee689e7eac9de3d74f540 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 7 Jan 2015 05:43:01 +0100 Subject: change search term with --- TreeView.hs | 7 +++++++ test5.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) 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 -- cgit v1.2.3