Skip to content

Commit 5c8d173

Browse files
Fix bug with history changing with new songs. (#64)
1 parent 96c4eb6 commit 5c8d173

6 files changed

Lines changed: 20 additions & 19 deletions

File tree

.github/workflows/haskell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: 'ubuntu-22.04'
66
strategy:
77
matrix:
8-
ghc: ['9.4', '9.6', '9.8', '9.10', 'latest']
8+
ghc: ['9.6', '9.8', '9.10', 'latest']
99
name: GHC ${{ matrix.ghc }}
1010
steps:
1111
- uses: actions/checkout@v4

Core.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ showHist = do
600600
histVisible = Just $ do
601601
(tm, ix) <- toList $ playHist st
602602
pure (UTF8.toString $ showTimeDiff_ True tm now
603-
, UTF8.toString $ fbase $ music st ! ix)
603+
, (ix, UTF8.toString $ fbase $ music st ! ix))
604604
}
605605

606606
-- | Toggle the mode flag

Keymap.hs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Base hiding (all)
3737

3838
import Core
3939
import Config (package)
40-
import State (getsST, touchST, HState(helpVisible, playHist))
40+
import State (getsST, touchST, HState(helpVisible, histVisible))
4141
import Style (defaultSty, StringA(Fast))
4242
import qualified UI (resetui)
4343
import Lexers ((>||<),action,meta,execLexer
@@ -47,7 +47,6 @@ import UI.HSCurses.Curses (Key(..), decodeKey)
4747

4848
import qualified Data.ByteString.Char8 as P
4949
import qualified Data.Map as M
50-
import qualified Data.Sequence as Seq
5150

5251
data Direction = Forwards | Backwards
5352
data Zipper = Zipper { cur :: !String, back :: ![String], front :: ![String] }
@@ -120,9 +119,9 @@ printSearch spec = with do
120119
touchST
121120

122121
updateSearch :: (Zipper -> Zipper) -> SearchState -> MetaTarget
123-
updateSearch f st@(SearchState _ spec) =
122+
updateSearch f sst@(SearchState _ spec) =
124123
let spec' = spec{ schZipper = f $ schZipper spec }
125-
in (printSearch spec', st{schSpec=spec'}, Just dosearch)
124+
in (printSearch spec', sst{schSpec=spec'}, Just dosearch)
126125

127126
search_char :: LexerS
128127
search_char = anyNonSpecial `meta` \c -> updateSearch $ zipEdit (++ c)
@@ -168,30 +167,32 @@ search_eval = enter `meta` \_ (SearchState hist spec) -> case cur $ schZipper sp
168167

169168
history :: LexerS
170169
history = alt ['H', ';'] `meta`
171-
\_ st -> (with (showHist *> touchST), st, Just inner) where
170+
\_ sst -> (with (showHist *> touchST), sst, Just inner) where
172171
inner =
173-
alt any' `meta` (\_ st -> (with (hideHist *> touchST), st, Just allKeys))
172+
alt any' `meta` (\_ sst -> (with (hideHist *> touchST), sst, Just allKeys))
174173
>||< alt ['0'..'9'] `meta` handleKey '0' 0
175174
>||< alt ['a'..'z'] `meta` handleKey 'a' 10
176-
handleKey base off cs st =
175+
handleKey base off cs sst =
177176
(with do
178-
ph <- getsST playHist
177+
phm <- getsST histVisible
179178
for_
180-
do ph Seq.!? (fromEnum (head cs) - (fromEnum base - off))
181-
do jump . snd
179+
do phm >>= (!? (fromEnum (head cs) - (fromEnum base - off)))
180+
do jump . fst . snd
182181
hideHist
183182
touchST
184-
, st
183+
, sst
185184
, Just allKeys
186185
)
186+
-- Compatibility: List.!? only added in GHC 9.8
187+
xs !? n = listToMaybe $ drop n xs
187188

188189
------------------------------------------------------------------------
189190

190191
confirmQuit :: LexerS
191192
confirmQuit = char 'q' `meta`
192-
\_ st -> (with (forcePause *> toggleExit *> touchST), st, Just inner) where
193-
inner = alt any' `meta` (\_ st -> (with (toggleExit *> touchST), st, Just allKeys))
194-
>||< char 'y' `meta` (\_ st -> (with $ quit Nothing, st, Nothing))
193+
\_ sst -> (with (forcePause *> toggleExit *> touchST), sst, Just inner) where
194+
inner = alt any' `meta` (\_ sst -> (with (toggleExit *> touchST), sst, Just allKeys))
195+
>||< char 'y' `meta` (\_ sst -> (with $ quit Nothing, sst, Nothing))
195196

196197
------------------------------------------------------------------------
197198

State.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ data HState = HState {
6464
,status :: !Status
6565
,minibuffer :: !StringA -- contents of minibuffer
6666
,helpVisible :: !Bool -- is the help window shown?
67-
,histVisible :: !(Maybe [(String, String)]) -- history pop-up if shown
67+
,histVisible :: !(Maybe [(String, (Int, String))]) -- history pop-up if shown
6868
,exitVisible :: !Bool -- confirm exit modal shown
6969
,miniFocused :: !Bool -- is the mini buffer focused?
7070
,mode :: !Mode -- random mode

UI.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ instance ModalElement HistModal where
332332
let wd = modalWidth swd
333333
mtlen = maximum $ map (length . fst) hist
334334
tlen = min (mtlen + 1) $ wd `div` 3
335-
(wd,) $ flip map (zip (['0'..'9']++['a'..'z']) hist) \ (c, (time, song)) ->
335+
(wd,) $ flip map (zip (['0'..'9']++['a'..'z']) hist) \ (c, (time, (_, song))) ->
336336
let tstr = ellipsize tlen $ replicate (tlen - displayWidth time) ' ' ++ time
337337
in Fast (UTF8.fromString $ forceWidth wd $ ' ' : c : ' ' : tstr ++ ' ' : song) sty
338338

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.16.1
4+
version: 2.16.2
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

0 commit comments

Comments
 (0)