@@ -98,10 +98,8 @@ end = do
9898screenSize :: IO (Int , Int )
9999screenSize = Curses. scrSize
100100
101- --
102101-- | Rewrite of Curses.getCh to avoid looping on terminal crash
103102-- | (also no unget support since I don't need it)
104- --
105103getCh :: IO Curses. Key
106104getCh = do
107105 threadWaitRead 0
@@ -113,10 +111,8 @@ getCh = do
113111 exitFailure
114112 k -> pure $ Curses. decodeKey k
115113
116- --
117114-- | Read a key. UIs need to define a method for getting events.
118115-- We only need to refresh if we don't have no SIGWINCH support.
119- --
120116getKey :: IO Char
121117getKey = do
122118 k <- getCh
@@ -260,39 +256,37 @@ showClock t =
260256
261257-- | The time used and time left
262258pTimes :: DrawData -> StringA
263- pTimes DD { drawFrame= Just Frame { .. } , drawSize= Size {sizeW= w} } =
259+ pTimes DD { drawFrame, drawSize= Size {sizeW= w} } =
264260 flip Fast defaultSty $ if w - 4 < P. length elapsed
265261 then " "
266262 else mconcat $ [" " , elapsed] ++ [gap <> " -" <> remaining | distance > 0 ]
267263 where
268- elapsed = showClock currentTime
269- remaining = showClock timeLeft
264+ elapsed = showClock ( maybe 0 currentTime drawFrame)
265+ remaining = maybe " ?:??.? " ( showClock . timeLeft) drawFrame
270266 gap = spaces distance
271267 distance = w - 5 - P. length elapsed - P. length remaining
272- pTimes _ = Fast " " defaultSty
273268
274269------------------------------------------------------------------------
275270
276271-- | A progress bar
277272progressBar :: DrawData -> StringA
278- progressBar dd@ DD {drawSize= Size {sizeW= w}, drawState= st} = case drawFrame dd of
279- Nothing -> FancyS [(" " , defaultSty), (spaces (w- 4 ), bgs)]
280- where
281- Style _ bg = progress (config st)
282- bgs = Style bg bg
273+ progressBar dd@ DD {drawSize= Size {sizeW}, drawState= st} = case drawFrame dd of
274+ Nothing -> FancyS [(" " , defaultSty), (spaces width, bgs)]
283275 Just Frame {.. } -> FancyS
284276 [ (" " , defaultSty)
285277 , (spaces distance, fgs)
286278 , (spaces (width - distance), bgs) ]
287279 where
288- width = w - 4
289- total = curr + left
290- distance = round ((curr / total) * fromIntegral width)
291- curr = realToFrac currentTime :: Float
292- left = realToFrac timeLeft
293- Style fg bg = progress (config st)
294- bgs = Style bg bg
295- fgs = Style fg fg
280+ total = curr + left - ε
281+ distance = ceiling (curr * fromIntegral (width - 1 ) / total)
282+ curr = toRational currentTime
283+ left = toRational timeLeft
284+ ε = 1 / 200
285+ where
286+ width = sizeW - 4
287+ Style fg bg = progress (config st)
288+ bgs = Style bg bg
289+ fgs = Style fg fg
296290
297291------------------------------------------------------------------------
298292
@@ -338,17 +332,16 @@ playInfo dd = mconcat
338332playTitle :: DrawData -> StringA
339333playTitle dd =
340334 flip Fast hl $ mconcat if gap >= 2
341- then [" " , inf, spaces gapl, indic, spaces gapr, time, " " , ver, " " ]
335+ then [" " , inf, spaces gapl, u indic, spaces gapr, time, " " , ver, " " ]
342336 else let gap' = x - indicl; gapl' = gap' `div` 2
343337 in if gap' >= 2
344- then [spaces gapl', indic, spaces $ gap' - gapl']
345- else [" " , P. take (x- 2 ) indic, " " ]
338+ then [spaces gapl', u indic, spaces $ gap' - gapl']
339+ else [" " , u $ take (x- 2 ) indic, " " ]
346340 where
347341 inf = playInfo dd
348342 time = pTime dd
349- indic = u $ pState dd ++ ' ' : pMode dd
343+ indic = pState dd ++ ' ' : pMode dd
350344 ver = pVersion
351-
352345 x = sizeW $ drawSize dd
353346 lsize = 1 + P. length inf
354347 rsize = 2 + P. length time + P. length ver
@@ -434,9 +427,9 @@ redrawJustClock = Draw $ discardErrors do
434427 st <- getsHS id
435428 (h, w) <- screenSize
436429 let dd = DD (Size h w) undefined st (clock st)
437- Curses. wMove Curses. stdScr 1 0 -- hardcoded!
430+ Curses. wMove Curses. stdScr 1 0
438431 drawLine $ progressBar dd
439- Curses. wMove Curses. stdScr 2 0 -- hardcoded!
432+ Curses. wMove Curses. stdScr 2 0
440433 drawLine $ pTimes dd
441434
442435------------------------------------------------------------------------
@@ -518,15 +511,11 @@ maybeLineDown _ h y x
518511lineDown :: Int -> Int -> IO ()
519512lineDown h y = Curses. wMove Curses. stdScr (min h (y+ 1 )) 0
520513
521- --
522514-- | Fill to end of line spaces
523- --
524515fillLine :: IO ()
525516fillLine = discardErrors Curses. clrToEol -- harmless?
526517
527- --
528518-- | move cursor to origin of stdScr.
529- --
530519gotoTop :: IO ()
531520gotoTop = Curses. wMove Curses. stdScr 0 0
532521{-# INLINE gotoTop #-}
@@ -540,9 +529,7 @@ slice i j arr =
540529
541530------------------------------------------------------------------------
542531
543- --
544532-- | magics for setting xterm titles using ansi escape sequences
545- --
546533setXtermTitle :: [ByteString ] -> IO ()
547534setXtermTitle strs = do
548535 traverse_ (P. hPut stderr) (before : strs ++ [after])
0 commit comments