@@ -8,7 +8,12 @@ module Graphics.Text.Width ( wcwidth
88 )
99 where
1010
11−foreign import ccall unsafe "vty_mk_wcwidth" wcwidth :: Char -> Int
11+import Foreign.C.Types (CInt(..))
12+
13+foreign import ccall unsafe "vty_mk_wcwidth" c_wcwidth :: Char -> CInt
14+
15+wcwidth :: Char -> Int
16+wcwidth = fromIntegral . c_wcwidth
1217
1318wcswidth :: String -> Int
1419wcswidth = sum . map wcwidth
@@ -22,13 +27,8 @@ wcswidth = sum . map wcwidth
2227
2328-- | Returns the display width of a character. Assumes all characters with unknown widths are 0 width
2429safeWcwidth :: Char -> Int
25−safeWcwidth c = case wcwidth c of
26− i | i < 0 -> 0
27− | otherwise -> i
30+safeWcwidth = max 0 . wcwidth
2831
2932-- | Returns the display width of a string. Assumes all characters with unknown widths are 0 width
3033safeWcswidth :: String -> Int
31−safeWcswidth str = case wcswidth str of
32− i | i < 0 -> 0
33− | otherwise -> i
34−
34+safeWcswidth = sum . map safeWcwidth