mirror of
https://github.com/ilyakooo0/vty.git
synced 2024-10-04 19:27:08 +03:00
update docs and change unsafeIOToST import
This commit is contained in:
parent
ae0f2bacff
commit
2957f7b6e1
@ -8,7 +8,7 @@ import Data.Word
|
||||
|
||||
import Numeric
|
||||
|
||||
-- Converts an array of ISO-10646 characters (Char type) to an array of Word8 bytes that is the
|
||||
-- | Converts an array of ISO-10646 characters (Char type) to an array of Word8 bytes that is the
|
||||
-- corresponding UTF8 byte sequence
|
||||
utf8_from_iso :: Integral i => [i] -> [Word8]
|
||||
utf8_from_iso = encode . map toEnum
|
||||
|
@ -11,16 +11,12 @@ import Foreign.C.String
|
||||
import Foreign.Storable
|
||||
import Foreign.Ptr
|
||||
|
||||
-- import Numeric ( showHex )
|
||||
|
||||
import System.IO.Unsafe
|
||||
|
||||
wcwidth :: Char -> Int
|
||||
wcwidth c = unsafePerformIO (withCWString [c] $! \ws -> do
|
||||
wc <- peek ws
|
||||
-- putStr $ "wcwidth(0x" ++ showHex (fromEnum wc) "" ++ ")"
|
||||
let !w = fromIntegral $! wcwidth' wc
|
||||
-- putStrLn $ " -> " ++ show w
|
||||
return w
|
||||
)
|
||||
{-# NOINLINE wcwidth #-}
|
||||
@ -29,9 +25,7 @@ foreign import ccall unsafe "vty_mk_wcwidth" wcwidth' :: CWchar -> CInt
|
||||
|
||||
wcswidth :: String -> Int
|
||||
wcswidth str = unsafePerformIO (withCWStringLen str $! \(ws, ws_len) -> do
|
||||
-- putStr $ "wcswidth(...)"
|
||||
let !w = fromIntegral $! wcswidth' ws (fromIntegral ws_len)
|
||||
-- putStrLn $ " -> " ++ show w
|
||||
return w
|
||||
)
|
||||
{-# NOINLINE wcswidth #-}
|
||||
|
@ -28,6 +28,7 @@ import Data.List
|
||||
import GHC.Prim
|
||||
import GHC.Word
|
||||
|
||||
-- | capability evaluator state
|
||||
data EvalState = EvalState
|
||||
{ eval_stack :: ![ CapParam ]
|
||||
, eval_expression :: !CapExpression
|
||||
|
@ -16,7 +16,8 @@ import Graphics.Vty.DisplayRegion
|
||||
import Codec.Binary.UTF8.String ( encode )
|
||||
|
||||
import Control.Monad ( forM_ )
|
||||
import Control.Monad.ST.Strict
|
||||
import Control.Monad.ST.Strict hiding ( unsafeIOToST )
|
||||
import Control.Monad.ST.Unsafe ( unsafeIOToST )
|
||||
|
||||
import Data.Vector (Vector)
|
||||
import qualified Data.Vector as Vector hiding ( take, replicate )
|
||||
@ -48,12 +49,15 @@ data DisplayOps = DisplayOps
|
||||
, display_ops :: RowOps
|
||||
}
|
||||
|
||||
-- vector of span operation vectors. One per row of the screen.
|
||||
-- | vector of span operation vectors. One per row of the screen.
|
||||
type RowOps = Vector SpanOps
|
||||
|
||||
type MRowOps s = MVector s SpanOps
|
||||
|
||||
-- vector of span operations. executed in succession
|
||||
-- | vector of span operations. executed in succession. This represents the operations required to
|
||||
-- render a row of the terminal. The operations in one row may effect subsequent rows.
|
||||
-- EG: Setting the foreground color in one row will effect all subsequent rows until the foreground
|
||||
-- color is changed.
|
||||
type SpanOps = Vector SpanOp
|
||||
|
||||
type MSpanOps s = MVector s SpanOp
|
||||
@ -66,19 +70,23 @@ instance Show SpanOp where
|
||||
show (AttributeChange attr) = show attr
|
||||
show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
|
||||
|
||||
-- | Number of columns the DisplayOps are defined for
|
||||
span_ops_columns :: DisplayOps -> Word
|
||||
span_ops_columns ops = region_width $ effected_region ops
|
||||
|
||||
-- | Number of rows the DisplayOps are defined for
|
||||
span_ops_rows :: DisplayOps -> Word
|
||||
span_ops_rows ops = region_height $ effected_region ops
|
||||
|
||||
-- | The number of columns a SpanOps effects.
|
||||
span_ops_effected_columns :: SpanOps -> Word
|
||||
span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
|
||||
where
|
||||
span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
|
||||
span_ops_effected_columns' t _ = t
|
||||
|
||||
-- |
|
||||
-- | This represents an operation on the terminal. Either an attribute change or the output of a
|
||||
-- text string.
|
||||
--
|
||||
-- todo: This type may need to be restructured to increase sharing in the bytestring
|
||||
--
|
||||
@ -91,12 +99,12 @@ data SpanOp =
|
||||
| TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
|
||||
deriving Eq
|
||||
|
||||
-- used to determine the width of a span operation , if it has one.
|
||||
-- | The width of a single SpanOp in columns
|
||||
span_op_has_width :: SpanOp -> Maybe (Word, Word)
|
||||
span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
|
||||
span_op_has_width _ = Nothing
|
||||
|
||||
-- returns the number of columns to the character at the given position in the span op
|
||||
-- | returns the number of columns to the character at the given position in the span op
|
||||
columns_to_char_offset :: Word -> SpanOp -> Word
|
||||
columns_to_char_offset cx (TextSpan _ _ utf8_str) =
|
||||
let str = UTF8.toString utf8_str
|
||||
|
Loading…
Reference in New Issue
Block a user