Skip to content

Commit 9f0002f

Browse files
Misc code work. (#131)
1 parent 604943d commit 9f0002f

2 files changed

Lines changed: 12 additions & 24 deletions

File tree

Core.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import UI qualified
3333
import Data.ByteString.Char8 qualified as P
3434
import Data.Sequence qualified as Seq
3535

36-
import Data.Array ((!), bounds, Array)
36+
import Data.Array ((!), Array)
3737
import Data.Proxy
3838
import Data.Tuple (swap)
3939
import Control.Monad.State.Strict
@@ -447,10 +447,9 @@ jumpToPrevDir = jumpToDir (\i _ -> max (i-1) 0)
447447

448448
-- | Generic jump to dir
449449
jumpToDir :: (Int -> Int -> Int) -> IO ()
450-
jumpToDir fn = modifyHS_ $ \st -> if size st == 0 then st else
450+
jumpToDir fn = modifyHS_ \st ->
451451
let i = fdir (music st ! cursor st)
452-
len = 1 + (snd . bounds $ folders st)
453-
d = fn i len
452+
d = fn i (length $ folders st)
454453
in st { cursor = dlo (folders st ! d) }
455454

456455
------------------------------------------------------------------------
@@ -463,14 +462,12 @@ instance Lookup File where extract = fbase
463462

464463
jumpToMatchFile :: Maybe String -> Bool -> IO ()
465464
jumpToMatchFile re sw = genericJumpToMatch re sw k sel
466-
where k st = (music st, if size st == 0 then -1 else cursor st, size st)
465+
where k st = (music st, cursor st, size st)
467466
sel i _ = i
468467

469468
jumpToMatchDir :: Maybe String -> Bool -> IO ()
470469
jumpToMatchDir re sw = genericJumpToMatch re sw k sel
471-
where k st = (folders st
472-
, if size st == 0 then -1 else fdir (music st ! cursor st)
473-
, 1 + (snd . bounds $ folders st))
470+
where k st = (folders st, fdir (music st ! cursor st), length $ folders st)
474471
sel i st = dlo (folders st ! i)
475472

476473
genericJumpToMatch :: Lookup a

UI.hs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ pPlaying dd = FancyS $ map (, defaultSty) $ " " : line where
193193
pId3 :: DrawData -> ByteString
194194
pId3 DD{drawState=st} = case id3 st of
195195
Just i -> id3str i
196-
Nothing -> case size st of
197-
0 -> "(empty)"
198-
_ -> fbase $ music st ! current st
196+
Nothing -> fbase $ music st ! current st
199197

200198
-- | mp3 information
201199
pInfo :: DrawData -> ByteString
@@ -315,26 +313,22 @@ pMode dd = take 4 $ map toLower $ show $ mode $ drawState dd
315313

316314
------------------------------------------------------------------------
317315

318-
-- | "x/n dir(s) y/m file(s)" cursor position read-out.
316+
-- | "x/n dirs y/m files" cursor position read-out.
319317
playInfo :: DrawData -> ByteString
320318
playInfo dd = mconcat
321-
-- TODO pregenerate as template
322319
[ spaces (P.length numd - P.length curd)
323-
, curd, "/", numd, " dir", onPlural (snd . bounds $ folders st) "" "s"
324-
, " "
325-
, spaces (P.length numf - P.length curf)
326-
, curf, "/", numf, " file", onPlural (size st) "" "s"
320+
, curd, "/", numd, " dirs"
321+
, spaces (1 + P.length numf - P.length curf)
322+
, curf, "/", numf, " files"
327323
]
328324
where
329325
st = drawState dd
330326
tobs = P.pack . show
331-
onPlural 1 s _ = s
332-
onPlural _ _ p = p
333327
curf = tobs $ 1 + cursor st
334328
numf = tobs $ size st
335329
mydir = fdir $ music st ! cursor st
336330
curd = tobs $ 1 + mydir
337-
numd = tobs $ 1 + snd (bounds $ folders st)
331+
numd = tobs $ length $ folders st
338332

339333
-- | The top title bar: cursor position + play indicator + uptime + version.
340334
playTitle :: DrawData -> StringA
@@ -427,10 +421,7 @@ playList dd@DD{ drawSize=Size y x, drawPos=Pos{posY=o}, drawState=st } =
427421
: map (, sty) v
428422
where
429423
sty' = if sty == sty2 || sty == sty3 then sty2 else sty1
430-
d = toMaxWidth (indent - 1) $ takeFileName
431-
$ case size st of
432-
0 -> "(empty)"
433-
_ -> dname $ folders st ! i
424+
d = toMaxWidth (indent - 1) $ takeFileName $ dname $ folders st ! i
434425

435426
------------------------------------------------------------------------
436427

0 commit comments

Comments
 (0)