on master help sign in
clear to eol on row end when using terminfo based terminal
commite5eaad51c284cfcfbfbb40f08263bda2f025a847 authorCorey O'Connor <corey@ooyala.com> dateTue 23 Jul 2013, 01:16 (13 years ago) parente568a9a
6 files changed+35−13
src/Data/Terminfo/Eval.hs+1−1 src/Data/Terminfo/Parse.hs+14−3 src/Graphics/Vty/Terminal/Interface.hs+10−2 src/Graphics/Vty/Terminal/Mock.hs+5 src/Graphics/Vty/Terminal/TerminfoBased.hs+5−1 test/Verify/Data/Terminfo/Parse.hs−6
src/Data/Terminfo/Eval.hs+1−1
@@ -162,7 +162,7 @@ serialize_cap_ops :: OutputBuffer -> CapOps -> EvalT IO OutputBuffer
162162serialize_cap_ops out_ptr ops = foldM serialize_cap_op out_ptr ops
163163
164164serialize_cap_op :: OutputBuffer -> CapOp -> EvalT IO OutputBuffer
165−serialize_cap_op !out_ptr ( Bytes !offset !byte_count !next_offset ) = do
165+serialize_cap_op !out_ptr (Bytes !offset !byte_count !next_offset) = do
166166 !cap <- get >>= return . eval_expression
167167 let ( !start_ptr, _ ) = cap_bytes cap
168168 !src_ptr = start_ptr `plusPtr` offset
src/Data/Terminfo/Parse.hs+14−3
@@ -21,6 +21,8 @@ import Foreign.C.Types
2121import Foreign.Marshal.Array
2222import Foreign.Ptr
2323
24+import Numeric (showHex)
25+
2426import Text.ParserCombinators.Parsec
2527
2628type CapBytes = ( Ptr Word8, CSize )
@@ -31,7 +33,16 @@ data CapExpression = CapExpression
3133 , source_string :: !String
3234 , param_count :: !Word
3335 , param_ops :: !ParamOps
34− }
36+ } deriving (Eq)
37+
38+instance Show CapExpression where
39+ show c
40+ = "CapExpression { " ++ show (cap_ops c) ++ " }"
41+ ++ " <- [" ++ hex_dump ( map ( toEnum . fromEnum ) $! source_string c ) ++ "]"
42+ ++ " <= " ++ show (source_string c)
43+ where
44+ hex_dump :: [Word8] -> String
45+ hex_dump = foldr (\b s -> showHex b s) ""
3546
3647instance NFData CapExpression where
3748 rnf (CapExpression ops !_bytes !str !c !p_ops)
@@ -55,7 +66,7 @@ data CapOp =
5566 | BitwiseOr | BitwiseXOr | BitwiseAnd
5667 | ArithPlus | ArithMinus
5768 | CompareEq | CompareLt | CompareGt
58− deriving ( Show )
69+ deriving (Show, Eq)
5970
6071instance NFData CapOp where
6172 rnf (Bytes offset _count next_offset) = rnf offset `seq` rnf next_offset
@@ -76,7 +87,7 @@ instance NFData CapOp where
7687type ParamOps = [ParamOp]
7788data ParamOp =
7889 IncFirstTwo
79− deriving ( Show )
90+ deriving (Show, Eq)
8091
8192instance NFData ParamOp where
8293 rnf IncFirstTwo = ()
src/Graphics/Vty/Terminal/Interface.hs+10−2
@@ -88,6 +88,8 @@ display_context t r = liftIO $ do
8888 , serialize_set_attr = serialize_set_attr self
8989 , default_attr_required_bytes = default_attr_required_bytes self
9090 , serialize_default_attr = serialize_default_attr self
91+ , row_end_required_bytes = row_end_required_bytes self
92+ , serialize_row_end = serialize_row_end self
9193 , inline_hack = return ()
9294 }
9395 mfix (mk_display_context t . def_context)
@@ -120,6 +122,8 @@ data DisplayContext = DisplayContext
120122 -- | Reset the display attributes to the default display attributes
121123 , default_attr_required_bytes :: Int
122124 , serialize_default_attr :: OutputBuffer -> IO OutputBuffer
125+ , row_end_required_bytes :: Int
126+ , serialize_row_end :: OutputBuffer -> IO OutputBuffer
123127 -- | See Graphics.Vty.Terminal.XTermColor.inline_hack
124128 , inline_hack :: IO ()
125129 }
@@ -236,7 +240,7 @@ span_op_required_bytes dc fattr (AttributeChange attr) =
236240 in (c, fattr')
237241span_op_required_bytes _dc fattr (TextSpan _ _ str) = (utf8_text_required_bytes str, fattr)
238242span_op_required_bytes _dc _fattr (Skip _) = error "span_op_required_bytes for Skip."
239−span_op_required_bytes _dc fattr (RowEnd _) = (0,fattr)
243+span_op_required_bytes dc fattr (RowEnd _) = (row_end_required_bytes dc, fattr)
240244
241245serialize_output_ops :: DisplayContext
242246 -> OutputBuffer
@@ -272,6 +276,8 @@ serialize_span_ops dc y out_ptr in_fattr span_ops = do
272276 (out_ptr', in_fattr)
273277 span_ops
274278
279+-- |
280+-- TODO: move this into the terminal implementation?
275281serialize_span_op :: DisplayContext
276282 -> SpanOp
277283 -> OutputBuffer
@@ -287,7 +293,9 @@ serialize_span_op _dc (TextSpan _ _ str) out_ptr fattr = do
287293 out_ptr' <- serialize_utf8_text str out_ptr
288294 return (out_ptr', fattr)
289295serialize_span_op _dc (Skip _) _out_ptr _fattr = error "serialize_span_op for Skip"
290−serialize_span_op _dc (RowEnd _) out_ptr fattr = return (out_ptr, fattr)
296+serialize_span_op dc (RowEnd _) out_ptr fattr = do
297+ out_ptr' <- serialize_row_end dc out_ptr
298+ return (out_ptr', fattr)
291299
292300send_to_terminal :: Terminal -> Int -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
293301send_to_terminal t c f = allocaBytes (fromEnum c) $ \start_ptr -> do
src/Graphics/Vty/Terminal/Mock.hs+5
@@ -79,6 +79,11 @@ mock_terminal r = liftIO $ do
7979 , serialize_default_attr = \ptr -> do
8080 poke ptr (toEnum $ fromEnum 'D')
8181 return $ ptr `plusPtr` 1
82+ -- row end is always visualized as the single character 'E'
83+ , row_end_required_bytes = 1
84+ , serialize_row_end = \ptr -> do
85+ poke ptr (toEnum $ fromEnum 'E')
86+ return $ ptr `plusPtr` 1
8287 }
8388 }
8489
src/Graphics/Vty/Terminal/TerminfoBased.hs+5−1
@@ -47,6 +47,7 @@ data TerminfoCaps = TerminfoCaps
4747 , set_back_color :: CapExpression
4848 , set_default_attr :: CapExpression
4949 , clear_screen :: CapExpression
50+ , clear_eol :: CapExpression
5051 , display_attr_caps :: DisplayAttrCaps
5152 }
5253
@@ -109,6 +110,7 @@ reserve_terminal in_ID out_handle = liftIO $ mfix $ \self -> do
109110 <*> pure set_back_cap
110111 <*> require_cap ti "sgr0"
111112 <*> require_cap ti "clear"
113+ <*> require_cap ti "el"
112114 <*> current_display_attr_caps ti
113115 let send_cap s = send_cap_to_terminal self (s terminfo_caps)
114116 maybe_send_cap s = when (isJust $ s terminfo_caps) . send_cap (fromJust . s)
@@ -212,7 +214,9 @@ mk_terminfo_display_context terminfo_caps self = do
212214 , attr_required_bytes = \_prev_attr _req_attr _diffs -> assumed_attr_required_bytes
213215 , serialize_set_attr = terminfo_serialize_set_attr self terminfo_caps
214216 , default_attr_required_bytes = cap_expression_required_bytes (set_default_attr terminfo_caps) []
215− , serialize_default_attr = \out_ptr -> serialize_cap_expression (set_default_attr terminfo_caps) [] out_ptr
217+ , serialize_default_attr = serialize_cap_expression (set_default_attr terminfo_caps) []
218+ , row_end_required_bytes = cap_expression_required_bytes (clear_eol terminfo_caps) []
219+ , serialize_row_end = serialize_cap_expression (clear_eol terminfo_caps) []
216220 }
217221
218222-- | Instead of evaluating all the rules related to setting display attributes twice (once in
test/Verify/Data/Terminfo/Parse.hs−6
@@ -12,12 +12,6 @@ import Data.Word
1212
1313import Numeric
1414
15−instance Show CapExpression where
16− show c
17− = "CapExpression { " ++ show (cap_ops c) ++ " }"
18− ++ " <- [" ++ hex_dump ( map ( toEnum . fromEnum ) $! source_string c ) ++ "]"
19− ++ " <= " ++ show (source_string c)
20−
2115hex_dump :: [Word8] -> String
2216hex_dump bytes = foldr (\b s -> showHex b s) "" bytes
2317