on master help sign in
rename DisplayRegion module to Prelude
commit4e45d7c0241726ed59b9e9836db7f257dfdc9bef authorCorey O'Connor <corey@ooyala.com> dateThu 19 Dec 2013, 22:24 (13 years ago) parentadf2e87
35 files changed+205−205
CHANGELOG+1 README.md−8 src/Graphics/Vty.hs+23−24 src/Graphics/Vty/Debug.hs+3−2 src/Graphics/Vty/DisplayRegion.hs−10 src/Graphics/Vty/Inline.hs+2−2 src/Graphics/Vty/Input.hs+5−5 src/Graphics/Vty/Terminal.hs → src/Graphics/Vty/Output.hs+21−25 src/Graphics/Vty/Terminal/Interface.hs → src/Graphics/Vty/Output/Interface.hs+16−12 src/Graphics/Vty/Terminal/MacOSX.hs → src/Graphics/Vty/Output/MacOSX.hs+8−11 src/Graphics/Vty/Terminal/Mock.hs → src/Graphics/Vty/Output/Mock.hs+8−10 src/Graphics/Vty/Terminal/TerminfoBased.hs → src/Graphics/Vty/Output/TerminfoBased.hs+13−13 src/Graphics/Vty/Terminal/XTermColor.hs → src/Graphics/Vty/Output/XTermColor.hs+5−5 src/Graphics/Vty/PictureToSpans.hs+3−4 src/Graphics/Vty/Prelude.hs+18 src/Graphics/Vty/Span.hs+4−5 test/BenchImageFuzz.hs+1−1 test/BenchNoDiffOpt.hs+1−1 test/BenchRenderChar.hs+2−2 test/BenchVerticalScroll.hs+1−1 test/Rouge.hs+1−1 test/Verify/Graphics/Vty/Terminal.hs → test/Verify/Graphics/Vty/Output.hs+2−2 test/Verify/Graphics/Vty/Picture.hs+2−1 test/Verify/Graphics/Vty/DisplayRegion.hs → test/Verify/Graphics/Vty/Prelude.hs+6−5 test/VerifyCropSpanGeneration.hs+2−1 test/VerifyEvalTerminfoCaps.hs+1−1 test/VerifyInline.hs+3−3 test/VerifyLayersSpanGeneration.hs+9−8 test/VerifyTerminal.hs → test/VerifyOutput.hs+3−3 test/VerifyParseTerminfoCaps.hs+1−1 test/VerifySimpleSpanGeneration.hs+3−2 test/VerifyUsingMockInput.hs+2−1 test/VerifyUsingMockTerminal.hs+11−10 test/interactive_terminal_test.hs+5−6 vty.cabal+19−19
CHANGELOG+1
@@ -1,6 +1,7 @@
115.0.0
22 * removed the typeclass based terminal and display context interface in favor of a data
33 structure of properties interface.
4+ * renamed the Terminal interface to Output
45 * The default picture for an image now uses the "clear" background. This background fills
56 background spans with spaces or just ends the line.
67 * Previously the background defaulted to the space character. This causes issues copying
README.md−8
@@ -76,11 +76,3 @@ rm -rf dist ; cabal configure --enable-tests --disable-library-coverage \
7676 --enable-library-profiling \
7777 --enable-executable-profiling
7878~~~
79−
80−# References
81−
82−* https://github.com/b4winckler/vim/blob/master/src/term.c
83−* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
84−* http://ulisse.elettra.trieste.it/services/doc/serial/config.html
85−* http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html
86−* http://www.unixwiz.net/techtips/termios-vmin-vtime.html
src/Graphics/Vty.hs+23−24
@@ -1,17 +1,22 @@
1−-- Copyright 2009-2010 Corey O'Connor
2−{-# LANGUAGE ForeignFunctionInterface, BangPatterns, UnboxedTuples #-}
3−{-# CFILES gwinsz.c #-}
4−
1+-- | Vty supports input and output to terminal devices. The input is provides as a sequence of
2+-- 'Event's. The output is defined by a 'Picture'. Which is one or more layers of 'Image's.
3+--
4+-- - References
5+--
56-- Good sources of documentation for terminal programming are:
6−-- vt100 control sequences: http://vt100.net/docs/vt100-ug/chapter3.html#S3.3.3
7−-- Xterm control sequences: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
8−
7+--
8+-- - <https://github.com/b4winckler/vim/blob/master/src/term.c>
9+-- - <http://invisible-island.net/xterm/ctlseqs/ctlseqs.html>
10+-- - <http://ulisse.elettra.trieste.it/services/doc/serial/config.html>
11+-- - <http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html>
12+-- - <http://www.unixwiz.net/techtips/termios-vmin-vtime.html>
13+-- - <<http://vt100.net/docs/vt100-ug/chapter3.html vt100 control sequences>
914module Graphics.Vty ( Vty(..)
1015 , mkVty
1116 , mkVtyEscDelay
12− , module Graphics.Vty.Terminal
17+ , module Graphics.Vty.Output
1318 , module Graphics.Vty.Picture
14− , module Graphics.Vty.DisplayRegion
19+ , DisplayRegion
1520 , Key(..)
1621 , Modifier(..)
1722 , Button(..)
@@ -19,11 +24,11 @@ module Graphics.Vty ( Vty(..)
1924 )
2025 where
2126
27+import Graphics.Vty.Prelude
2228
23−import Graphics.Vty.Terminal
24−import Graphics.Vty.Picture
25−import Graphics.Vty.DisplayRegion
2629import Graphics.Vty.Input
30+import Graphics.Vty.Output
31+import Graphics.Vty.Picture
2732
2833import Data.IORef
2934
@@ -35,9 +40,6 @@ import qualified System.Console.Terminfo as Terminfo
3540--
3641-- This does not assure any thread safety. In theory, as long as an update action is not executed
3742-- when another update action is already then it's safe to call this on multiple threads.
38−--
39−-- todo: Once the Terminal interface encompasses input this interface will be deprecated.
40−-- Currently, just using the Terminal interface there is no support for input events.
4143data Vty = Vty
4244 { -- | Outputs the given Picture. Equivalent to output_picture applied to a display context
4345 -- implicitly managed by Vty.
@@ -56,11 +58,11 @@ data Vty = Vty
5658 --
5759 -- 3. shutdown vty.
5860 --
59− -- todo: provide a similar abstraction to Graphics.Vty.Terminal for input. Use haskeline's
61+ -- todo: provide a similar abstraction to Graphics.Vty.Output for input. Use haskeline's
6062 -- input backend for implementation.
6163 --
6264 -- todo: remove explicit `shutdown` requirement.
63− , terminal :: Terminal
65+ , terminal :: Output
6466 -- | Refresh the display. Normally the library takes care of refreshing. Nonetheless, some
6567 -- other program might output to the terminal and mess the display. In that case the user
6668 -- might want to force a refresh.
@@ -87,15 +89,14 @@ mkVtyEscDelay escDelay = do
8789 (kvar, endi) <- initTermInput escDelay term_info
8890 intMkVty kvar ( endi >> release_display t >> release_terminal t ) t
8991
90−intMkVty :: IO Event -> IO () -> Terminal -> IO Vty
92+intMkVty :: IO Event -> IO () -> Output -> IO Vty
9193intMkVty kvar fend t = do
9294 last_pic_ref <- newIORef Nothing
9395 last_update_ref <- newIORef Nothing
9496
9597 let inner_update in_pic = do
96− b <- display_bounds t
97− let DisplayRegion w h = b
98− cursor = pic_cursor in_pic
98+ b@(w,h) <- display_bounds t
99+ let cursor = pic_cursor in_pic
99100 in_pic' = case cursor of
100101 Cursor x y ->
101102 let
@@ -136,9 +137,7 @@ intMkVty kvar fend t = do
136137 case k of
137138 (EvResize _ _) -> inner_refresh
138139 >> display_bounds t
139− >>= return . ( \(DisplayRegion w h)
140− -> EvResize (fromEnum w) (fromEnum h)
141− )
140+ >>= return . (\(w,h)-> EvResize w h)
142141 _ -> return k
143142
144143 return $ Vty { update = inner_update
src/Graphics/Vty/Debug.hs+3−2
@@ -4,10 +4,11 @@ module Graphics.Vty.Debug ( module Graphics.Vty.Debug
44 )
55where
66
7+import Graphics.Vty.Prelude
8+
79import Graphics.Vty.Attributes
810import Graphics.Vty.Debug.Image
911import Graphics.Vty.Span
10−import Graphics.Vty.DisplayRegion
1112
1213import qualified Data.Vector as Vector
1314
@@ -35,5 +36,5 @@ data MockWindow = MockWindow Int Int
3536 deriving (Show, Eq)
3637
3738region_for_window :: MockWindow -> DisplayRegion
38−region_for_window (MockWindow w h) = DisplayRegion w h
39+region_for_window (MockWindow w h) = (w,h)
3940
src/Graphics/Vty/DisplayRegion.hsdeleted−10
@@ -1,10 +0,0 @@
1−-- Copyright 2009 Corey O'Connor
2−module Graphics.Vty.DisplayRegion
3− where
4−
5−-- | Region of the terminal that vty will output to. Units are columns not characters.
6−data DisplayRegion = DisplayRegion
7− { region_width :: !Int
8− , region_height :: !Int
9− } deriving ( Show, Eq )
10−
src/Graphics/Vty/Inline.hs+2−2
@@ -33,7 +33,7 @@ module Graphics.Vty.Inline ( module Graphics.Vty.Inline
3333import Graphics.Vty
3434import Graphics.Vty.DisplayAttributes
3535import Graphics.Vty.Inline.Unsafe
36−import Graphics.Vty.Terminal.Interface
36+import Graphics.Vty.Output.Interface
3737
3838import Control.Applicative
3939import Control.Monad.State.Strict
@@ -79,7 +79,7 @@ default_all = put def_attr
7979-- | Apply the provided display attribute changes to the given terminal.
8080--
8181-- This does not flush the terminal.
82−put_attr_change :: ( Applicative m, MonadIO m ) => Terminal -> InlineM () -> m ()
82+put_attr_change :: ( Applicative m, MonadIO m ) => Output -> InlineM () -> m ()
8383put_attr_change t c = liftIO $ do
8484 bounds <- display_bounds t
8585 dc <- display_context t bounds
src/Graphics/Vty/Input.hs+5−5
@@ -56,19 +56,19 @@ defaultEscDelay = 10000
5656-- - disables software flow control on outgoing data. This stops the process from being
5757-- suspended if the output terminal cannot keep up. I presume this has little effect these
5858-- days. I hope this means that output will be buffered if the terminal cannot keep up. In the
59−-- ol days the output might of been dropped.
59+-- old days the output might of been dropped.
6060--
6161-- "raw" mode is used for input.
6262--
6363-- * ISIG disabled
64−-- - enables keyboard combinations that result in signals. People would probably want this to
65−-- be an option.
64+-- - enables keyboard combinations that result in signals. This should probably be a dynamic
65+-- option.
6666--
6767-- * ECHO disabled
68−-- - input is not echod to the output.
68+-- - input is not echod to the output. Pobably should be a dynamic option.
6969--
7070-- * ICANON disabled
71−-- - canonical mode (line mode) input is not used.
71+-- - canonical mode (line mode) input is not used. Probably should be a dynamic option.
7272--
7373-- * IEXTEN disabled
7474-- - extended functions are disabled. Uh. Whatever these are.
src/Graphics/Vty/Terminal.hs → src/Graphics/Vty/Output.hsrenamed+21−25
@@ -1,25 +1,25 @@
1−-- | Terminal IO device.
1+-- | Output interface.
22--
33-- Access to the current terminal or a specific terminal device.
44--
55-- See also:
66--
7−-- 1. Graphics.Vty.Terminal: This instantiates an abtract interface to the terminal interface based
7+-- 1. "Graphics.Vty.Output": This instantiates an abtract interface to the terminal interface based
88-- on the TERM and COLORTERM environment variables.
99--
10−-- 2. Graphics.Vty.Terminal.Interface: Defines the generic interface all terminals need to implement.
10+-- 2. Graphics.Vty.Output.Interface: Defines the generic interface all terminals need to implement.
1111--
12−-- 3. Graphics.Vty.Terminal.TerminfoBased: Defines a terminal instance that uses terminfo for all
12+-- 3. Graphics.Vty.Output.TerminfoBased: Defines a terminal instance that uses terminfo for all
1313-- control strings. No attempt is made to change the character set to UTF-8 for these terminals.
1414-- I don't know a way to reliably determine if that is required or how to do so.
1515--
16−-- 4. Graphics.Vty.Terminal.XTermColor: This module contains an interface suitable for xterm-like
16+-- 4. Graphics.Vty.Output.XTermColor: This module contains an interface suitable for xterm-like
1717-- terminals. These are the terminals where TERM == xterm. This does use terminfo for as many
1818-- control codes as possible.
1919--
2020-- Copyright 2009-2010 Corey O'Connor
21−module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
22− , Terminal(..) -- \todo hide constructors
21+module Graphics.Vty.Output ( module Graphics.Vty.Output
22+ , Output(..) -- \todo hide constructors
2323 , AssumedState(..)
2424 , DisplayContext(..) -- \todo hide constructors
2525 , output_picture
@@ -28,15 +28,14 @@ module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
2828 where
2929
3030
31−import Graphics.Vty.DisplayRegion
32−import Graphics.Vty.Terminal.Interface
33−import Graphics.Vty.Terminal.MacOSX as MacOSX
34−import Graphics.Vty.Terminal.XTermColor as XTermColor
35−import Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
31+import Graphics.Vty.Prelude
32+
33+import Graphics.Vty.Output.Interface
34+import Graphics.Vty.Output.MacOSX as MacOSX
35+import Graphics.Vty.Output.XTermColor as XTermColor
36+import Graphics.Vty.Output.TerminfoBased as TerminfoBased
3637
37−import Control.Applicative
3838import Control.Exception ( SomeException, try )
39−import Control.Monad
4039import Control.Monad.Trans
4140
4241import Data.List ( isPrefixOf )
@@ -46,9 +45,9 @@ import GHC.IO.Handle
4645import System.Environment
4746import System.IO
4847
49−-- | Returns a `Terminal` for the current terminal.
48+-- | Returns a `Output` for the current terminal.
5049--
51−-- The specific Terminal implementation used is hidden from the API user. All terminal
50+-- The specific Output implementation used is hidden from the API user. All terminal
5251-- implementations are assumed to perform more, or less, the same. Currently all implementations use
5352-- terminfo for at least some terminal specific information. This is why platforms without terminfo
5453-- are not supported. However, as mentioned before, any specifics about it being based on terminfo
@@ -80,16 +79,14 @@ import System.IO
8079-- The file descriptor used for output will a duplicate of the current stdout file descriptor.
8180--
8281-- todo: add an implementation for windows that does not depend on terminfo. Should be installable
83−-- with only what is provided in the haskell platform.
84−--
85−-- todo: The Terminal interface does not provide any input support.
86−current_terminal :: ( Applicative m, MonadIO m ) => m Terminal
82+-- with only what is provided in the haskell platform. Use ansi-terminal
83+current_terminal :: ( Applicative m, MonadIO m ) => m Output
8784current_terminal = do
8885 term_type <- liftIO $ getEnv "TERM"
8986 out_handle <- liftIO $ hDuplicate stdout
9087 terminal_with_name_and_io term_type out_handle
9188
92−terminal_with_name_and_io :: (Applicative m, MonadIO m) => String -> Handle -> m Terminal
89+terminal_with_name_and_io :: (Applicative m, MonadIO m) => String -> Handle -> m Output
9390terminal_with_name_and_io term_type out_handle = do
9491 t <- if "xterm" `isPrefixOf` term_type
9592 then do
@@ -123,7 +120,7 @@ terminal_with_name_and_io term_type out_handle = do
123120--
124121-- Currently, the only way to set the cursor position to a given character coordinate is to specify
125122-- the coordinate in the Picture instance provided to output_picture or refresh.
126−set_cursor_pos :: MonadIO m => Terminal -> Int -> Int -> m ()
123+set_cursor_pos :: MonadIO m => Output -> Int -> Int -> m ()
127124set_cursor_pos t x y = do
128125 bounds <- display_bounds t
129126 when (x >= 0 && x < region_width bounds && y >= 0 && y < region_height bounds) $ do
@@ -131,16 +128,15 @@ set_cursor_pos t x y = do
131128 liftIO $ send_to_terminal t (move_cursor_required_bytes dc x y) (serialize_move_cursor dc x y)
132129
133130-- | Hides the cursor
134−hide_cursor :: MonadIO m => Terminal -> m ()
131+hide_cursor :: MonadIO m => Output -> m ()
135132hide_cursor t = do
136133 bounds <- display_bounds t
137134 dc <- display_context t bounds
138135 liftIO $ send_to_terminal t (hide_cursor_required_bytes dc) (serialize_hide_cursor dc)
139136
140137-- | Shows the cursor
141−show_cursor :: MonadIO m => Terminal -> m ()
138+show_cursor :: MonadIO m => Output -> m ()
142139show_cursor t = do
143140 bounds <- display_bounds t
144141 dc <- display_context t bounds
145142 liftIO $ send_to_terminal t (show_cursor_required_bytes dc) (serialize_show_cursor dc)
146−
src/Graphics/Vty/Terminal/Interface.hs → src/Graphics/Vty/Output/Interface.hsrenamed+16−12
@@ -5,17 +5,18 @@
55{-# LANGUAGE ExistentialQuantification #-}
66{-# LANGUAGE GADTs #-}
77{-# LANGUAGE FlexibleContexts #-}
8−module Graphics.Vty.Terminal.Interface ( module Graphics.Vty.Terminal.Interface
9− , OutputBuffer
10− )
8+module Graphics.Vty.Output.Interface ( module Graphics.Vty.Output.Interface
9+ , OutputBuffer
10+ )
1111 where
1212
13+import Graphics.Vty.Prelude
14+
1315import Data.Marshalling
1416
1517import Graphics.Vty.Picture
1618import Graphics.Vty.PictureToSpans
1719import Graphics.Vty.Span
18−import Graphics.Vty.DisplayRegion
1920
2021import Graphics.Vty.DisplayAttributes
2122
@@ -27,19 +28,22 @@ import qualified Data.Text.Lazy as TL
2728import Data.IORef
2829import qualified Data.Vector as Vector
2930
30−data Terminal = Terminal
31− { -- | Text identifier for the terminal. Used for debugging.
31+data Output = Output
32+ { -- | Text identifier for the output device. Used for debugging.
3233 terminal_ID :: String
3334 , release_terminal :: MonadIO m => m ()
3435 -- | Clear the display and initialize the terminal to some initial display state.
3536 --
3637 -- The expectation of a program is that the display starts in some initial state.
3738 -- The initial state would consist of fixed values:
39+ --
3840 -- - cursor at top left
3941 -- - UTF-8 character encoding
4042 -- - drawing characteristics are the default
43+ --
4144 -- The abstract operation I think all these behaviors are instances of is reserving exclusive
4245 -- access to a display such that:
46+ --
4347 -- - The previous state cannot be determined
4448 -- - When exclusive access to a display is released the display returns to the previous state.
4549 , reserve_display :: MonadIO m => m ()
@@ -59,10 +63,10 @@ data Terminal = Terminal
5963 -- | Acquire display access to the given region of the display.
6064 -- Currently all regions have the upper left corner of (0,0) and the lower right corner at
6165 -- (max display_width provided_width, max display_height provided_height)
62− , mk_display_context :: MonadIO m => Terminal -> DisplayRegion -> m DisplayContext
66+ , mk_display_context :: MonadIO m => Output -> DisplayRegion -> m DisplayContext
6367 }
6468
65−display_context :: MonadIO m => Terminal -> DisplayRegion -> m DisplayContext
69+display_context :: MonadIO m => Output -> DisplayRegion -> m DisplayContext
6670display_context t = liftIO . mk_display_context t t
6771
6872data AssumedState = AssumedState
@@ -74,7 +78,7 @@ initial_assumed_state :: AssumedState
7478initial_assumed_state = AssumedState Nothing Nothing
7579
7680data DisplayContext = DisplayContext
77− { context_device :: Terminal
81+ { context_device :: Output
7882 -- | Provide the bounds of the display context.
7983 , context_region :: DisplayRegion
8084 -- | sets the output position to the specified row and column. Where the number of bytes
@@ -103,7 +107,7 @@ data DisplayContext = DisplayContext
103107 , serialize_default_attr :: OutputBuffer -> IO OutputBuffer
104108 , row_end_required_bytes :: Int
105109 , serialize_row_end :: OutputBuffer -> IO OutputBuffer
106− -- | See Graphics.Vty.Terminal.XTermColor.inline_hack
110+ -- | See Graphics.Vty.Output.XTermColor.inline_hack
107111 , inline_hack :: IO ()
108112 }
109113
@@ -273,7 +277,7 @@ serialize_span_op dc (RowEnd _) out_ptr fattr = do
273277 out_ptr' <- serialize_row_end dc out_ptr
274278 return (out_ptr', fattr)
275279
276−send_to_terminal :: Terminal -> Int -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
280+send_to_terminal :: Output -> Int -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
277281send_to_terminal t c f = allocaBytes (fromEnum c) $ \start_ptr -> do
278282 end_ptr <- f start_ptr
279283 case end_ptr `minusPtr` start_ptr of
@@ -319,7 +323,7 @@ cursor_column_offset ops cx cy =
319323
320324-- | Not all terminals support all display attributes. This filters a display attribute to what the
321325-- given terminal can display.
322−limit_attr_for_display :: Terminal -> Attr -> Attr
326+limit_attr_for_display :: Output -> Attr -> Attr
323327limit_attr_for_display t attr
324328 = attr { attr_fore_color = clamp_color $ attr_fore_color attr
325329 , attr_back_color = clamp_color $ attr_back_color attr
src/Graphics/Vty/Terminal/MacOSX.hs → src/Graphics/Vty/Output/MacOSX.hsrenamed+8−11
@@ -8,11 +8,11 @@
88{-# LANGUAGE MagicHash #-}
99{-# LANGUAGE FlexibleInstances #-}
1010{-# LANGUAGE TypeFamilies #-}
11−module Graphics.Vty.Terminal.MacOSX ( reserve_terminal )
11+module Graphics.Vty.Output.MacOSX ( reserve_terminal )
1212 where
1313
14−import Graphics.Vty.Terminal.Interface
15−import qualified Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
14+import Graphics.Vty.Output.Interface
15+import qualified Graphics.Vty.Output.TerminfoBased as TerminfoBased
1616
1717import Control.Applicative
1818import Control.Monad.Trans
@@ -23,7 +23,7 @@ import System.IO
2323-- "xterm-256color" is used.
2424--
2525-- This effects the terminfo lookup.
26−reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Terminal
26+reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Output
2727reserve_terminal v out_handle = do
2828 let remap_term "iTerm.app" = "xterm-256color"
2929 remap_term _ = "xterm"
@@ -32,13 +32,10 @@ reserve_terminal v out_handle = do
3232 hPutStr out_handle str
3333 hFlush out_handle
3434 t <- TerminfoBased.reserve_terminal (remap_term v) out_handle
35− let t' = t
36− { terminal_ID = terminal_ID t ++ " (Mac)"
37− , reserve_display = terminal_app_reserve_display flushed_put
38− , release_display = terminal_app_release_display flushed_put
39− }
40− return t'
41−
35+ return $ t { terminal_ID = terminal_ID t ++ " (Mac)"
36+ , reserve_display = terminal_app_reserve_display flushed_put
37+ , release_display = terminal_app_release_display flushed_put
38+ }
4239
4340-- | Terminal.app requires the xterm-color smcup and rmcup caps. Not the generic xterm ones.
4441-- Otherwise, Terminal.app expects the xterm caps.
src/Graphics/Vty/Terminal/Mock.hs → src/Graphics/Vty/Output/Mock.hsrenamed+8−10
@@ -3,13 +3,13 @@
33{-# LANGUAGE TypeFamilies #-}
44-- | This provides a mock terminal implementation that is nice for testing. This transforms the
55-- output operations to visible characters. Which is nice for some tests.
6−module Graphics.Vty.Terminal.Mock ( MockData, mock_terminal )
6+module Graphics.Vty.Output.Mock ( MockData, mock_terminal )
77 where
88
9−import Graphics.Vty.DisplayRegion
10−import Graphics.Vty.Terminal.Interface
9+import Graphics.Vty.Prelude
10+
11+import Graphics.Vty.Output.Interface
1112
12−import Control.Applicative
1313import Control.Monad.Trans
1414
1515import qualified Data.ByteString as BS
@@ -32,15 +32,13 @@ type MockData = IORef (UTF8.UTF8 BS.ByteString)
3232-- parsing the text representation and determining how the picture was mapped to terminal
3333-- operations.
3434--
35−-- All terminals support the operations specified in the Terminal class defined in
36−-- Graphics.Vty.Terminal. As an instance of the Terminal class is also an instance of the Monad
37−-- class there exists a monoid that defines it's algebra. The string representation is a sequence of
38−-- identifiers where each identifier is the name of an operation in the algebra.
39−mock_terminal :: (Applicative m, MonadIO m) => DisplayRegion -> m (MockData, Terminal)
35+-- The string representation is a sequence of identifiers where each identifier is the name of an
36+-- operation in the algebra.
37+mock_terminal :: (Applicative m, MonadIO m) => DisplayRegion -> m (MockData, Output)
4038mock_terminal r = liftIO $ do
4139 out_ref <- newIORef undefined
4240 new_assumed_state_ref <- newIORef initial_assumed_state
43− let t = Terminal
41+ let t = Output
4442 { terminal_ID = "mock terminal"
4543 , release_terminal = return ()
4644 , reserve_display = return ()
src/Graphics/Vty/Terminal/TerminfoBased.hs → src/Graphics/Vty/Output/TerminfoBased.hsrenamed+13−13
@@ -7,19 +7,19 @@
77-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
88{-# LANGUAGE FlexibleInstances #-}
99{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
10−module Graphics.Vty.Terminal.TerminfoBased ( reserve_terminal )
10+{-# CFILES gwinsz.c #-}
11+module Graphics.Vty.Output.TerminfoBased ( reserve_terminal )
1112 where
1213
14+import Graphics.Vty.Prelude
15+
1316import Data.Terminfo.Parse
1417import Data.Terminfo.Eval
1518
1619import Graphics.Vty.Attributes
1720import Graphics.Vty.DisplayAttributes
18−import Graphics.Vty.Terminal.Interface
19−import Graphics.Vty.DisplayRegion
21+import Graphics.Vty.Output.Interface
2022
21−import Control.Applicative
22−import Control.Monad ( foldM, when )
2323import Control.Monad.Trans
2424
2525import Data.Bits ( (.&.) )
@@ -59,7 +59,7 @@ data DisplayAttrCaps = DisplayAttrCaps
5959 , enter_bold_mode :: Maybe CapExpression
6060 }
6161
62−send_cap_to_terminal :: Terminal -> CapExpression -> [CapParam] -> IO ()
62+send_cap_to_terminal :: Output -> CapExpression -> [CapParam] -> IO ()
6363send_cap_to_terminal t cap cap_params = do
6464 send_to_terminal t (cap_expression_required_bytes cap cap_params)
6565 (serialize_cap_expression cap cap_params)
@@ -74,7 +74,7 @@ send_cap_to_terminal t cap cap_params = do
7474 - todo: Some display attributes like underline and bold have independent string capabilities that
7575 - should be used instead of the generic "sgr" string capability.
7676 -}
77−reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Terminal
77+reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Output
7878reserve_terminal in_ID out_handle = liftIO $ do
7979 ti <- Terminfo.setupTerm in_ID
8080 -- assumes set foreground always implies set background exists.
@@ -110,7 +110,7 @@ reserve_terminal in_ID out_handle = liftIO $ do
110110 <*> require_cap ti "el"
111111 <*> current_display_attr_caps ti
112112 new_assumed_state_ref <- newIORef initial_assumed_state
113− let t = Terminal
113+ let t = Output
114114 { terminal_ID = in_ID
115115 , release_terminal = liftIO $ do
116116 send_cap set_default_attr []
@@ -129,7 +129,7 @@ reserve_terminal in_ID out_handle = liftIO $ do
129129 raw_size <- liftIO $ get_window_size
130130 case raw_size of
131131 (w, h) | w < 0 || h < 0 -> fail $ "getwinsize returned < 0 : " ++ show raw_size
132− | otherwise -> return $ DisplayRegion (toEnum w) (toEnum h)
132+ | otherwise -> return (w,h)
133133 , output_byte_buffer = \out_ptr out_byte_count -> do
134134 hPutBuf out_handle out_ptr (fromEnum out_byte_count)
135135 hFlush out_handle
@@ -189,7 +189,7 @@ get_window_size = do
189189 (a,b) <- (`divMod` 65536) `fmap` c_get_window_size
190190 return (fromIntegral b, fromIntegral a)
191191
192−terminfo_display_context :: Terminal -> TerminfoCaps -> DisplayRegion -> IO DisplayContext
192+terminfo_display_context :: Output -> TerminfoCaps -> DisplayRegion -> IO DisplayContext
193193terminfo_display_context t_actual terminfo_caps r =
194194 let dc = DisplayContext
195195 { context_device = t_actual
@@ -461,8 +461,8 @@ style_to_apply_seq s = concat
461461 , apply_if_required ApplyBlink bold
462462 ]
463463 where
464− apply_if_required ap flag
465− = if 0 == ( flag .&. s )
464+ apply_if_required op flag
465+ = if 0 == (flag .&. s)
466466 then []
467− else [ ap ]
467+ else [op]
468468
src/Graphics/Vty/Terminal/XTermColor.hs → src/Graphics/Vty/Output/XTermColor.hsrenamed+5−5
@@ -1,9 +1,9 @@
11-- Copyright 2009-2010 Corey O'Connor
2−module Graphics.Vty.Terminal.XTermColor ( reserve_terminal )
2+module Graphics.Vty.Output.XTermColor ( reserve_terminal )
33 where
44
5−import Graphics.Vty.Terminal.Interface
6−import qualified Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
5+import Graphics.Vty.Output.Interface
6+import qualified Graphics.Vty.Output.TerminfoBased as TerminfoBased
77
88import Control.Applicative
99import Control.Monad.Trans
@@ -14,7 +14,7 @@ import qualified Data.Text.Encoding as T
1414import System.IO
1515
1616-- | Initialize the display to UTF-8.
17−reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Terminal
17+reserve_terminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Output
1818reserve_terminal variant out_handle = liftIO $ do
1919 let flushed_put str = do
2020 hPutStr out_handle str
@@ -45,7 +45,7 @@ set_default_char_set = "\ESC%@"
4545-- | I think xterm is broken: Reseting the background color as the first bytes serialized on a
4646-- new line does not effect the background color xterm uses to clear the line. Which is used
4747-- *after* the next newline.
48−xterm_inline_hack :: Terminal -> IO ()
48+xterm_inline_hack :: Output -> IO ()
4949xterm_inline_hack t = do
5050 let s_utf8 = T.encodeUtf8 $ T.pack "\ESC[K"
5151 send_to_terminal t (utf8_text_required_bytes s_utf8)
src/Graphics/Vty/PictureToSpans.hs+3−4
@@ -8,13 +8,13 @@
88 -}
99module Graphics.Vty.PictureToSpans where
1010
11−import Graphics.Vty.DisplayRegion
11+import Graphics.Vty.Prelude
12+
1213import Graphics.Vty.Image
1314import Graphics.Vty.Image.Internal
1415import Graphics.Vty.Picture
1516import Graphics.Vty.Span
1617
17−import Control.Applicative
1818import Control.Lens hiding ( op )
1919import Control.Monad.Reader
2020import Control.Monad.State.Strict hiding ( state )
@@ -71,8 +71,7 @@ display_ops_for_pic pic r = Vector.create (combined_ops_for_layers pic r)
7171--
7272-- largerly used only for debugging.
7373display_ops_for_image :: Image -> DisplayOps
74−display_ops_for_image i = display_ops_for_pic (pic_for_image i)
75− (DisplayRegion (image_width i) (image_height i))
74+display_ops_for_image i = display_ops_for_pic (pic_for_image i) (image_width i, image_height i)
7675
7776-- | Produces the span ops for each layer then combines them.
7877--
src/Graphics/Vty/Prelude.hsnew file+18
@@ -0,0 +1,18 @@
1+-- | Prelude for Vty modules. Not particularly useful outside of Vty.
2+module Graphics.Vty.Prelude ( module Graphics.Vty.Prelude
3+ , module Control.Applicative
4+ , module Control.Monad
5+ )
6+where
7+
8+import Control.Applicative hiding ((<|>))
9+import Control.Monad
10+
11+-- | Named alias for a Int pair
12+type DisplayRegion = (Int,Int)
13+
14+region_width :: DisplayRegion -> Int
15+region_width = fst
16+
17+region_height :: DisplayRegion -> Int
18+region_height = snd
src/Graphics/Vty/Span.hs+4−5
@@ -16,16 +16,15 @@
1616module Graphics.Vty.Span
1717 where
1818
19−import Graphics.Vty.DisplayRegion
20−import Graphics.Vty.Image
19+import Graphics.Vty.Prelude
2120
21+import Graphics.Vty.Image
2222import Graphics.Vty.Image.Internal ( clip_text )
2323
24+import qualified Data.Text.Lazy as TL
2425import Data.Vector (Vector)
2526import qualified Data.Vector as Vector
2627
27−import qualified Data.Text.Lazy as TL
28−
2928-- | This represents an operation on the terminal. Either an attribute change or the output of a
3029-- text string.
3130data SpanOp =
@@ -112,7 +111,7 @@ display_ops_rows :: DisplayOps -> Int
112111display_ops_rows ops = Vector.length ops
113112
114113effected_region :: DisplayOps -> DisplayRegion
115−effected_region ops = DisplayRegion (display_ops_columns ops) (display_ops_rows ops)
114+effected_region ops = (display_ops_columns ops, display_ops_rows ops)
116115
117116-- | The number of columns a SpanOps effects.
118117span_ops_effected_columns :: SpanOps -> Int
test/BenchImageFuzz.hs+1−1
@@ -20,7 +20,7 @@ random_picture = pic_for_image <$> random_image
2020
2121bench_0 = do
2222 vty <- mkVty
23− DisplayRegion w h <- display_bounds $ terminal vty
23+ (w,h) <- display_bounds $ terminal vty
2424 let pictures = replicateM 3000 random_picture
2525 bench ps = do
2626 forM ps (update vty)
test/BenchNoDiffOpt.hs+1−1
@@ -19,7 +19,7 @@ bench_0 = do
1919 let fixed_gen = mkStdGen 0
2020 setStdGen fixed_gen
2121 vty <- mkVty
22− DisplayRegion w h <- display_bounds $ terminal vty
22+ (w,h) <- display_bounds $ terminal vty
2323 let images = return $ (image_0, image_1)
2424 image_0 = char_fill def_attr 'X' w h
2525 image_1 = char_fill def_attr '0' w h
test/BenchRenderChar.hs+2−2
@@ -11,7 +11,7 @@ import Control.Monad ( forM_ )
1111
1212bench_0 = do
1313 vty <- mkVty
14− DisplayRegion w h <- display_bounds $ terminal vty
14+ (w,h) <- display_bounds $ terminal vty
1515 let test_chars = return $ take 500 $ cycle $ [ c | c <- ['a'..'z']]
1616 bench d = do
1717 forM_ d $ \test_char -> do
@@ -27,7 +27,7 @@ test_image_using_char c w h
2727
2828bench_1 = do
2929 vty <- mkVty
30− DisplayRegion w h <- display_bounds $ terminal vty
30+ (w,h) <- display_bounds $ terminal vty
3131 let test_chars = return $ take 500 $ cycle $ [ c | c <- ['a'..'z']]
3232 bench d = do
3333 forM_ d $ \test_char -> do
test/BenchVerticalScroll.hs+1−1
@@ -53,7 +53,7 @@ clines g maxll = map (pad maxll . horiz_cat . map (uncurry string))
5353 where (g1,g2) = split g
5454
5555benchgen :: DisplayRegion -> [Picture]
56−benchgen (DisplayRegion w h)
56+benchgen (w,h)
5757 = take 2000 $ map ((\i -> pic_for_image i) . vert_cat . take (fromEnum h))
5858 $ tails
5959 $ clines (mkStdGen 80) w
test/Rouge.hs+1−1
@@ -116,7 +116,7 @@ update_display :: Game ()
116116update_display = do
117117 let info = string def_attr "Move with the arrows keys. Press ESC to exit."
118118 -- determine offsets to place the dude in the center of the level.
119− DisplayRegion w h <- asks terminal >>= liftIO . display_bounds
119+ (w,h) <- asks terminal >>= liftIO . display_bounds
120120 the_dude <- gets dude
121121 let ox = (w `div` 2) - dude_x the_dude
122122 oy = (h `div` 2) - dude_y the_dude
test/Verify/Graphics/Vty/Terminal.hs → test/Verify/Graphics/Vty/Output.hsrenamed+2−2
@@ -1,6 +1,6 @@
1−module Verify.Graphics.Vty.Terminal where
1+module Verify.Graphics.Vty.Output where
22
3−import Graphics.Vty.Terminal.Mock
3+import Graphics.Vty.Output.Mock
44
55import qualified Data.ByteString as BS
66import Data.IORef
test/Verify/Graphics/Vty/Picture.hs+2−1
@@ -4,12 +4,13 @@ module Verify.Graphics.Vty.Picture ( module Verify.Graphics.Vty.Picture
44 )
55 where
66
7+import Verify.Graphics.Vty.Prelude
8+
79import Graphics.Vty.Picture
810import Graphics.Vty.Debug
911
1012import Verify.Graphics.Vty.Attributes
1113import Verify.Graphics.Vty.Image
12−import Verify.Graphics.Vty.DisplayRegion
1314
1415import Verify
1516
test/Verify/Graphics/Vty/DisplayRegion.hs → test/Verify/Graphics/Vty/Prelude.hsrenamed+6−5
@@ -1,11 +1,12 @@
1−module Verify.Graphics.Vty.DisplayRegion ( module Verify.Graphics.Vty.DisplayRegion
2− , module Graphics.Vty.DisplayRegion
3− , MockWindow(..)
4− )
1+module Verify.Graphics.Vty.Prelude ( module Verify.Graphics.Vty.Prelude
2+ , module Graphics.Vty.Prelude
3+ , MockWindow(..)
4+ )
55 where
66
7+import Graphics.Vty.Prelude
8+
79import Graphics.Vty.Debug
8−import Graphics.Vty.DisplayRegion
910
1011import Verify
1112
test/VerifyCropSpanGeneration.hs+2−1
@@ -2,7 +2,8 @@
22{-# LANGUAGE NamedFieldPuns #-}
33module VerifyCropSpanGeneration where
44
5−import Verify.Graphics.Vty.DisplayRegion
5+import Verify.Graphics.Vty.Prelude
6+
67import Verify.Graphics.Vty.Image
78import Verify.Graphics.Vty.Picture
89import Verify.Graphics.Vty.Span
test/VerifyEvalTerminfoCaps.hs+1−1
@@ -11,7 +11,7 @@ import Control.DeepSeq
1111import qualified System.Console.Terminfo as Terminfo
1212
1313import Verify
14−import Verify.Graphics.Vty.Terminal
14+import Verify.Graphics.Vty.Output
1515
1616import Control.Applicative ( (<$>) )
1717import Control.Exception ( try, SomeException(..) )
test/VerifyInline.hs+3−3
@@ -1,10 +1,10 @@
11module VerifyInline where
22
33import Graphics.Vty.Inline
4−import Graphics.Vty.Terminal
5−import Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
4+import Graphics.Vty.Output
5+import Graphics.Vty.Output.TerminfoBased as TerminfoBased
66
7−import Verify.Graphics.Vty.Terminal
7+import Verify.Graphics.Vty.Output
88
99import Verify
1010
test/VerifyLayersSpanGeneration.hs+9−8
@@ -2,7 +2,8 @@
22{-# LANGUAGE NamedFieldPuns #-}
33module VerifyLayersSpanGeneration where
44
5−import Verify.Graphics.Vty.DisplayRegion
5+import Verify.Graphics.Vty.Prelude
6+
67import Verify.Graphics.Vty.Image
78import Verify.Graphics.Vty.Picture
89import Verify.Graphics.Vty.Span
@@ -21,7 +22,7 @@ larger_horiz_span_occlusion row_0 row_1 =
2122 (i_larger, i_smaller) = if image_width i_0 > image_width i_1 then (i_0, i_1) else (i_1, i_0)
2223 expected_ops = display_ops_for_image i_larger
2324 p = pic_for_layers [i_larger, i_smaller]
24− ops = display_ops_for_pic p $ DisplayRegion (image_width i_larger) (image_height i_larger)
25+ ops = display_ops_for_pic p (image_width i_larger,image_height i_larger)
2526 in verify_ops_equality expected_ops ops
2627
2728-- | Two rows stacked vertical is equivalent to the first row rendered as the top layer and the
@@ -35,7 +36,7 @@ vert_stack_layer_equivalence_0 row_0 row_1 =
3536 i_lower = background_fill (image_width i_0) 1 <-> i_1
3637 p_layered = pic_for_layers [i_0, i_lower]
3738 expected_ops = display_ops_for_image i
38− ops_layered = display_ops_for_pic p_layered $ DisplayRegion (image_width i_lower) (image_height i_lower)
39+ ops_layered = display_ops_for_pic p_layered (image_width i_lower,image_height i_lower)
3940 in verify_ops_equality expected_ops ops_layered
4041
4142vert_stack_layer_equivalence_1 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
@@ -48,7 +49,7 @@ vert_stack_layer_equivalence_1 row_0 row_1 =
4849 i_upper = background_fill (image_width i_0) 1 <-> i_1
4950 p_layered = pic_for_layers [i_upper, i_lower]
5051 expected_ops = display_ops_for_image i
51− ops_layered = display_ops_for_pic p_layered $ DisplayRegion (image_width i_lower) (image_height i_lower)
52+ ops_layered = display_ops_for_pic p_layered (image_width i_lower,image_height i_lower)
5253 in verify_ops_equality expected_ops ops_layered
5354
5455-- | Two rows horiz joined is equivalent to the first row rendered as the top layer and the
@@ -62,7 +63,7 @@ horiz_join_layer_equivalence_0 row_0 row_1 =
6263 i_lower = background_fill (image_width i_0) 1 <|> i_1
6364 p_layered = pic_for_layers [i_0, i_lower]
6465 expected_ops = display_ops_for_image i
65− ops_layered = display_ops_for_pic p_layered $ DisplayRegion (image_width i_lower) (image_height i_lower)
66+ ops_layered = display_ops_for_pic p_layered (image_width i_lower,image_height i_lower)
6667 in verify_ops_equality expected_ops ops_layered
6768
6869horiz_join_layer_equivalence_1 :: SingleRowSingleAttrImage -> SingleRowSingleAttrImage -> Result
@@ -75,7 +76,7 @@ horiz_join_layer_equivalence_1 row_0 row_1 =
7576 i_upper = background_fill (image_width i_0) 1 <|> i_1
7677 p_layered = pic_for_layers [i_upper, i_lower]
7778 expected_ops = display_ops_for_image i
78− ops_layered = display_ops_for_pic p_layered $ DisplayRegion (image_width i_lower) (image_height i_lower)
79+ ops_layered = display_ops_for_pic p_layered (image_width i_lower,image_height i_lower)
7980 in verify_ops_equality expected_ops ops_layered
8081
8182horiz_join_alternate_0 :: Result
@@ -90,7 +91,7 @@ horiz_join_alternate_0 =
9091 layer_1 = horiz_cat $ replicate size $ background_fill size 1 <|> i_1
9192 expected_ops = display_ops_for_image i
9293 ops_layered = display_ops_for_pic (pic_for_layers [layer_0, layer_1])
93− (DisplayRegion (image_width i) (image_height i))
94+ (image_width i,image_height i)
9495 in verify_ops_equality expected_ops ops_layered
9596
9697horiz_join_alternate_1 :: Result
@@ -104,7 +105,7 @@ horiz_join_alternate_1 =
104105 layers = [l | b <- take 4 [0,size*2..], let l = background_fill b 1 <|> i_0 <|> i_1]
105106 expected_ops = display_ops_for_image i
106107 ops_layered = display_ops_for_pic (pic_for_layers layers)
107− (DisplayRegion (image_width i) (image_height i))
108+ (image_width i,image_height i)
108109 in verify_ops_equality expected_ops ops_layered
109110
110111tests :: IO [Test]
test/VerifyTerminal.hs → test/VerifyOutput.hsrenamed+3−3
@@ -2,13 +2,13 @@
22 - This assumes appropriate definitions exist in the current environment for the terminals of
33 - interest.
44 -}
5−module VerifyTerminal where
5+module VerifyOutput where
66import Verify
77
88import Graphics.Vty
99
1010import Verify.Graphics.Vty.Image
11−import Verify.Graphics.Vty.Terminal
11+import Verify.Graphics.Vty.Output
1212
1313import Control.Monad
1414
@@ -49,7 +49,7 @@ smoke_test_term term_name i = do
4949 t <- terminal_with_name_and_io term_name null_out
5050 putStrLn $ "context color count: " ++ show (context_color_count t)
5151 reserve_display t
52− dc <- display_context t (DisplayRegion 100 100)
52+ dc <- display_context t (100,100)
5353 -- always show the cursor to produce tests for terminals with no cursor support.
5454 let pic = (pic_for_image i) { pic_cursor = Cursor 0 0 }
5555 output_picture dc pic
test/VerifyParseTerminfoCaps.hs+1−1
@@ -6,7 +6,7 @@ import Prelude hiding ( catch )
66import qualified System.Console.Terminfo as Terminfo
77
88import Verify.Data.Terminfo.Parse
9−import Verify.Graphics.Vty.Terminal
9+import Verify.Graphics.Vty.Output
1010import Verify
1111
1212import Data.Maybe ( catMaybes, fromJust )
test/VerifySimpleSpanGeneration.hs+3−2
@@ -2,7 +2,8 @@
22{-# LANGUAGE NamedFieldPuns #-}
33module VerifySimpleSpanGeneration where
44
5−import Verify.Graphics.Vty.DisplayRegion
5+import Verify.Graphics.Vty.Prelude
6+
67import Verify.Graphics.Vty.Image
78import Verify.Graphics.Vty.Picture
89import Verify.Graphics.Vty.Span
@@ -152,7 +153,7 @@ single_attr_single_span_stack_op_coverage stack =
152153image_coverage_matches_bounds :: Image -> Result
153154image_coverage_matches_bounds i =
154155 let p = pic_for_image i
155− r = DisplayRegion (image_width i) (image_height i)
156+ r = (image_width i,image_height i)
156157 ops = display_ops_for_pic p r
157158 in verify_all_spans_have_width i ops (image_width i)
158159
test/VerifyUsingMockInput.hs+2−1
@@ -6,7 +6,7 @@
66 -}
77module Main where
88
9−import Verify.Graphics.Vty.Terminal
9+import Verify.Graphics.Vty.Output
1010
1111import Data.List (intersperse)
1212
@@ -82,6 +82,7 @@ gen_events_using_io_actions max_duration input_action output_action = do
8282 Just () <- timeout max_duration' $ takeMVar read_complete
8383 return ()
8484
85+compare_events :: (Show a1, Show a, Eq a1) => a -> [a1] -> [a1] -> IO Bool
8586compare_events input_spec expected_events out_events = compare_events' expected_events out_events
8687 where
8788 compare_events' [] [] = return True
test/VerifyUsingMockTerminal.hs+11−10
@@ -1,12 +1,13 @@
11module VerifyUsingMockTerminal where
22
3−import Verify.Graphics.Vty.DisplayRegion
3+import Verify.Graphics.Vty.Prelude
4+
45import Verify.Graphics.Vty.Picture
56import Verify.Graphics.Vty.Image
67import Verify.Graphics.Vty.Span
7−import Verify.Graphics.Vty.Terminal
8−import Graphics.Vty.Terminal
9−import Graphics.Vty.Terminal.Mock
8+import Verify.Graphics.Vty.Output
9+import Graphics.Vty.Output
10+import Graphics.Vty.Output.Mock
1011
1112import Graphics.Vty.Debug
1213
@@ -20,7 +21,7 @@ import System.IO
2021
2122unit_image_unit_bounds :: UnitImage -> Property
2223unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
23− (_,t) <- mock_terminal (DisplayRegion 1 1)
24+ (_,t) <- mock_terminal (1,1)
2425 dc <- display_bounds t >>= display_context t
2526 let pic = pic_for_image i
2627 output_picture dc pic
@@ -28,7 +29,7 @@ unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
2829
2930unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
3031unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
31− (_,t) <- mock_terminal (DisplayRegion w h)
32+ (_,t) <- mock_terminal (w,h)
3233 dc <- display_bounds t >>= display_context t
3334 let pic = pic_for_image i
3435 output_picture dc pic
@@ -36,7 +37,7 @@ unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
3637
3738single_T_row :: MockWindow -> Property
3839single_T_row (MockWindow w h) = liftIOResult $ do
39− (mock_data,t) <- mock_terminal (DisplayRegion w h)
40+ (mock_data,t) <- mock_terminal (w,h)
4041 dc <- display_bounds t >>= display_context t
4142 -- create an image that contains just the character T repeated for a single row
4243 let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
@@ -51,7 +52,7 @@ single_T_row (MockWindow w h) = liftIOResult $ do
5152
5253many_T_rows :: MockWindow -> Property
5354many_T_rows (MockWindow w h) = liftIOResult $ do
54− (mock_data, t) <- mock_terminal (DisplayRegion w h)
55+ (mock_data, t) <- mock_terminal (w,h)
5556 dc <- display_bounds t >>= display_context t
5657 -- create an image that contains the character 'T' repeated for all the rows
5758 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
@@ -64,7 +65,7 @@ many_T_rows (MockWindow w h) = liftIOResult $ do
6465
6566many_T_rows_cropped_width :: MockWindow -> Property
6667many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
67− (mock_data,t) <- mock_terminal (DisplayRegion w h)
68+ (mock_data,t) <- mock_terminal (w,h)
6869 dc <- display_bounds t >>= display_context t
6970 -- create an image that contains the character 'T' repeated for all the rows
7071 let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
@@ -77,7 +78,7 @@ many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
7778
7879many_T_rows_cropped_height :: MockWindow -> Property
7980many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
80− (mock_data,t) <- mock_terminal (DisplayRegion w h)
81+ (mock_data,t) <- mock_terminal (w,h)
8182 dc <- display_bounds t >>= display_context t
8283 -- create an image that contains the character 'T' repeated for all the rows
8384 let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
test/interactive_terminal_test.hs+5−6
@@ -5,8 +5,7 @@ import Graphics.Vty
55import Graphics.Vty.Attributes
66import Graphics.Vty.Inline
77import Graphics.Vty.Picture
8−import Graphics.Vty.Terminal
9−import Graphics.Vty.DisplayRegion
8+import Graphics.Vty.Output
109
1110import Control.Concurrent (threadDelay)
1211import Control.Exception
@@ -224,7 +223,7 @@ display_bounds_test_0 = Test
224223 , test_action = do
225224 t <- current_terminal
226225 reserve_display t
227− DisplayRegion w h <- display_bounds t
226+ (w,h) <- display_bounds t
228227 let row_0 = replicate (fromEnum w) 'X' ++ "\n"
229228 row_h = replicate (fromEnum w - 1) 'X'
230229 row_n = "X" ++ replicate (fromEnum w - 2) ' ' ++ "X\n"
@@ -245,7 +244,7 @@ display_bounds_test_1 = Test
245244 , test_action = do
246245 t <- current_terminal
247246 reserve_display t
248− DisplayRegion w h <- display_bounds t
247+ (w,h) <- display_bounds t
249248 set_cursor_pos t 0 0
250249 let row_0 = replicate (fromEnum w) 'X' ++ "\n"
251250 putStr row_0
@@ -274,7 +273,7 @@ display_bounds_test_2 = Test
274273 , test_action = do
275274 t <- current_terminal
276275 reserve_display t
277− bounds@(DisplayRegion w h) <- display_bounds t
276+ bounds@(w,h) <- display_bounds t
278277 let first_row = horiz_cat $ replicate (fromEnum w) (char def_attr 'X')
279278 middle_rows = vert_cat $ replicate (fromEnum h - 2) middle_row
280279 middle_row = (char def_attr 'X') <|> background_fill (w - 2) 1 <|> (char def_attr 'X')
@@ -297,7 +296,7 @@ display_bounds_test_3 = Test
297296 , test_action = do
298297 t <- current_terminal
299298 reserve_display t
300− DisplayRegion w h <- display_bounds t
299+ (w,h) <- display_bounds t
301300 hide_cursor t
302301 set_cursor_pos t 0 0
303302 let row_0 = replicate (fromEnum w) 'X'
vty.cabal+19−19
@@ -65,7 +65,8 @@ library
6565 Graphics.Vty.Input.Internal
6666 Graphics.Vty.Input.Terminfo
6767 Graphics.Vty.Picture
68− Graphics.Vty.Terminal
68+ Graphics.Vty.Prelude
69+ Graphics.Vty.Output
6970 Graphics.Text.Width
7071 -- the modules below are only meant to be used by the tests.
7172 Codec.Binary.UTF8.Debug
@@ -73,16 +74,15 @@ library
7374 Data.Terminfo.Eval
7475 Data.Marshalling
7576 Graphics.Vty.Debug
76− Graphics.Vty.DisplayRegion
7777 Graphics.Vty.DisplayAttributes
7878 Graphics.Vty.Image.Internal
7979 Graphics.Vty.PictureToSpans
8080 Graphics.Vty.Span
81− Graphics.Vty.Terminal.Mock
82− Graphics.Vty.Terminal.Interface
83− Graphics.Vty.Terminal.MacOSX
84− Graphics.Vty.Terminal.XTermColor
85− Graphics.Vty.Terminal.TerminfoBased
81+ Graphics.Vty.Output.Mock
82+ Graphics.Vty.Output.Interface
83+ Graphics.Vty.Output.MacOSX
84+ Graphics.Vty.Output.XTermColor
85+ Graphics.Vty.Output.TerminfoBased
8686
8787 other-modules: Graphics.Vty.Attributes.Color
8888 Graphics.Vty.Attributes.Color240
@@ -139,11 +139,11 @@ test-suite verify-using-mock-terminal
139139
140140 other-modules: Verify
141141 Verify.Graphics.Vty.Attributes
142− Verify.Graphics.Vty.DisplayRegion
142+ Verify.Graphics.Vty.Prelude
143143 Verify.Graphics.Vty.Picture
144144 Verify.Graphics.Vty.Image
145145 Verify.Graphics.Vty.Span
146− Verify.Graphics.Vty.Terminal
146+ Verify.Graphics.Vty.Output
147147
148148 build-depends: vty,
149149 Cabal == 1.18.*,
@@ -168,15 +168,15 @@ test-suite verify-terminal
168168
169169 hs-source-dirs: test
170170
171− test-module: VerifyTerminal
171+ test-module: VerifyOutput
172172
173173 other-modules: Verify
174174 Verify.Graphics.Vty.Attributes
175− Verify.Graphics.Vty.DisplayRegion
175+ Verify.Graphics.Vty.Prelude
176176 Verify.Graphics.Vty.Picture
177177 Verify.Graphics.Vty.Image
178178 Verify.Graphics.Vty.Span
179− Verify.Graphics.Vty.Terminal
179+ Verify.Graphics.Vty.Output
180180
181181 build-depends: vty,
182182 Cabal == 1.18.*,
@@ -205,7 +205,7 @@ test-suite verify-display-attributes
205205
206206 other-modules: Verify
207207 Verify.Graphics.Vty.Attributes
208− Verify.Graphics.Vty.DisplayRegion
208+ Verify.Graphics.Vty.Prelude
209209 Verify.Graphics.Vty.Picture
210210 Verify.Graphics.Vty.Image
211211 Verify.Graphics.Vty.Span
@@ -261,7 +261,7 @@ test-suite verify-eval-terminfo-caps
261261 test-module: VerifyEvalTerminfoCaps
262262
263263 other-modules: Verify
264− Verify.Graphics.Vty.Terminal
264+ Verify.Graphics.Vty.Output
265265
266266 build-depends: vty,
267267 Cabal == 1.18.*,
@@ -345,7 +345,7 @@ test-suite verify-inline
345345 test-module: VerifyInline
346346
347347 other-modules: Verify
348− Verify.Graphics.Vty.Terminal
348+ Verify.Graphics.Vty.Output
349349
350350 build-depends: vty,
351351 Cabal == 1.18.*,
@@ -373,7 +373,7 @@ test-suite verify-parse-terminfo-caps
373373
374374 other-modules: Verify
375375 Verify.Data.Terminfo.Parse
376− Verify.Graphics.Vty.Terminal
376+ Verify.Graphics.Vty.Output
377377
378378 build-depends: vty,
379379 Cabal == 1.18.*,
@@ -402,7 +402,7 @@ test-suite verify-simple-span-generation
402402
403403 other-modules: Verify
404404 Verify.Graphics.Vty.Attributes
405− Verify.Graphics.Vty.DisplayRegion
405+ Verify.Graphics.Vty.Prelude
406406 Verify.Graphics.Vty.Picture
407407 Verify.Graphics.Vty.Image
408408 Verify.Graphics.Vty.Span
@@ -434,7 +434,7 @@ test-suite verify-crop-span-generation
434434
435435 other-modules: Verify
436436 Verify.Graphics.Vty.Attributes
437− Verify.Graphics.Vty.DisplayRegion
437+ Verify.Graphics.Vty.Prelude
438438 Verify.Graphics.Vty.Picture
439439 Verify.Graphics.Vty.Image
440440 Verify.Graphics.Vty.Span
@@ -466,7 +466,7 @@ test-suite verify-layers-span-generation
466466
467467 other-modules: Verify
468468 Verify.Graphics.Vty.Attributes
469− Verify.Graphics.Vty.DisplayRegion
469+ Verify.Graphics.Vty.Prelude
470470 Verify.Graphics.Vty.Picture
471471 Verify.Graphics.Vty.Image
472472 Verify.Graphics.Vty.Span