create file if does not exist
This commit is contained in:
parent
8a676d6b4f
commit
419cad6cab
1 changed files with 19 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue