on master help sign in
update docs and change unsafeIOToST import
2957f7bCorey O'Connor
src/Codec/Binary/UTF8/Debug.hs+1−1
@@ -8,7 +8,7 @@ import Data.Word
8
8
9import Numeric
9import Numeric
10
10
11−-- Converts an array of ISO-10646 characters (Char type) to an array of Word8 bytes that is the
11+-- | Converts an array of ISO-10646 characters (Char type) to an array of Word8 bytes that is the
12-- corresponding UTF8 byte sequence
12-- corresponding UTF8 byte sequence
13utf8_from_iso :: Integral i => [i] -> [Word8]
13utf8_from_iso :: Integral i => [i] -> [Word8]
14utf8_from_iso = encode . map toEnum
14utf8_from_iso = encode . map toEnum
src/Codec/Binary/UTF8/Width.hs−6
@@ -11,16 +11,12 @@ import Foreign.C.String
11import Foreign.Storable
11import Foreign.Storable
12import Foreign.Ptr
12import Foreign.Ptr
13
13
14−-- import Numeric ( showHex )
15−
16import System.IO.Unsafe
14import System.IO.Unsafe
17
15
18wcwidth :: Char -> Int
16wcwidth :: Char -> Int
19wcwidth c = unsafePerformIO (withCWString [c] $! \ws -> do
17wcwidth c = unsafePerformIO (withCWString [c] $! \ws -> do
20 wc <- peek ws
18 wc <- peek ws
21− -- putStr $ "wcwidth(0x" ++ showHex (fromEnum wc) "" ++ ")"
22 let !w = fromIntegral $! wcwidth' wc
19 let !w = fromIntegral $! wcwidth' wc
23− -- putStrLn $ " -> " ++ show w
24 return w
20 return w
25 )
21 )
26{-# NOINLINE wcwidth #-}
22{-# NOINLINE wcwidth #-}
@@ -29,9 +25,7 @@ foreign import ccall unsafe "vty_mk_wcwidth" wcwidth' :: CWchar -> CInt
29
25
30wcswidth :: String -> Int
26wcswidth :: String -> Int
31wcswidth str = unsafePerformIO (withCWStringLen str $! \(ws, ws_len) -> do
27wcswidth str = unsafePerformIO (withCWStringLen str $! \(ws, ws_len) -> do
32− -- putStr $ "wcswidth(...)"
33 let !w = fromIntegral $! wcswidth' ws (fromIntegral ws_len)
28 let !w = fromIntegral $! wcswidth' ws (fromIntegral ws_len)
34− -- putStrLn $ " -> " ++ show w
35 return w
29 return w
36 )
30 )
37{-# NOINLINE wcswidth #-}
31{-# NOINLINE wcswidth #-}
src/Data/Terminfo/Eval.hs+1
@@ -28,6 +28,7 @@ import Data.List
28import GHC.Prim
28import GHC.Prim
29import GHC.Word
29import GHC.Word
30
30
31+-- | capability evaluator state
31data EvalState = EvalState
32data EvalState = EvalState
32 { eval_stack :: ![ CapParam ]
33 { eval_stack :: ![ CapParam ]
33 , eval_expression :: !CapExpression
34 , eval_expression :: !CapExpression
src/Graphics/Vty/Span.hs+14−6
@@ -16,7 +16,8 @@ import Graphics.Vty.DisplayRegion
16import Codec.Binary.UTF8.String ( encode )
16import Codec.Binary.UTF8.String ( encode )
17
17
18import Control.Monad ( forM_ )
18import Control.Monad ( forM_ )
19−import Control.Monad.ST.Strict
19+import Control.Monad.ST.Strict hiding ( unsafeIOToST )
20+import Control.Monad.ST.Unsafe ( unsafeIOToST )
20
21
21import Data.Vector (Vector)
22import Data.Vector (Vector)
22import qualified Data.Vector as Vector hiding ( take, replicate )
23import qualified Data.Vector as Vector hiding ( take, replicate )
@@ -48,12 +49,15 @@ data DisplayOps = DisplayOps
48 , display_ops :: RowOps
49 , display_ops :: RowOps
49 }
50 }
50
51
51−-- vector of span operation vectors. One per row of the screen.
52+-- | vector of span operation vectors. One per row of the screen.
52type RowOps = Vector SpanOps
53type RowOps = Vector SpanOps
53
54
54type MRowOps s = MVector s SpanOps
55type MRowOps s = MVector s SpanOps
55
56
56−-- vector of span operations. executed in succession
57+-- | vector of span operations. executed in succession. This represents the operations required to
58+-- render a row of the terminal. The operations in one row may effect subsequent rows.
59+-- EG: Setting the foreground color in one row will effect all subsequent rows until the foreground
60+-- color is changed.
57type SpanOps = Vector SpanOp
61type SpanOps = Vector SpanOp
58
62
59type MSpanOps s = MVector s SpanOp
63type MSpanOps s = MVector s SpanOp
@@ -66,19 +70,23 @@ instance Show SpanOp where
66 show (AttributeChange attr) = show attr
70 show (AttributeChange attr) = show attr
67 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
71 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
68
72
73+-- | Number of columns the DisplayOps are defined for
69span_ops_columns :: DisplayOps -> Word
74span_ops_columns :: DisplayOps -> Word
70span_ops_columns ops = region_width $ effected_region ops
75span_ops_columns ops = region_width $ effected_region ops
71
76
77+-- | Number of rows the DisplayOps are defined for
72span_ops_rows :: DisplayOps -> Word
78span_ops_rows :: DisplayOps -> Word
73span_ops_rows ops = region_height $ effected_region ops
79span_ops_rows ops = region_height $ effected_region ops
74
80
81+-- | The number of columns a SpanOps effects.
75span_ops_effected_columns :: SpanOps -> Word
82span_ops_effected_columns :: SpanOps -> Word
76span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
83span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
77 where
84 where
78 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
85 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
79 span_ops_effected_columns' t _ = t
86 span_ops_effected_columns' t _ = t
80
87
81−-- |
88+-- | This represents an operation on the terminal. Either an attribute change or the output of a
89+-- text string.
82--
90--
83-- todo: This type may need to be restructured to increase sharing in the bytestring
91-- todo: This type may need to be restructured to increase sharing in the bytestring
84--
92--
@@ -91,12 +99,12 @@ data SpanOp =
91 | TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
99 | TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
92 deriving Eq
100 deriving Eq
93
101
94−-- used to determine the width of a span operation , if it has one.
102+-- | The width of a single SpanOp in columns
95span_op_has_width :: SpanOp -> Maybe (Word, Word)
103span_op_has_width :: SpanOp -> Maybe (Word, Word)
96span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
104span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
97span_op_has_width _ = Nothing
105span_op_has_width _ = Nothing
98
106
99−-- returns the number of columns to the character at the given position in the span op
107+-- | returns the number of columns to the character at the given position in the span op
100columns_to_char_offset :: Word -> SpanOp -> Word
108columns_to_char_offset :: Word -> SpanOp -> Word
101columns_to_char_offset cx (TextSpan _ _ utf8_str) =
109columns_to_char_offset cx (TextSpan _ _ utf8_str) =
102 let str = UTF8.toString utf8_str
110 let str = UTF8.toString utf8_str