@@ -1,11 +1,9 @@
1−{-# LANGUAGE MultiWayIf #-}
1+-- Copyright Corey O'Connor
2{-# LANGUAGE TemplateHaskell #-}
2{-# LANGUAGE TemplateHaskell #-}
3−-- Copyright 2009-2010 Corey O'Connor
4{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE BangPatterns #-}
5{-# LANGUAGE ExistentialQuantification #-}
4{-# LANGUAGE ExistentialQuantification #-}
6{-# LANGUAGE NamedFieldPuns #-}
5{-# LANGUAGE NamedFieldPuns #-}
7{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GADTs #-}
8−{-# LANGUAGE ExistentialQuantification #-}
9{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE ScopedTypeVariables #-}
10-- The ops to define the content for an output region.
8-- The ops to define the content for an output region.
11module Graphics.Vty.Span
9module Graphics.Vty.Span
@@ -281,6 +279,19 @@ add_maybe_clipped BGFill {output_width, output_height} = do
281 let output_width' = min (output_width - s.^skip_columns) s.^remaining_columns
279 let output_width' = min (output_width - s.^skip_columns) s.^remaining_columns
282 output_height' = min (output_height - s.^skip_rows ) s.^remaining_rows
280 output_height' = min (output_height - s.^skip_rows ) s.^remaining_rows
283 add_unclipped (BGFill output_width' output_height')
281 add_unclipped (BGFill output_width' output_height')
282+add_maybe_clipped CropRight {cropped_image, output_width} = do
283+ remaining_columns .= output_width
284+ add_maybe_clipped cropped_image
285+add_maybe_clipped CropLeft {cropped_image, left_skip} = do
286+ skip_columns += left_skip
287+ add_maybe_clipped cropped_image
288+add_maybe_clipped CropBottom {cropped_image, output_height} = do
289+ remaining_rows .= output_height
290+ add_maybe_clipped cropped_image
291+add_maybe_clipped CropTop {cropped_image, top_skip} = do
292+ skip_rows += top_skip
293+ add_maybe_clipped cropped_image
284add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
295add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
285 state <- get
296 state <- get
286 when (state^.remaining == 0) $ fail $ name ++ " with remaining == 0"
297 when (state^.remaining == 0) $ fail $ name ++ " with remaining == 0"
@@ -328,34 +339,6 @@ add_unclipped_text txt = do
328 used_display_columns = wcswidth $ TL.unpack txt
339 used_display_columns = wcswidth $ TL.unpack txt
329 use row_offset >>= snoc_op op
340 use row_offset >>= snoc_op op
331−-- | Add a background fill of the given column width to the row display operations.
333−-- This has a fast path for background characters that are a single column and a single byte.
334−-- Otherwise this has to compute the width of the background character and replicate a sequence of
335−-- bytes to fill in the required width.
336−snoc_bg_fill :: MRowOps s -> Background -> Int -> Int -> ST s ()
337−snoc_bg_fill _row_ops _bg 0 _row
339−snoc_bg_fill mrow_ops (Background c back_attr) fill_length row
341− snoc_op mrow_ops row $ AttributeChange back_attr
342− -- By all likelyhood the background character will be an ASCII character. Which is a single
343− -- byte in utf8. Optimize for this special case.
344− utf8_bs <- if c <= (toEnum 255 :: Char)
346− let !(c_byte :: Word8) = BInt.c2w c
347− in unsafeIOToST $ do
348− BInt.create fill_length
349− $ \ptr -> mapM_ (\i -> pokeByteOff ptr i c_byte)
350− [0 .. (fill_length - 1)]
352− let !(c_bytes :: [Word8]) = encode [c]
353− in unsafeIOToST $ do
354− BInt.create (fill_length * length c_bytes)
355− $ \ptr -> mapM_ (\(i,b) -> pokeByteOff ptr i b)
356− $ zip [0 .. (fill_length - 1)] (cycle c_bytes)
357− snoc_op mrow_ops row $ TextSpan fill_length fill_length (UTF8.fromRep utf8_bs)
359-- | snocs the operation to the operations for the given row.
342-- | snocs the operation to the operations for the given row.
360snoc_op :: SpanOp -> Int -> BlitM s ()
343snoc_op :: SpanOp -> Int -> BlitM s ()
361snoc_op !op !row = do
344snoc_op !op !row = do