on master help sign in
change Output interface to use Write
f165d08Corey O'Connor
src/Graphics/Vty/Output/Interface.hs+17−34
@@ -5,10 +5,8 @@
5{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE ExistentialQuantification #-}
6{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GADTs #-}
7{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE FlexibleContexts #-}
8−module Graphics.Vty.Output.Interface ( module Graphics.Vty.Output.Interface
8+module Graphics.Vty.Output.Interface
9− , OutputBuffer
10− )
11− where
9+where
12
10
13import Graphics.Vty.Prelude
11import Graphics.Vty.Prelude
14
12
@@ -18,13 +16,16 @@ import Graphics.Vty.Span
18
16
19import Graphics.Vty.DisplayAttributes
17import Graphics.Vty.DisplayAttributes
20
18
19+import Blaze.ByteString.Builder (Write)
20+import Blaze.ByteString.Builder.ByteString (writeByteString)
21+
21import Control.Monad.Trans
22import Control.Monad.Trans
22
23
23−import qualified Data.ByteString.Internal as BS
24+import qualified Data.ByteString as BS
24import qualified Data.Text.Encoding as T
25import qualified Data.Text.Encoding as T
25import qualified Data.Text.Lazy as TL
26import qualified Data.Text.Lazy as TL
26import Data.IORef
27import Data.IORef
27−import qualified Data.Vector as Vector
28+import qualified Data.Vector.Unboxed as Vector
28
29
29data Output = Output
30data Output = Output
30 { -- | Text identifier for the output device. Used for debugging.
31 { -- | Text identifier for the output device. Used for debugging.
@@ -50,9 +51,8 @@ data Output = Output
50 , release_display :: MonadIO m => m ()
51 , release_display :: MonadIO m => m ()
51 -- | Returns the current display bounds.
52 -- | Returns the current display bounds.
52 , display_bounds :: MonadIO m => m DisplayRegion
53 , display_bounds :: MonadIO m => m DisplayRegion
53− -- | Output the byte buffer of the specified size to the terminal device. The size is equal to
54+ -- | Output the byte string to the terminal device.
54− -- end_ptr - start_ptr
55− , output_byte_buffer :: OutputBuffer -> Int -> IO ()
55+ , output_byte_buffer :: BS.ByteString -> IO ()
56 -- | Maximum number of colors supported by the context.
56 -- | Maximum number of colors supported by the context.
57 , context_color_count :: Int
57 , context_color_count :: Int
58 -- | if the cursor can be shown / hidden
58 -- | if the cursor can be shown / hidden
@@ -81,12 +81,9 @@ data DisplayContext = DisplayContext
81 , context_region :: DisplayRegion
81 , context_region :: DisplayRegion
82 -- | sets the output position to the specified row and column. Where the number of bytes
82 -- | sets the output position to the specified row and column. Where the number of bytes
83 -- required for the control codes can be specified seperate from the actual byte sequence.
83 -- required for the control codes can be specified seperate from the actual byte sequence.
84− , move_cursor_required_bytes :: Int -> Int -> Int
84+ , write_move_cursor :: Int -> Int -> Write
85− , serialize_move_cursor :: Int -> Int -> OutputBuffer -> IO OutputBuffer
85+ , write_show_cursor :: Write
86− , show_cursor_required_bytes :: Int
86+ , write_hide_cursor :: Write
87− , serialize_show_cursor :: OutputBuffer -> IO OutputBuffer
88− , hide_cursor_required_bytes :: Int
89− , serialize_hide_cursor :: OutputBuffer -> IO OutputBuffer
90 -- | Assure the specified output attributes will be applied to all the following text until the
87 -- | Assure the specified output attributes will be applied to all the following text until the
91 -- next output attribute change. Where the number of bytes required for the control codes can
88 -- next output attribute change. Where the number of bytes required for the control codes can
92 -- be specified seperate from the actual byte sequence. The required number of bytes must be
89 -- be specified seperate from the actual byte sequence. The required number of bytes must be
@@ -98,31 +95,17 @@ data DisplayContext = DisplayContext
98 -- attributes. In order to support this the currently applied display attributes are required.
95 -- attributes. In order to support this the currently applied display attributes are required.
99 -- In addition it may be possible to optimize the state changes based off the currently applied
96 -- In addition it may be possible to optimize the state changes based off the currently applied
100 -- display attributes.
97 -- display attributes.
101− , attr_required_bytes :: FixedAttr -> Attr -> DisplayAttrDiff -> Int
102− , serialize_set_attr :: FixedAttr -> Attr -> DisplayAttrDiff -> OutputBuffer -> IO OutputBuffer
98+ , write_set_attr :: FixedAttr -> Attr -> DisplayAttrDiff -> Write
103 -- | Reset the display attributes to the default display attributes
99 -- | Reset the display attributes to the default display attributes
104− , default_attr_required_bytes :: Int
100+ , write_default_attr :: Write
105− , serialize_default_attr :: OutputBuffer -> IO OutputBuffer
101+ , write_row_end :: Write
106− , row_end_required_bytes :: Int
107− , serialize_row_end :: OutputBuffer -> IO OutputBuffer
108 -- | See Graphics.Vty.Output.XTermColor.inline_hack
102 -- | See Graphics.Vty.Output.XTermColor.inline_hack
109 , inline_hack :: IO ()
103 , inline_hack :: IO ()
110 }
104 }
111
105
112-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.
106-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.
113−utf8_text_required_bytes :: BS.ByteString -> Int
107+write_utf8_text :: BS.ByteString -> Write
114−utf8_text_required_bytes str =
108+write_utf8_text str dest_ptr = writeByteString
115− let (_, _, src_bytes_length) = BS.toForeignPtr str
116− in src_bytes_length
117−
118−-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.
119−serialize_utf8_text :: BS.ByteString -> OutputBuffer -> IO OutputBuffer
120−serialize_utf8_text str dest_ptr =
121− let (src_fptr, src_ptr_offset, src_bytes_length) = BS.toForeignPtr str
122− in withForeignPtr src_fptr $ \src_ptr -> do
123− let src_ptr' = src_ptr `plusPtr` src_ptr_offset
124− BS.memcpy dest_ptr src_ptr' (toEnum src_bytes_length)
125− return (dest_ptr `plusPtr` src_bytes_length)
126
109
127-- | Displays the given `Picture`.
110-- | Displays the given `Picture`.
128--
111--