Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10e1e52

Browse files
committed
Use package "editor-open" in order to have YAML syntax highlighting
1 parent 4634352 commit 10e1e52

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

tasklite-core/package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ library:
5555
- cassava
5656
- colour
5757
- directory
58+
- editor-open
5859
- exceptions
5960
- file-embed
6061
- filepath
@@ -75,7 +76,6 @@ library:
7576
- QuickCheck
7677
- quickcheck-instances
7778
- random
78-
- read-editor
7979
- simple-sql-parser
8080
- sqlite-simple
8181
- sqlite-simple

tasklite-core/source/ImportExport.hs

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import Protolude (
2424
Text,
2525
Traversable (sequence),
2626
asum,
27-
decodeUtf8,
2827
die,
2928
fromMaybe,
3029
hush,
@@ -77,8 +76,8 @@ import Lib (
7776
execWithConn,
7877
execWithTask,
7978
insertNotes,
79+
insertRecord,
8080
insertTags,
81-
insertRecord ,
8281
updateTask,
8382
)
8483
import Note (Note (..))
@@ -95,7 +94,6 @@ import System.Directory (createDirectoryIfMissing, removeFile)
9594
import System.FilePath (takeExtension, (</>))
9695
import System.Posix.User (getEffectiveUserName)
9796
import System.Process (readProcess)
98-
import System.ReadEditor (readEditorWith)
9997
import Task (
10098
Task (
10199
Task,
@@ -120,6 +118,7 @@ import Task (
120118
textToTaskState,
121119
zeroTask,
122120
)
121+
import Text.Editor (runUserEditorDWIM, yamlTemplate)
123122
import Text.Parsec.Rfc2822 (GenericMessage (..), message)
124123
import Text.Parsec.Rfc2822 qualified as Email
125124
import Text.ParserCombinators.Parsec as Parsec (parse)
@@ -712,18 +711,15 @@ backupDatabase conf = do
712711

713712
editTaskByTask :: Config -> Connection -> Task -> IO (Doc AnsiStyle)
714713
editTaskByTask _ connection taskToEdit = do
715-
let taskYaml = (T.unpack . decodeUtf8 . Yaml.encode) taskToEdit
716-
717-
newContent <- readEditorWith taskYaml
714+
let taskYaml = Yaml.encode taskToEdit
715+
newContent <- runUserEditorDWIM yamlTemplate taskYaml
718716

719717
if newContent == taskYaml
720718
then
721719
pure $
722720
"⚠️ Nothing changed" <+> hardline
723721
else do
724722
let
725-
newContentBS = P.encodeUtf8 $ T.pack newContent
726-
727723
parseMetadata :: Value -> Parser Bool
728724
parseMetadata val = case val of
729725
Object obj -> do
@@ -735,10 +731,10 @@ editTaskByTask _ connection taskToEdit = do
735731

736732
hasMetadata =
737733
parseMaybe parseMetadata
738-
=<< (rightToMaybe $ Yaml.decodeEither' newContentBS :: Maybe Value)
734+
=<< (rightToMaybe $ Yaml.decodeEither' newContent :: Maybe Value)
739735

740736
decodeResult :: Either ParseException ImportTask
741-
decodeResult = Yaml.decodeEither' newContentBS
737+
decodeResult = Yaml.decodeEither' newContent
742738

743739
case decodeResult of
744740
Left error -> die $ show error <> " in task \n" <> show newContent

tasklite-core/tasklite-core.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ library
7272
, cassava
7373
, colour
7474
, directory
75+
, editor-open
7576
, exceptions
7677
, file-embed
7778
, filepath
@@ -90,7 +91,6 @@ library
9091
, protolude
9192
, quickcheck-instances
9293
, random
93-
, read-editor
9494
, simple-sql-parser
9595
, sqlite-simple
9696
, syb

0 commit comments

Comments
 (0)