diff --git a/src/App/Gui.hs b/src/App/Gui.hs index bd5e598..56468df 100644 --- a/src/App/Gui.hs +++ b/src/App/Gui.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} module Gui (runEditor) where @@ -17,6 +18,10 @@ import qualified Graphics.Vty as Vty import Data.Text (pack, singleton) import Data.Text.Markup (Markup, (@@)) +---- Files ---- +import System.IO (IOMode (..), hClose, hGetContents, + openFile) + ---- Various ---- import Control.Monad.IO.Class (liftIO) import Data.List @@ -45,8 +50,19 @@ makeLenses ''HeditState runEditor :: FilePath -> IO () runEditor f = do - content <- readFile f - _ <- BrickMain.defaultMain theApp (initialState f content) + handle <- openFile f ReadWriteMode -- creates file if it does not exist + content <- hGetContents handle + {- + reads the content before closing the handle (non-lazy) + this is the version with the fewest "dependecies" + other options: + - ByteString.hGetContents: strict, fast + -> ByteString.Lazy for lazy, fast + - Text.IO.hGetContents: strict, needs 2x file size while reading in + -> filesize == 2xRAM = bad + -} + content `seq` hClose handle + BrickMain.defaultMain theApp (initialState f content) return () theApp :: App HeditState Vty.Event Names