@@ -10,7 +10,8 @@ module Text (
1010 displayWidth , toMaxWidth , toWidth , byteLength ,
1111 fromBS , isLineSafe ,
1212 encodeFS ,
13- drawText , setXtermTitle
13+ drawText , setXtermTitle ,
14+ toBS , -- only used in test suite
1415) where
1516
1617import Base
@@ -35,12 +36,12 @@ newtype SText = SText ByteString
3536 deriving newtype (Semigroup , Monoid )
3637
3738-- | Convenient internal combinator.
38- unSText :: SText -> ByteString
39- unSText (SText bs) = bs
39+ toBS :: SText -> ByteString
40+ toBS (SText bs) = bs
4041
4142-- | Can be used in lieu of 'displayWidth' for known 1-width-character text.
4243byteLength :: SText -> Int
43- byteLength = P. length . unSText
44+ byteLength = P. length . toBS
4445
4546instance IsString SText where
4647 fromString = SText . UTF8. fromString . toPrintable
@@ -55,7 +56,7 @@ matches s = match' <$> makeRegexOptsM (compIgnoreCase + compExtended + compNoSub
5556
5657-- | Possible number.
5758readIntM :: SText -> Maybe Int
58- readIntM = fmap fst . P. readInt . unSText
59+ readIntM = fmap fst . P. readInt . toBS
5960
6061showInt :: Int -> SText
6162showInt = SText . P. pack . show
@@ -111,7 +112,7 @@ encodeFS str = do
111112
112113-- | Sum of the column widths of every codepoint.
113114displayWidth :: SText -> Int
114- displayWidth = UTF8. foldl (\ acc c -> acc + charWidth c) 0 . unSText
115+ displayWidth = UTF8. foldl (\ acc c -> acc + charWidth c) 0 . toBS
115116
116117-- | These functions truncate with ellipses if needed to get width ≤'w'.
117118-- 'toWidth' adds padding as needed so the width is exactly 'w'.
@@ -125,7 +126,7 @@ sizer pad w s@(SText bs)
125126 | True = walk 0 bs
126127 where
127128 dw = displayWidth s
128- byteTake i = SText . P. take i . unSText
129+ byteTake i = SText . P. take i . toBS
129130 walk ! l rest
130131 | l' >= w = byteTake (byteLength s - P. length rest) s
131132 <> mconcat (replicate (w- l) " …" )
@@ -146,7 +147,7 @@ foreign import ccall unsafe
146147-- | Set xterm title with ANSI escape sequence.
147148setXtermTitle :: [SText ] -> IO ()
148149setXtermTitle strs = do
149- traverse_ (P. hPut stderr) (before : map unSText strs ++ [after])
150+ traverse_ (P. hPut stderr) (before : map toBS strs ++ [after])
150151 hFlush stderr
151152 where
152153 before = " \ESC ]0;"
0 commit comments