{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
module Lib.FileHandling
where
import UniformBase
import Uniform.Pandoc (extMD)
textlinesFile :: TypedFile5 Text [Text]
textlinesFile :: TypedFile5 Text [Text]
textlinesFile = forall a b. TypedFiles5 a b => Extension -> TypedFile5 a b
makeTyped Extension
txtExtension
textlinesNewFile :: TypedFile5 Text [Text]
textlinesNewFile :: TypedFile5 Text [Text]
textlinesNewFile = forall a b. TypedFiles5 a b => Extension -> TypedFile5 a b
makeTyped Extension
newExtension
textlinesBakFile :: TypedFile5 Text [Text]
textlinesBakFile :: TypedFile5 Text [Text]
textlinesBakFile = forall a b. TypedFiles5 a b => Extension -> TypedFile5 a b
makeTyped Extension
bakExtension
mdFile :: TypedFile5 Text [Text]
mdFile :: TypedFile5 Text [Text]
mdFile = forall a b. TypedFiles5 a b => Extension -> TypedFile5 a b
makeTyped Extension
extMD
txtExtension :: Extension
txtExtension :: Extension
txtExtension = FilePath -> Extension
Extension FilePath
"txt" :: Extension
newExtension :: Extension
newExtension :: Extension
newExtension = FilePath -> Extension
Extension FilePath
"new" :: Extension
bakExtension :: Extension
bakExtension :: Extension
bakExtension = FilePath -> Extension
Extension FilePath
"bak" :: Extension
instance TypedFiles7 Text [Text] where
wrap7 :: Text -> [Text]
wrap7 Text
t = forall a. CharChains a => a -> [a]
lines' Text
t
unwrap7 :: [Text] -> Text
unwrap7 [Text]
t = forall a. CharChains a => [a] -> a
unlines' [Text]
t
readErlaubt :: Path Abs File -> ErrIO [Text]
readErlaubt :: Path Abs File -> ErrIO [Text]
readErlaubt Path Abs File
fnErl = do
[Text]
erl :: [Text] <- forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> ErrIO b
read8 Path Abs File
fnErl TypedFile5 Text [Text]
textlinesFile
let erl2 :: [Text]
erl2 = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. CharChains a => a -> [a]
words' forall a b. (a -> b) -> a -> b
$ [Text]
erl :: [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text]
erl2
writeWithBak :: Bool -> Path Abs File -> TypedFile5 Text [Text]-> [Text] -> ErrIO ()
writeWithBak :: Bool
-> Path Abs File -> TypedFile5 Text [Text] -> [Text] -> ErrIO ()
writeWithBak Bool
debug Path Abs File
fn TypedFile5 Text [Text]
textLineType [Text]
res =
if Bool
debug
then forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> b -> ErrIO ()
write8 Path Abs File
fn TypedFile5 Text [Text]
textlinesNewFile [Text]
res
else do
forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> ErrIO ()
renameToBak8 Path Abs File
fn TypedFile5 Text [Text]
textLineType
forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> b -> ErrIO ()
write8 Path Abs File
fn TypedFile5 Text [Text]
textLineType [Text]
res