summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2023-01-05 23:48:16 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-01-18 22:24:51 -0500
commit981ff7c4d0e0dd1f4cf721ceb3e99128e442f9fc (patch)
tree768983730880b77540a84e72af42d13b6ec34add /utils
parent32ab07bf3d6ce45e8ea5b55e8095174a6b42a7f0 (diff)
downloadhaskell-981ff7c4d0e0dd1f4cf721ceb3e99128e442f9fc.tar.gz
ghc-pkg does not have to depend on terminfo
Diffstat (limited to 'utils')
-rw-r--r--utils/ghc-pkg/Main.hs54
-rw-r--r--utils/ghc-pkg/ghc-pkg.cabal.in8
2 files changed, 17 insertions, 45 deletions
diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index 5e91d905e6..5fb6a85bce 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -10,13 +10,6 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
--- We never want to link against terminfo while bootstrapping.
-#if defined(BOOTSTRAPPING)
-#if defined(WITH_TERMINFO)
-#undef WITH_TERMINFO
-#endif
-#endif
-
-- Fine if this comes from make/Hadrian or the pre-built base.
#include <ghcplatform.h>
@@ -100,10 +93,6 @@ import System.Posix hiding (fdToHandle)
import qualified System.Info(os)
#endif
-#if defined(WITH_TERMINFO)
-import System.Console.Terminfo as Terminfo
-#endif
-
#if defined(mingw32_HOST_OS)
# if defined(i386_HOST_ARCH)
# define WINDOWS_CCONV stdcall
@@ -1582,37 +1571,28 @@ listPackages verbosity my_flags mPackageName mModuleName = do
if simple_output then show_simple stack else do
-#if !defined(WITH_TERMINFO)
+#if defined(mingw32_HOST_OS)
mapM_ show_normal stack
#else
let
- show_colour withF db@PackageDB{ packages = pkg_confs } =
- if null pkg_confs
- then termText (location db) <#> termText "\n (no packages)\n"
- else
- mconcat $ map (<#> termText "\n") $
- (termText (location db)
- : map (termText " " <#>) (map pp_pkg pkg_confs))
- where
- pp_pkg p
- | installedUnitId p `elem` broken = withF Red doc
- | exposed p = doc
- | otherwise = withF Blue doc
- where doc | verbosity >= Verbose
- = termText (printf "%s (%s)" pkg (display (installedUnitId p)))
- | otherwise
- = termText pkg
- where
- pkg = display (mungedId p)
+ show_colour PackageDB{ location = db_name, packages = pkg_confs } =
+ do hPutStrLn stdout db_name
+ if null pkg_confs
+ then hPutStrLn stdout " (no packages)"
+ else hPutStrLn stdout $ unlines (map (" " ++) (map pp_pkg pkg_confs))
+ where
+ pp_pkg p
+ | installedUnitId p `elem` broken = printf "\ESC[31m%s\ESC[0m" doc -- red color
+ | exposed p = doc
+ | otherwise = printf "\ESC[34m%s\ESC[0m" doc -- blue color
+ where doc | verbosity >= Verbose = printf "%s (%s)" pkg (display (installedUnitId p))
+ | otherwise = pkg
+ where
+ pkg = display (mungedId p)
is_tty <- hIsTerminalDevice stdout
- if not is_tty
- then mapM_ show_normal stack
- else do tty <- Terminfo.setupTermFromEnv
- case Terminfo.getCapability tty withForegroundColor of
- Nothing -> mapM_ show_normal stack
- Just w -> runTermOutput tty $ mconcat $
- map (show_colour w) stack
+ -- Coloured text is a part of ANSI standard, no reason to query terminfo
+ mapM_ (if is_tty then show_colour else show_normal) stack
#endif
simplePackageList :: [Flag] -> [InstalledPackageInfo] -> IO ()
diff --git a/utils/ghc-pkg/ghc-pkg.cabal.in b/utils/ghc-pkg/ghc-pkg.cabal.in
index 4d9402c2d3..2503f0bba3 100644
--- a/utils/ghc-pkg/ghc-pkg.cabal.in
+++ b/utils/ghc-pkg/ghc-pkg.cabal.in
@@ -15,11 +15,6 @@ Category: Development
build-type: Simple
cabal-version: >=1.10
-Flag terminfo
- Description: Build GHC with terminfo support on non-Windows platforms.
- Default: True
- Manual: False
-
Executable ghc-pkg
Default-Language: Haskell2010
Main-Is: Main.hs
@@ -35,9 +30,6 @@ Executable ghc-pkg
binary,
ghc-boot,
bytestring
- if !os(windows) && flag(terminfo)
- Build-Depends: terminfo
- Cpp-Options: -DWITH_TERMINFO
if !os(windows)
Build-Depends: unix
if os(windows)