on master help sign in
correctly set the attribute when adding background spans
d2adb00Corey O'Connor
src/Graphics/Vty/PictureToSpans.hs+18−15
@@ -91,7 +91,7 @@ substitute_skips ClearBackground ops = do
91 Skip w -> Vector.init row_ops `Vector.snoc` RowEnd w
91 Skip w -> Vector.init row_ops `Vector.snoc` RowEnd w
92 _ -> row_ops
92 _ -> row_ops
93 -- now all the skips can be replaced by replications of ' ' of the required width.
93 -- now all the skips can be replaced by replications of ' ' of the required width.
94− let row_ops'' = swap_skips_for_single_column_char_span ' ' row_ops'
94+ let row_ops'' = swap_skips_for_single_column_char_span ' ' current_attr row_ops'
95 MVector.write ops row row_ops''
95 MVector.write ops row row_ops''
96 return ops
96 return ops
97substitute_skips (Background {background_char, background_attr}) ops = do
97substitute_skips (Background {background_char, background_attr}) ops = do
@@ -102,31 +102,34 @@ substitute_skips (Background {background_char, background_attr}) ops = do
102 | w == 1 -> do
102 | w == 1 -> do
103 forM_ [0 .. MVector.length ops - 1] $ \row -> do
103 forM_ [0 .. MVector.length ops - 1] $ \row -> do
104 row_ops <- MVector.read ops row
104 row_ops <- MVector.read ops row
105− let row_ops' = swap_skips_for_single_column_char_span background_char row_ops
105+ let row_ops' = swap_skips_for_single_column_char_span background_char background_attr row_ops
106− row_ops'' = (AttributeChange background_attr) `Vector.cons` row_ops'
107− MVector.write ops row row_ops''
106+ MVector.write ops row row_ops'
108 | otherwise -> do
107 | otherwise -> do
109 forM_ [0 .. MVector.length ops - 1] $ \row -> do
108 forM_ [0 .. MVector.length ops - 1] $ \row -> do
110 row_ops <- MVector.read ops row
109 row_ops <- MVector.read ops row
111− let row_ops' = swap_skips_for_char_span w background_char row_ops
110+ let row_ops' = swap_skips_for_char_span w background_char background_attr row_ops
112− row_ops'' = (AttributeChange background_attr) `Vector.cons` row_ops'
113− MVector.write ops row row_ops''
111+ MVector.write ops row row_ops'
114 return ops
112 return ops
115
113
116−swap_skips_for_single_column_char_span :: Char -> SpanOps -> SpanOps
114+swap_skips_for_single_column_char_span :: Char -> Attr -> SpanOps -> SpanOps
117−swap_skips_for_single_column_char_span c = Vector.map f
115+swap_skips_for_single_column_char_span c a = Vector.concatMap f
118− where f (Skip ow) = TextSpan ow ow (T.encodeUtf8 $ T.pack $ replicate ow c)
116+ where f (Skip ow) = let txt = T.pack $ replicate ow c
119− f v = v
117+ in Vector.cons (AttributeChange a)
118+ (Vector.singleton $ TextSpan ow ow (T.encodeUtf8 txt))
119+ f v = Vector.singleton v
120
120
121−swap_skips_for_char_span :: Int -> Char -> SpanOps -> SpanOps
121+swap_skips_for_char_span :: Int -> Char -> Attr -> SpanOps -> SpanOps
122−swap_skips_for_char_span w c = Vector.map f
122+swap_skips_for_char_span w c a = Vector.concatMap f
123 where
123 where
124 f (Skip ow) = let txt_0_cw = ow `div` w
124 f (Skip ow) = let txt_0_cw = ow `div` w
125 txt_0 = T.pack $ replicate txt_0_cw c
125 txt_0 = T.pack $ replicate txt_0_cw c
126 txt_1_cw = ow `mod` w
126 txt_1_cw = ow `mod` w
127 txt_1 = T.pack $ replicate txt_1_cw '…'
127 txt_1 = T.pack $ replicate txt_1_cw '…'
128+ cw = txt_0_cw + txt_1_cw
128− in TextSpan ow (txt_0_cw + txt_1_cw) $ T.encodeUtf8 (txt_0 `T.append` txt_1)
129+ txt = txt_0 `T.append` txt_1
129− f v = v
130+ in Vector.cons (AttributeChange a)
131+ (Vector.singleton $ TextSpan ow cw $ T.encodeUtf8 txt)
132+ f v = Vector.singleton v
130
133
131-- | Builds a vector of row operations that will output the given picture to the terminal.
134-- | Builds a vector of row operations that will output the given picture to the terminal.
132--
135--