Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Handle splits on show
Browse files Browse the repository at this point in the history
  • Loading branch information
jazcarate committed Aug 30, 2020
1 parent 403521c commit f80b1db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Mbl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import qualified Lens.Micro as L
import Data.List ( find
, intercalate
, sortBy
, groupBy
)
import Lens.Micro ( (&)
, (^.)
Expand Down Expand Up @@ -79,7 +80,8 @@ showMBLs mbls = intercalate
storeRefs :: MBL -> T.State (Map.Map ByteString Char) String
storeRefs m = do
let as = scaleWait minimumTick (actions m)
charActions <- CM.mapM storeLongActions as
charActions <- (CM.mapM . CM.mapM) storeLongActions
$ groupBy (\a b -> isPrint a == True && isPrint b == True) as
return $ intercalate
""
[ maybe
Expand All @@ -90,7 +92,7 @@ showMBLs mbls = intercalate
<> ": "
)
$ name m
, BS.unpack $ BS.intercalate "" charActions
, BS.unpack $ BS.intercalate "" $ BS.intercalate "|" <$> charActions
, show $ repeat m
]
storeLongActions :: Action -> T.State (Map.Map ByteString Char) ByteString
Expand All @@ -109,9 +111,14 @@ showMBLs mbls = intercalate
else pure $ escapedA
where escapedA = escape a

isPrint :: Action -> Bool
isPrint a = case a of
Print _ -> True
_ -> False

escape :: ByteString -> ByteString
escape = BS.concatMap escape'
where escape' c = if c == '-' then "\\-" else BS.singleton c
where escape' c = if c == '-' || c == '|' then BS.snoc "\\" c else BS.singleton c

scaleWait :: D.Microseconds -> [Action] -> [Action]
scaleWait g as = concatMap scale as
Expand Down
4 changes: 2 additions & 2 deletions test/MblSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ spec = do
describe "Single Mbl" $ do
it "shows one char mbl inline" $ do
show <$> runParser configuration "tick: 1s\n--a-b" `shouldBe` Right "tick: 1s\n--a-b\n"
xit "shows the split" $ do --TODO handle split in show
show <$> runParser configuration "--a|b" `shouldBe` Right "--a|b"
it "shows the split" $ do
show <$> runParser configuration "tick: 1s\n--a|b" `shouldBe` Right "tick: 1s\n--a|b\n"
it "escapes delimiters" $ do
show <$> runParser configuration "tick: 1s\n--\\-" `shouldBe` Right "tick: 1s\n--a\n\n[a]: -"
it "keeps the name" $ do
Expand Down

0 comments on commit f80b1db

Please sign in to comment.