clear to eol on row end when using terminfo based terminal

This commit is contained in:
Corey O'Connor 2013-07-23 01:16:25 -07:00
parent e568a9a312
commit e5eaad51c2
6 changed files with 35 additions and 13 deletions

View File

@ -162,7 +162,7 @@ serialize_cap_ops :: OutputBuffer -> CapOps -> EvalT IO OutputBuffer
serialize_cap_ops out_ptr ops = foldM serialize_cap_op out_ptr ops
serialize_cap_op :: OutputBuffer -> CapOp -> EvalT IO OutputBuffer
serialize_cap_op !out_ptr ( Bytes !offset !byte_count !next_offset ) = do
serialize_cap_op !out_ptr (Bytes !offset !byte_count !next_offset) = do
!cap <- get >>= return . eval_expression
let ( !start_ptr, _ ) = cap_bytes cap
!src_ptr = start_ptr `plusPtr` offset

View File

@ -21,6 +21,8 @@ import Foreign.C.Types
import Foreign.Marshal.Array
import Foreign.Ptr
import Numeric (showHex)
import Text.ParserCombinators.Parsec
type CapBytes = ( Ptr Word8, CSize )
@ -31,7 +33,16 @@ data CapExpression = CapExpression
, source_string :: !String
, param_count :: !Word
, param_ops :: !ParamOps
}
} deriving (Eq)
instance Show CapExpression where
show c
= "CapExpression { " ++ show (cap_ops c) ++ " }"
++ " <- [" ++ hex_dump ( map ( toEnum . fromEnum ) $! source_string c ) ++ "]"
++ " <= " ++ show (source_string c)
where
hex_dump :: [Word8] -> String
hex_dump = foldr (\b s -> showHex b s) ""
instance NFData CapExpression where
rnf (CapExpression ops !_bytes !str !c !p_ops)
@ -55,7 +66,7 @@ data CapOp =
| BitwiseOr | BitwiseXOr | BitwiseAnd
| ArithPlus | ArithMinus
| CompareEq | CompareLt | CompareGt
deriving ( Show )
deriving (Show, Eq)
instance NFData CapOp where
rnf (Bytes offset _count next_offset) = rnf offset `seq` rnf next_offset
@ -76,7 +87,7 @@ instance NFData CapOp where
type ParamOps = [ParamOp]
data ParamOp =
IncFirstTwo
deriving ( Show )
deriving (Show, Eq)
instance NFData ParamOp where
rnf IncFirstTwo = ()

View File

@ -88,6 +88,8 @@ display_context t r = liftIO $ do
, serialize_set_attr = serialize_set_attr self
, default_attr_required_bytes = default_attr_required_bytes self
, serialize_default_attr = serialize_default_attr self
, row_end_required_bytes = row_end_required_bytes self
, serialize_row_end = serialize_row_end self
, inline_hack = return ()
}
mfix (mk_display_context t . def_context)
@ -120,6 +122,8 @@ data DisplayContext = DisplayContext
-- | Reset the display attributes to the default display attributes
, default_attr_required_bytes :: Int
, serialize_default_attr :: OutputBuffer -> IO OutputBuffer
, row_end_required_bytes :: Int
, serialize_row_end :: OutputBuffer -> IO OutputBuffer
-- | See Graphics.Vty.Terminal.XTermColor.inline_hack
, inline_hack :: IO ()
}
@ -236,7 +240,7 @@ span_op_required_bytes dc fattr (AttributeChange attr) =
in (c, fattr')
span_op_required_bytes _dc fattr (TextSpan _ _ str) = (utf8_text_required_bytes str, fattr)
span_op_required_bytes _dc _fattr (Skip _) = error "span_op_required_bytes for Skip."
span_op_required_bytes _dc fattr (RowEnd _) = (0,fattr)
span_op_required_bytes dc fattr (RowEnd _) = (row_end_required_bytes dc, fattr)
serialize_output_ops :: DisplayContext
-> OutputBuffer
@ -272,6 +276,8 @@ serialize_span_ops dc y out_ptr in_fattr span_ops = do
(out_ptr', in_fattr)
span_ops
-- |
-- TODO: move this into the terminal implementation?
serialize_span_op :: DisplayContext
-> SpanOp
-> OutputBuffer
@ -287,7 +293,9 @@ serialize_span_op _dc (TextSpan _ _ str) out_ptr fattr = do
out_ptr' <- serialize_utf8_text str out_ptr
return (out_ptr', fattr)
serialize_span_op _dc (Skip _) _out_ptr _fattr = error "serialize_span_op for Skip"
serialize_span_op _dc (RowEnd _) out_ptr fattr = return (out_ptr, fattr)
serialize_span_op dc (RowEnd _) out_ptr fattr = do
out_ptr' <- serialize_row_end dc out_ptr
return (out_ptr', fattr)
send_to_terminal :: Terminal -> Int -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
send_to_terminal t c f = allocaBytes (fromEnum c) $ \start_ptr -> do

View File

@ -79,6 +79,11 @@ mock_terminal r = liftIO $ do
, serialize_default_attr = \ptr -> do
poke ptr (toEnum $ fromEnum 'D')
return $ ptr `plusPtr` 1
-- row end is always visualized as the single character 'E'
, row_end_required_bytes = 1
, serialize_row_end = \ptr -> do
poke ptr (toEnum $ fromEnum 'E')
return $ ptr `plusPtr` 1
}
}

View File

@ -47,6 +47,7 @@ data TerminfoCaps = TerminfoCaps
, set_back_color :: CapExpression
, set_default_attr :: CapExpression
, clear_screen :: CapExpression
, clear_eol :: CapExpression
, display_attr_caps :: DisplayAttrCaps
}
@ -109,6 +110,7 @@ reserve_terminal in_ID out_handle = liftIO $ mfix $ \self -> do
<*> pure set_back_cap
<*> require_cap ti "sgr0"
<*> require_cap ti "clear"
<*> require_cap ti "el"
<*> current_display_attr_caps ti
let send_cap s = send_cap_to_terminal self (s terminfo_caps)
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
, attr_required_bytes = \_prev_attr _req_attr _diffs -> assumed_attr_required_bytes
, serialize_set_attr = terminfo_serialize_set_attr self terminfo_caps
, default_attr_required_bytes = cap_expression_required_bytes (set_default_attr terminfo_caps) []
, serialize_default_attr = \out_ptr -> serialize_cap_expression (set_default_attr terminfo_caps) [] out_ptr
, serialize_default_attr = serialize_cap_expression (set_default_attr terminfo_caps) []
, row_end_required_bytes = cap_expression_required_bytes (clear_eol terminfo_caps) []
, serialize_row_end = serialize_cap_expression (clear_eol terminfo_caps) []
}
-- | Instead of evaluating all the rules related to setting display attributes twice (once in

View File

@ -12,12 +12,6 @@ import Data.Word
import Numeric
instance Show CapExpression where
show c
= "CapExpression { " ++ show (cap_ops c) ++ " }"
++ " <- [" ++ hex_dump ( map ( toEnum . fromEnum ) $! source_string c ) ++ "]"
++ " <= " ++ show (source_string c)
hex_dump :: [Word8] -> String
hex_dump bytes = foldr (\b s -> showHex b s) "" bytes