Skip to content

Commit

Permalink
Do not depend on wcwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Aug 12, 2022
1 parent e692065 commit 3300450
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- vim:fdm=marker
{-# LANGUAGE BangPatterns, ImplicitParams, MultiParamTypeClasses, DeriveDataTypeable, FlexibleContexts #-}
{-# LANGUAGE BangPatterns, ImplicitParams, MultiParamTypeClasses, DeriveDataTypeable, FlexibleContexts, CApiFFI #-}
-- | Console reporter ingredient
module Test.Tasty.Ingredients.ConsoleReporter
( consoleTestReporter
Expand Down Expand Up @@ -48,8 +48,8 @@ import Test.Tasty.Runners.Utils
import Text.Printf
import qualified Data.IntMap as IntMap
import Data.Char
#ifdef VERSION_wcwidth
import Data.Char.WCWidth (wcwidth)
#ifdef USE_WCWIDTH
import Foreign.C.Types (CInt(..), CWchar(..))
#endif
import Data.List (isInfixOf)
import Data.Maybe
Expand Down Expand Up @@ -678,11 +678,12 @@ computeAlignment opts =
-- (This only works properly on Unix at the moment; on Windows, the function
-- treats every character as width-1 like 'Data.List.length' does.)
stringWidth :: String -> Int
#ifdef VERSION_wcwidth
#ifdef USE_WCWIDTH
stringWidth = Prelude.sum . map charWidth
where charWidth c = case wcwidth c of
where charWidth c = case wcwidth (fromIntegral (ord c)) of
-1 -> 1 -- many chars have "undefined" width; default to 1 for these.
w -> w
w -> fromIntegral w
foreign import capi safe "wchar.h wcwidth" wcwidth :: CWchar -> CInt
#else
stringWidth = length
#endif
Expand Down
2 changes: 1 addition & 1 deletion core/tasty.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ library
build-depends: time >= 1.4

if !os(windows) && !impl(ghcjs)
build-depends: wcwidth
cpp-options: -DUSE_WCWIDTH
if flag(unix)
build-depends: unix

Expand Down

0 comments on commit 3300450

Please sign in to comment.