Skip to content

Commit f62231c

Browse files
Hopeful fix for spinning on terminal crash.
1 parent b0c97c8 commit f62231c

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

Core.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,8 @@ mpgInput field = runForever $ do
271271
run :: IO ()
272272
run = runForever $ sequence_ . keymap =<< getKeys
273273
where
274-
getKeys = unsafeInterleaveIO $ do
275-
c <- UI.getKey
276-
cs <- getKeys
277-
pure (c:cs) -- A lazy list of curses keys
274+
-- A lazy list of curses keys
275+
getKeys = unsafeInterleaveIO $ (:) <$> UI.getKey <*> getKeys
278276

279277
------------------------------------------------------------------------
280278

UI.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,34 @@ suspend = raiseSignal sigTSTP
132132
screenSize :: IO (Int, Int)
133133
screenSize = Curses.scrSize
134134

135+
--
136+
-- | Rewrite of Curses.getCh to avoid looping on terminal crash
137+
-- | (also no unget support since I don't need it)
138+
--
139+
getCh :: IO Curses.Key
140+
getCh = do
141+
threadWaitRead 0
142+
v <- Curses.getch
143+
case v of
144+
-1 -> do
145+
putStrLn "Terminal has gone away? Hard-exiting now."
146+
exitFailure
147+
k -> pure $ Curses.decodeKey k
148+
135149
--
136150
-- | Read a key. UIs need to define a method for getting events.
137151
-- We only need to refresh if we don't have no SIGWINCH support.
138152
--
139153
getKey :: IO Char
140154
getKey = do
141-
k <- Curses.getCh
155+
k <- getCh
142156
if k == Curses.KeyResize
143157
then do
144158
when (isNothing Curses.cursesSigWinch) do
145159
runDraw $ redraw <> resizeui
146160
getKey
147161
else pure $ unkey k
148-
162+
149163
-- | Resize the window
150164
-- From "Writing Programs with NCURSES", by Eric S. Raymond and Zeyd M. Ben-Halim
151165
--

hmp3-ng.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.2
22

33
name: hmp3-ng
4-
version: 2.17.0
4+
version: 2.17.1
55
synopsis: A 2019 fork of an ncurses mp3 player written in Haskell
66
description: An mp3 player with a curses frontend. Playlists are populated by
77
passing file and directory names on the command line. 'h' displays

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-23.9
1+
resolver: lts-23.28
22
system-ghc: true
33
compiler-check: newer-minor
44

0 commit comments

Comments
 (0)