1-- Copyright 2009 Corey O'Connor
2{-# OPTIONS_GHC -D_XOPEN_SOURCE #-}
3{-# LANGUAGE ForeignFunctionInterface #-}
4module Graphics.Text.Width
16import Data.List (foldl')
17import qualified Data.Text as T
18import qualified Data.Text.Lazy as TL
20foreign import ccall unsafe "vty_mk_wcwidth" wcwidth :: Char -> Int
22wcswidth :: String -> Int
23wcswidth = foldl' (\l c -> wcwidth c + l) 0
25wctwidth :: T.Text -> Int
26wctwidth = T.foldl' (\l c -> wcwidth c + l) 0
28wctlwidth :: TL.Text -> Int
29wctlwidth = TL.foldl' (\l c -> wcwidth c + l) 0
31-- XXX: Characters with unknown widths occupy 1 column?
33-- Not sure if this is actually correct. I presume there is a
34-- replacement character that is output by the terminal instead of the
35-- character and this replacement character is 1 column wide. If this is
36-- not true for all terminals then a per-terminal replacement character
37-- width needs to be implemented.
39-- | Returns the display width of a character. Assumes all characters
40-- with unknown widths are 0 width.
41safeWcwidth :: Char -> Int
42safeWcwidth = max 0 . wcwidth
44-- | Returns the display width of a string. Assumes all characters with
45-- unknown widths are 0 width.
46safeWcswidth :: String -> Int
47safeWcswidth = foldl' (\l c -> safeWcwidth c + l) 0
49-- | Returns the display width of a text. Assumes all characters with
50-- unknown widths are 0 width.
51safeWctwidth :: T.Text -> Int
52safeWctwidth = T.foldl' (\l c -> safeWcwidth c + l) 0
54-- | Returns the display width of a lazy text. Assumes all characters
55-- with unknown widths are 0 width.
56safeWctlwidth :: TL.Text -> Int
57safeWctlwidth = TL.foldl' (\l c -> safeWcwidth c + l) 0
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list