From ded3c24223d98abd350b47112119c5c43f04a28c Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Sat, 13 Jan 2024 17:47:17 -0600 Subject: [PATCH] Depend only on `vty-crossplatform` (#1727) Closes #1623. Note that we still have to list both `vty-unix` and `vty-windows` in `stack.yaml` but that's OK; it just means they are both made available as extra dependencies, but only whichever is needed will actually be installed. In the codebase itself, we now get to avoid CPP on imports, and the code is quite a bit simpler. --- app/Swarm/App.hs | 16 ++-------------- stack.yaml | 7 ++++--- swarm.cabal | 11 ++++------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/Swarm/App.hs b/app/Swarm/App.hs index 0ecba52f..4a776586 100644 --- a/app/Swarm/App.hs +++ b/app/Swarm/App.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} @@ -24,13 +23,7 @@ import Data.IORef (newIORef, writeIORef) import Data.Text qualified as T import Data.Text.IO qualified as T import Graphics.Vty qualified as V -#if defined(mingw32_HOST_OS) || defined(__MINGW32__) -import Graphics.Vty.Platform.Windows.Settings qualified as VS -import Graphics.Vty.Platform.Windows qualified as VS -#else -import Graphics.Vty.Platform.Unix.Settings qualified as VS -import Graphics.Vty.Platform.Unix qualified as VS -#endif +import Graphics.Vty.CrossPlatform qualified as V import Swarm.Game.Failure (SystemFailure) import Swarm.Language.Pretty (prettyText) import Swarm.Log (LogSource (SystemLog), Severity (..)) @@ -116,12 +109,7 @@ appMain opts = do handleEvent e -- Setup virtual terminal - let buildVty = - case colorMode opts of - Nothing -> VS.mkVty V.defaultConfig - Just cMode -> do - platformSettings <- VS.defaultSettings - VS.mkVtyWithSettings V.defaultConfig $ platformSettings {VS.settingColorMode = cMode} + let buildVty = V.mkVty V.defaultConfig {V.configPreferredColorMode = colorMode opts} vty <- buildVty V.setMode (V.outputIface vty) V.Mouse True diff --git a/stack.yaml b/stack.yaml index 28be9eff..0993c24b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -3,9 +3,10 @@ extra-deps: - hsnoise-0.0.3@sha256:260b39175b8a3e3b1719ad3987b7d72a3fd7a0fa99be8639b91cf4dc3f1c8796,1476 - simple-enumeration-0.2.1@sha256:8625b269c1650d3dd0e3887351c153049f4369853e0d525219e07480ea004b9f,1178 - boolexpr-0.2@sha256:07f38a0206ad63c2c893e3c6271a2e45ea25ab4ef3a9e973edc746876f0ab9e8,853 -- vty-6.0@sha256:3c4ee4ffd6e38720e227c45e85eb91ff611125dbff178e9f2fadc993160e1464,3661 -- vty-crossplatform-0.2.0.0@sha256:6dc6b72ba2fe63f0af582a501ab133a69f49fb75fef3ad7a870412472be077ec,3161 -- vty-unix-0.1.0.0@sha256:8d1dd971d49b4d3575ec76994a8dd5d330d7b81a30ece40344ee170d73a28ac3,2932 +- vty-6.1@sha256:524d124223c02373260ebc409ddd622fbe97cacd1ea0ee98476b5992bddbc4f3,3661 +- vty-crossplatform-0.4.0.0@sha256:50593f91ad16777d921138475a8d2784d538fd206addd30664c620278d6c8544,3172 +- vty-unix-0.2.0.0@sha256:2af3d0bdae3c4b7b7e567ee374efe32c7439fabdf9096465ce011a6c6736e9ae,2932 +- vty-windows-0.2.0.1 - brick-2.1.1 - brick-list-skip-0.1.1.8 - astar-0.3.0.0 diff --git a/swarm.cabal b/swarm.cabal index 082455bf..3e8a7d40 100644 --- a/swarm.cabal +++ b/swarm.cabal @@ -132,7 +132,7 @@ library swarm-lang lsp >= 1.6 && < 1.7, hashable, megaparsec, - mtl, + mtl, parser-combinators, prettyprinter, split, @@ -286,7 +286,7 @@ library swarm-engine transformers >= 0.5.6.2 && < 0.6.2.0, unordered-containers >= 0.2.14 && < 0.3, vector >= 0.12 && < 0.14, - vty >= 6.0 && < 6.1, + vty >= 6.1 && < 6.2, witch >= 1.1.1.0 && < 1.3, witherable >= 0.4 && < 0.5, yaml >= 0.11 && < 0.11.12.0, @@ -576,7 +576,7 @@ library time >= 1.9 && < 1.14, transformers >= 0.5.6.2 && < 0.6.2.0, vector >= 0.12 && < 0.14, - vty >= 6.0 && < 6.1, + vty >= 6.1 && < 6.2, warp >= 3.2 && < 3.4, witch >= 1.1.1.0 && < 1.3, word-wrap >= 0.5 && < 0.6, @@ -608,14 +608,11 @@ executable swarm prettyprinter, text, vty, + vty-crossplatform >= 0.4 && < 0.5, swarm, swarm:swarm-lang, swarm:swarm-web, swarm:swarm-util, - if os(windows) - build-depends: vty-windows >= 0.1.0.3 && < 0.2, - else - build-depends: vty-unix >= 0.1.0.0 && < 0.2, hs-source-dirs: app default-language: Haskell2010 ghc-options: -threaded