Skip to content

Commit

Permalink
Fixed -ms, refactored the state dump code, will maybe come in handy l…
Browse files Browse the repository at this point in the history
…ater...
  • Loading branch information
SOwOphie committed Jul 15, 2020
1 parent 1b20226 commit e5e55d6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Selected text in the main view will no longer cause status messages to be
selected as well.
- Fixed elastic tabstops performace problems.
- Fixed `-ms` exiting immediately.

## Other Changes

Expand Down
19 changes: 10 additions & 9 deletions src/WSEdit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,20 @@ start = do
-- | Possibly loads the file specified in `fname`, then runs the editor.
exec :: Bool -> WSEdit ()
exec b = do
when b $ ( catchEditor (load True)
(\e -> quitComplain ( "An I/O error occured while loading:\n\n"
++ show e
)
>> return False
)
>>= flip when (do
if b
then catchEditor (load True)
(\e -> quitComplain ( "An I/O error occured while loading:\n\n"
++ show e
)
>> return False
)
>>= flip when (do
standby "Building initial rendering cache..."
rebuildAll Nothing
rebuildTabCache
mainLoop
)
)
)
else mainLoop

drawExitFrame

Expand Down
4 changes: 2 additions & 2 deletions src/WSEdit/Arguments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,14 @@ parseArguments (c, s) = do

let t = drop 1
$ dropWhile null
$ dropWhile (not. null)
$ dropWhile (not . null)
$ linesPlus sf

(tc, ts) = withSnd (drop 1 . dropWhile null)
$ span (not . null) t

c' = fmap ( unPrettyEdConfig (vtyObj cf)
(keymap cf)
(keymap cf)
)
$ readMay $ unlinesPlus tc
s' = readMay $ unlinesPlus ts
Expand Down
42 changes: 27 additions & 15 deletions src/WSEdit/Control/Global.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module WSEdit.Control.Global
( simulateCrash
, emergencySave
, bail
, dumpState
, quitComplain
, quit
, forceQuit
Expand Down Expand Up @@ -260,21 +261,12 @@ bail mayComp s = do
, "Writing state dump to $HOME/CRASH-DUMP ..."
]

liftIO $ writeFile (h ++ "/CRASH-DUMP")
$ "WSEDIT " ++ version ++ " CRASH LOG\n"
++ "Error message: " ++ (headDef "" $ lines s)
++ maybe "" (\str -> " (" ++ str ++ ")") mayComp
++ "\nLast recorded event: "
++ fromMaybe "-" (fmap show $ lastEvent st)
++ "\n\nEditor configuration:\n"
++ indent (ppShow $ prettyEdConfig c)
++ "\n\nEditor state:\n"
++ indent ( ppShow
$ mapPast (\hs -> hs { dict = empty })
$ fromJustNote (fqn "bail")
$ chopHist 10
$ Just st
)
dumpState (h ++ "/CRASH-DUMP")
$ "WSEDIT " ++ version ++ " CRASH LOG\n"
++ "Error message: " ++ (headDef "" $ lines s)
++ maybe "" (\str -> " (" ++ str ++ ")") mayComp
++ "\nLast recorded event: "
++ fromMaybe "-" (fmap show $ lastEvent st)

drawExitFrame

Expand All @@ -290,6 +282,26 @@ bail mayComp s = do

exitFailure


-- | Dumps the editor state and config to a given file, with a given prefix
-- added as the first few lines.
dumpState :: FilePath -> String -> WSEdit ()
dumpState f pref = do
c <- ask
st <- get

liftIO
$ writeFile f
$ pref
++ "\n\nEditor configuration:\n"
++ indent (ppShow $ prettyEdConfig c)
++ "\n\nEditor state:\n"
++ indent ( ppShow
$ mapPast (\hs -> hs { dict = empty })
$ fromJustNote (fqn "dumpState")
$ chopHist 10
$ Just st
)
where
indent :: String -> String
indent = unlinesPlus . map (" " ++) . linesPlus
Expand Down
4 changes: 2 additions & 2 deletions src/WSEdit/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import qualified WSEdit.Buffer as B

-- | Version number constant.
version :: String
version = "1.2.3.15"
version = "1.2.3.16"

-- | Upstream URL.
upstream :: String
Expand All @@ -129,7 +129,7 @@ data Stability = Prototype

-- | Current release stability
stability :: Stability
stability = RC
stability = Release



Expand Down
4 changes: 2 additions & 2 deletions src/WSEdit/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ dump s x = unsafePerformIO $ do

return x

-- | Appends the given string to the file @dmp@ in the user's home directory.
-- | Appends the given string to the file @dmp@ in the user's home directory.
dlog :: String -> IO ()
dlog s = do
h <- getHomeDirectory
Expand Down Expand Up @@ -348,10 +348,10 @@ timedM s a = do
++ "μs\n\n"

return a'

#endif



-- | Attempt to read a file, or return 'Nothing' if it fails.
mayReadFile :: FilePath -> IO (Maybe String)
mayReadFile f = do
Expand Down
2 changes: 1 addition & 1 deletion wsedit.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wsedit
version: 1.2.3.15
version: 1.2.3.16
synopsis: A simple terminal source code editor.
description:
homepage: https://github.com/LadyBoonami/wsedit
Expand Down

0 comments on commit e5e55d6

Please sign in to comment.