packages feed

rasa-ext-files (empty) → 0.1.0.0

raw patch · 4 files changed

+127/−0 lines, 4 filesdep +basedep +data-defaultdep +lenssetup-changed

Dependencies added: base, data-default, lens, rasa, rasa-ext-cmd, rasa-ext-status-bar, text

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License++Copyright (c) 2016 Chris Penner++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rasa-ext-files.cabal view
@@ -0,0 +1,36 @@+name:                rasa-ext-files+version:             0.1.0.0+synopsis:            Rasa Ext for filesystem actions+description:         Rasa Ext for filesystem actions+homepage:            https://github.com/ChrisPenner/rasa/+license:             MIT+license-file:        LICENSE+author:              Chris Penner+maintainer:          christopher.penner@gmail.com+copyright:           2016 Chris Penner+category:            Extension+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:+                       Rasa.Ext.Files++  build-depends:       base >= 4.7 && < 5+                     , rasa+                     , rasa-ext-status-bar+                     , rasa-ext-cmd+                     , data-default+                     , lens+                     , text+  default-language:    Haskell2010++  default-extensions:++  ghc-options:         -Wall++source-repository head+  type:     git+  location: https://github.com/ChrisPenner/rasa
+ src/Rasa/Ext/Files.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}++module Rasa.Ext.Files+  ( files+  , save+  ) where++import qualified Data.Text.IO as TIO+import Control.Lens+import System.Environment++import Data.Foldable+import Data.Typeable+import Data.Default +import Data.Monoid++import Control.Monad.IO.Class+import qualified Data.Text as T++import Rasa.Ext+import Rasa.Ext.Cmd+import Rasa.Ext.StatusBar++data FileInfo = FileInfo+  { _filename :: Maybe T.Text+  } deriving (Typeable, Show, Eq)++makeLenses ''FileInfo++instance Default FileInfo where+  def = FileInfo {+  _filename=Nothing+}++files :: Scheduler ()+files = do+  onInit $ do+    loadFiles+    addCmd "save" $ focusDo . saveAs+  beforeRender showFilename++showFilename :: Action ()+showFilename = focusDo $ do+  mName <- use $ bufExt.filename+  traverse_ (leftStatus . disp) mName+      where disp name = "<" <> name <> ">"++saveAs :: T.Text -> BufAction ()+saveAs fName = use text >>= liftIO . TIO.writeFile (T.unpack fName)++save :: BufAction ()+save = do+  mName <- use $ bufExt.filename+  case mName of+    Just fName -> saveAs fName+    Nothing -> return ()++setFilename :: T.Text -> BufAction ()+setFilename fname = bufExt.filename ?= fname++addFile :: T.Text -> T.Text -> Action ()+addFile fname txt = addBufferThen txt (setFilename fname)++loadFiles :: Action ()+loadFiles = do+  fileNames <- liftIO getArgs+  fileTexts <- liftIO $ traverse TIO.readFile fileNames+  mapM_ (uncurry addFile) $ zip (T.pack <$> fileNames) fileTexts