mirror of
https://github.com/ilyakooo0/vty.git
synced 2024-10-04 11:17:08 +03:00
cleanup and updates to get the test suite to compile
This commit is contained in:
parent
cd6747cfa6
commit
f3108faed9
@ -2,8 +2,6 @@
|
||||
module Graphics.Vty.DisplayRegion
|
||||
where
|
||||
|
||||
import Data.Word
|
||||
|
||||
-- | Region of the terminal that vty will output to. Units are columns not characters.
|
||||
data DisplayRegion = DisplayRegion
|
||||
{ region_width :: !Int
|
||||
|
@ -32,7 +32,6 @@ import Graphics.Vty.Attributes
|
||||
import Graphics.Vty.Image
|
||||
|
||||
import Control.DeepSeq
|
||||
import Data.Word
|
||||
|
||||
-- | The type of images to be displayed using 'update'.
|
||||
-- Can be constructed directly or using `pic_for_image`. Which provides an initial instance with
|
||||
|
@ -24,33 +24,22 @@ import Graphics.Vty.Image
|
||||
import Graphics.Vty.Image.Internal
|
||||
import Graphics.Vty.Picture
|
||||
import Graphics.Vty.DisplayRegion
|
||||
import Graphics.Text.Width
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Lens
|
||||
import Control.Monad ( forM_ )
|
||||
import Control.Lens hiding ( op )
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.State.Strict
|
||||
import Control.Monad.State.Strict hiding ( state )
|
||||
import Control.Monad.ST.Strict hiding ( unsafeIOToST )
|
||||
import Control.Monad.ST.Unsafe ( unsafeIOToST )
|
||||
|
||||
import Data.Monoid
|
||||
import Data.Vector (Vector)
|
||||
import qualified Data.Vector as Vector hiding ( take, replicate )
|
||||
import Data.Vector.Mutable ( MVector(..))
|
||||
import qualified Data.Vector.Mutable as Vector
|
||||
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
import qualified Data.ByteString.Lazy.Internal as BL
|
||||
import qualified Data.Foldable as Foldable
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Encoding as T
|
||||
import qualified Data.Text.Lazy as TL
|
||||
import qualified Data.Text.Lazy.Encoding as TL
|
||||
import Data.Word
|
||||
|
||||
import Foreign.Storable ( pokeByteOff )
|
||||
|
||||
-- | This represents an operation on the terminal. Either an attribute change or the output of a
|
||||
-- text string.
|
||||
@ -157,9 +146,9 @@ spans_for_pic pic r = DisplayOps r $ Vector.create (build_spans pic r)
|
||||
--
|
||||
-- Crops to the given display region.
|
||||
build_spans :: Picture -> DisplayRegion -> ST s (MRowOps s)
|
||||
build_spans pic region = do
|
||||
build_spans pic out_region = do
|
||||
-- First we create a mutable vector for each rows output operations.
|
||||
mrow_ops <- Vector.replicate (region_height region) Vector.empty
|
||||
out_ops <- Vector.replicate (region_height out_region) Vector.empty
|
||||
-- \todo I think building the span operations in display order would provide better performance.
|
||||
-- However, I got stuck trying to implement an algorithm that did this. This will be considered
|
||||
-- as a possible future optimization.
|
||||
@ -171,29 +160,29 @@ build_spans pic region = do
|
||||
--
|
||||
-- The images are made into span operations from left to right. It's possible that this could
|
||||
-- easily be made to assure top to bottom output as well.
|
||||
when (region_height region > 0 && region_width region > 0) $ do
|
||||
when (region_height out_region > 0 && region_width out_region > 0) $ do
|
||||
-- The ops builder recursively descends the image and outputs span ops that would
|
||||
-- display that image. The number of columns remaining in this row before exceeding the
|
||||
-- bounds is also provided. This is used to clip the span ops produced to the display.
|
||||
let full_build = do
|
||||
start_image_build $ pic_image pic
|
||||
-- Fill in any unspecified columns with the background pattern.
|
||||
forM_ [0 .. (region_height region - 1)] add_row_completion
|
||||
init_env = BlitEnv (pic_background pic) region mrow_ops
|
||||
init_state = BlitState 0 0 0 0 (region_width region) (region_height region)
|
||||
forM_ [0 .. (region_height out_region - 1)] add_row_completion
|
||||
init_env = BlitEnv (pic_background pic) out_region out_ops
|
||||
init_state = BlitState 0 0 0 0 (region_width out_region) (region_height out_region)
|
||||
_ <- runStateT (runReaderT full_build init_env) init_state
|
||||
return ()
|
||||
return mrow_ops
|
||||
return out_ops
|
||||
|
||||
-- | Add the operations required to build a given image to the current set of row operations
|
||||
-- returns the number of columns and rows contributed to the output.
|
||||
start_image_build :: Image -> BlitM s ()
|
||||
start_image_build image = do
|
||||
out_of_bounds <- is_out_of_bounds image <$> get
|
||||
out_of_bounds <- is_out_of_bounds <$> get
|
||||
when (not out_of_bounds) $ add_maybe_clipped image
|
||||
|
||||
is_out_of_bounds :: Image -> BlitState -> Bool
|
||||
is_out_of_bounds image s
|
||||
is_out_of_bounds :: BlitState -> Bool
|
||||
is_out_of_bounds s
|
||||
| s ^. remaining_columns <= 0 = True
|
||||
| s ^. remaining_rows <= 0 = True
|
||||
| otherwise = False
|
||||
@ -334,6 +323,7 @@ clip_text txt left_skip right_clip =
|
||||
| w == cw = (n+1, False)
|
||||
| w > cw = clip_for_char_width (w - cw) (TL.tail t) (n + 1)
|
||||
where cw = safe_wcwidth (TL.head t)
|
||||
clip_for_char_width _ _ _ = error "clip_for_char_width applied to undefined"
|
||||
in txt''
|
||||
|
||||
add_unclipped_text :: DisplayText -> BlitM s ()
|
||||
|
@ -82,6 +82,9 @@ instance DisplayTerminal DebugDisplay where
|
||||
-- | Provide the current bounds of the output terminal.
|
||||
context_region d = debug_display_bounds d
|
||||
|
||||
-- | Assume 16 colors
|
||||
context_color_count d = 16
|
||||
|
||||
-- | A cursor move is always visualized as the single character 'M'
|
||||
move_cursor_required_bytes _d _x _y = 1
|
||||
|
||||
|
@ -10,12 +10,10 @@ import Graphics.Vty.DisplayRegion
|
||||
|
||||
import Verify
|
||||
|
||||
import Data.Word
|
||||
|
||||
data EmptyWindow = EmptyWindow DebugWindow
|
||||
|
||||
instance Arbitrary EmptyWindow where
|
||||
arbitrary = return $ EmptyWindow (DebugWindow (0 :: Word) (0 :: Word))
|
||||
arbitrary = return $ EmptyWindow (DebugWindow (0 :: Int) (0 :: Int))
|
||||
|
||||
instance Show EmptyWindow where
|
||||
show (EmptyWindow _) = "EmptyWindow"
|
||||
|
@ -11,8 +11,6 @@ import Graphics.Vty.Image
|
||||
|
||||
import Verify
|
||||
|
||||
import Data.Word
|
||||
|
||||
data UnitImage = UnitImage Char Image
|
||||
|
||||
instance Arbitrary UnitImage where
|
||||
@ -38,7 +36,7 @@ instance Arbitrary DefaultImage where
|
||||
data SingleRowSingleAttrImage
|
||||
= SingleRowSingleAttrImage
|
||||
{ expected_attr :: Attr
|
||||
, expected_columns :: Word
|
||||
, expected_columns :: Int
|
||||
, row_image :: Image
|
||||
}
|
||||
|
||||
@ -74,8 +72,8 @@ instance Arbitrary SingleRowTwoAttrImage where
|
||||
data SingleAttrSingleSpanStack = SingleAttrSingleSpanStack
|
||||
{ stack_image :: Image
|
||||
, stack_source_images :: [SingleRowSingleAttrImage]
|
||||
, stack_width :: Word
|
||||
, stack_height :: Word
|
||||
, stack_width :: Int
|
||||
, stack_height :: Int
|
||||
}
|
||||
deriving Show
|
||||
|
||||
|
@ -2,12 +2,11 @@
|
||||
module VerifyImageOps where
|
||||
|
||||
import Graphics.Vty.Attributes
|
||||
import Graphics.Vty.Image.Internal
|
||||
import Verify.Graphics.Vty.Image
|
||||
|
||||
import Verify
|
||||
|
||||
import Data.Word
|
||||
|
||||
two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
|
||||
two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
|
||||
image_width (char def_attr c1 <|> char def_attr c2) == 2
|
||||
@ -50,7 +49,7 @@ horiz_concat_dw_assoc (DoubleColumnChar c0) (DoubleColumnChar c1) (DoubleColumnC
|
||||
|
||||
vert_contat_single_row :: NonEmptyList SingleRowSingleAttrImage -> Bool
|
||||
vert_contat_single_row (NonEmpty stack) =
|
||||
let expected_height :: Word = fromIntegral $ length stack
|
||||
let expected_height :: Int = length stack
|
||||
stack_image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack ]
|
||||
in image_height stack_image == expected_height
|
||||
|
||||
@ -58,7 +57,7 @@ disjoint_height_horiz_join :: NonEmptyList SingleRowSingleAttrImage
|
||||
-> NonEmptyList SingleRowSingleAttrImage
|
||||
-> Bool
|
||||
disjoint_height_horiz_join (NonEmpty stack_0) (NonEmpty stack_1) =
|
||||
let expected_height :: Word = fromIntegral $ max (length stack_0) (length stack_1)
|
||||
let expected_height :: Int = max (length stack_0) (length stack_1)
|
||||
stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
|
||||
stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
|
||||
in image_height (stack_image_0 <|> stack_image_1) == expected_height
|
||||
|
@ -3,11 +3,13 @@ module VerifyImageTrans where
|
||||
|
||||
import Verify.Graphics.Vty.Image
|
||||
|
||||
import Graphics.Vty.Image.Internal
|
||||
|
||||
import Verify
|
||||
|
||||
import Data.Word
|
||||
|
||||
is_horiz_text_of_columns :: Image -> Word -> Bool
|
||||
is_horiz_text_of_columns :: Image -> Int -> Bool
|
||||
is_horiz_text_of_columns (HorizText { output_width = in_w }) expected_w = in_w == expected_w
|
||||
is_horiz_text_of_columns (BGFill { output_width = in_w }) expected_w = in_w == expected_w
|
||||
is_horiz_text_of_columns _image _expected_w = False
|
||||
|
30
vty.cabal
30
vty.cabal
@ -62,12 +62,13 @@ library
|
||||
Graphics.Vty.LLInput
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Terminal
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
|
||||
other-modules: Data.Marshalling
|
||||
Data.Terminfo.Parse
|
||||
Data.Terminfo.Eval
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal.Generic
|
||||
Graphics.Vty.Terminal.MacOSX
|
||||
@ -125,6 +126,7 @@ test-suite verify-using-mock-terminal
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal
|
||||
@ -132,7 +134,7 @@ test-suite verify-using-mock-terminal
|
||||
Graphics.Vty.Terminal.Debug
|
||||
Graphics.Vty.Debug
|
||||
Graphics.Vty.Debug.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.DisplayRegion
|
||||
@ -178,6 +180,7 @@ test-suite verify-display-attributes
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal
|
||||
@ -185,7 +188,7 @@ test-suite verify-display-attributes
|
||||
Graphics.Vty.Terminal.Debug
|
||||
Graphics.Vty.Debug
|
||||
Graphics.Vty.Debug.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.DisplayRegion
|
||||
@ -259,7 +262,7 @@ test-suite verify-eval-terminfo-caps
|
||||
other-modules: Data.Terminfo.Parse
|
||||
Data.Terminfo.Eval
|
||||
Data.Marshalling
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
|
||||
build-depends: Cabal == 1.17.*,
|
||||
@ -293,10 +296,11 @@ test-suite verify-image-ops
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Debug.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.Image
|
||||
@ -337,7 +341,8 @@ test-suite verify-image-trans
|
||||
other-modules: Graphics.Vty.Attributes
|
||||
Graphics.Vty.Debug.Image
|
||||
Graphics.Vty.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.Image
|
||||
@ -373,7 +378,7 @@ test-suite verify-inline
|
||||
|
||||
test-module: VerifyInline
|
||||
|
||||
other-modules: Codec.Binary.UTF8.Width
|
||||
other-modules: Graphics.Text.Width
|
||||
Data.Terminfo.Eval
|
||||
Data.Terminfo.Parse
|
||||
Data.Marshalling
|
||||
@ -381,7 +386,9 @@ test-suite verify-inline
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Inline
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal
|
||||
Graphics.Vty.Terminal.Generic
|
||||
@ -492,6 +499,7 @@ test-suite verify-picture-to-span
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal
|
||||
@ -499,7 +507,7 @@ test-suite verify-picture-to-span
|
||||
Graphics.Vty.Terminal.Debug
|
||||
Graphics.Vty.Debug
|
||||
Graphics.Vty.Debug.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.DisplayRegion
|
||||
@ -545,6 +553,7 @@ test-suite verify-span-ops
|
||||
Graphics.Vty.DisplayAttributes
|
||||
Graphics.Vty.DisplayRegion
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Graphics.Vty.Picture
|
||||
Graphics.Vty.Span
|
||||
Graphics.Vty.Terminal
|
||||
@ -552,7 +561,7 @@ test-suite verify-span-ops
|
||||
Graphics.Vty.Terminal.Debug
|
||||
Graphics.Vty.Debug
|
||||
Graphics.Vty.Debug.Image
|
||||
Codec.Binary.UTF8.Width
|
||||
Graphics.Text.Width
|
||||
Verify
|
||||
Verify.Graphics.Vty.Attributes
|
||||
Verify.Graphics.Vty.DisplayRegion
|
||||
@ -593,9 +602,10 @@ test-suite verify-utf8-width
|
||||
|
||||
test-module: VerifyUtf8Width
|
||||
|
||||
other-modules: Codec.Binary.UTF8.Width
|
||||
other-modules: Graphics.Text.Width
|
||||
Graphics.Vty.Attributes
|
||||
Graphics.Vty.Image
|
||||
Graphics.Vty.Image.Internal
|
||||
Verify
|
||||
|
||||
c-sources: cbits/mk_wcwidth.c
|
||||
|
Loading…
Reference in New Issue
Block a user