@@ -20,6 +20,8 @@ module Graphics.Vty.Span
2020import Graphics.Vty.DisplayRegion
2121import Graphics.Vty.Image
2222
23+import Graphics.Vty.Image.Internal ( clip_text )
24+
2325import Data.Vector (Vector)
2426import qualified Data.Vector as Vector
2527
@@ -35,7 +37,7 @@ data SpanOp =
3537 { text_span_attr :: !Attr
3638 , text_span_output_width :: !Int
3739 , text_span_char_width :: !Int
38− , text_span_data :: DisplayText
40+ , text_span_text :: DisplayText
3941 }
4042 -- | Skips the given number of columns
4143 -- A skip is transparent.... maybe? I am not sure how attribute changes interact.
@@ -62,7 +64,25 @@ split_ops_at in_w in_ops = split_ops_at' in_w in_ops
6264 where
6365 split_ops_at' 0 ops = (Vector.empty, ops)
6466 split_ops_at' remaining_columns ops = case Vector.head ops of
65− t@(TextSpan {}) -> undefined
67+ t@(TextSpan {}) -> if remaining_columns >= text_span_output_width t
68+ then let (pre,post) = split_ops_at' (remaining_columns - text_span_output_width t) (Vector.tail ops)
69+ in (Vector.cons t pre, post)
70+ else let pre_txt = clip_text (text_span_text t) 0 remaining_columns
71+ pre_op = TextSpan { text_span_attr = text_span_attr t
72+ , text_span_output_width = remaining_columns
73+ , text_span_char_width = fromIntegral $! TL.length pre_txt
74+ , text_span_text = pre_txt
75+ }
76+ post_width = text_span_output_width t - remaining_columns
77+ post_txt = clip_text (text_span_text t) remaining_columns post_width
78+ post_op = TextSpan { text_span_attr = text_span_attr t
79+ , text_span_output_width = post_width
80+ , text_span_char_width = fromIntegral $! TL.length post_txt
81+ , text_span_text = post_txt
82+ }
83+ in ( Vector.singleton pre_op
84+ , Vector.cons post_op (Vector.tail ops)
85+ )
6686 Skip w -> if remaining_columns >= w
6787 then let (pre,post) = split_ops_at' (remaining_columns - w) (Vector.tail ops)
6888 in (Vector.cons (Skip w) pre, post)