packages feed

ansi-terminal-game 1.8.0.1 → 1.8.1.0

raw patch · 7 files changed

+66/−21 lines, 7 filesdep +colourPVP ok

version bump matches the API change (PVP)

Dependencies added: colour

API changes (from Hackage documentation)

+ Terminal.Game: data Colour a
+ Terminal.Game: paletteColor :: Word8 -> Plane -> Plane
+ Terminal.Game: rgbColor :: Colour Float -> Plane -> Plane
+ Terminal.Game: sRGB :: (Ord b, Floating b) => b -> b -> b -> Colour b
+ Terminal.Game: sRGB24 :: (Ord b, Floating b) => Word8 -> Word8 -> Word8 -> Colour b
+ Terminal.Game: sRGB24read :: (Ord b, Floating b) => String -> Colour b
+ Terminal.Game: sRGBBounded :: (Ord b, Floating b, Integral a, Bounded a) => a -> a -> a -> Colour b
+ Terminal.Game: xterm24LevelGray :: Int -> Word8
+ Terminal.Game: xterm6LevelRGB :: Int -> Int -> Int -> Word8
+ Terminal.Game: xtermSystem :: ColorIntensity -> Color -> Word8

Files

+ AUTHORS view
@@ -0,0 +1,3 @@+Francesco Ariis+Simon Michael+José Rafael Vieira
NEWS view
@@ -1,5 +1,5 @@-Next-----+1.8.1.0+-------  - Fixed hcat, vcat, stringPlane, stringPlane documentation to match   behaviour (i.e. they do not error on empty strong/list).@@ -9,6 +9,8 @@ - Provided instructions for hot-reloading a game running in normal   (interactive) mode with various means (tmux, urxvt, etc.).   Check `example/MainHotReload.hs`.+- Introduced RGB and term colours (patch by José Rafael Vieira).+- Added AUTHORS.  1.8.0.0 -------
ansi-terminal-game.cabal view
@@ -1,5 +1,5 @@ name:                ansi-terminal-game-version:             1.8.0.1+version:             1.8.1.0 synopsis:            sdl-like functions for terminal applications, based on                      ansi-terminal description:         Library which aims to replicate standard 2d game@@ -13,13 +13,14 @@ homepage:            http://www.ariis.it/static/articles/ansi-terminal-game/page.html license:             GPL-3 license-file:        COPYING-author:              Francesco Ariis+author:              Francesco Ariis et al. (see AUTHORS) maintainer:          fa-ml@ariis.it copyright:           © 2017-2021 Francesco Ariis category:            Game build-type:          Simple extra-source-files:  README,                      NEWS,+                     AUTHORS,                      test/records/alone-record-test.gr                      test/records/balls-dims.gr                      test/records/balls-slow.gr@@ -67,7 +68,8 @@                        split == 0.2.*,                        terminal-size == 0.3.*,                        unidecode >= 0.1.0 && < 0.2,-                       timers-tick > 0.5 && < 0.6+                       timers-tick > 0.5 && < 0.6,+                       colour >= 2.3.6 && < 2.4   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall@@ -120,7 +122,8 @@                        split == 0.2.*,                        terminal-size == 0.3.*,                        unidecode >= 0.1.0 && < 0.2,-                       timers-tick > 0.5 && < 0.6+                       timers-tick > 0.5 && < 0.6,+                       colour >= 2.3.6 && < 2.4                        -- the above plus hspec                        , hspec   build-tool-depends:  hspec-discover:hspec-discover
src/Terminal/Game.hs view
@@ -48,7 +48,7 @@                        -- parametrised over any state @s@, you are free                        -- to implement game logic as you prefer. -                       -- ** Timers/Animation+                       -- ** Timers/Animations                         -- *** Timers                        Timed,@@ -117,6 +117,17 @@                        -- *** Declarative drawing                        (|||), (===), (***), hcat, vcat, +                       -- *** Non-standard colors+                       -- | Non-standard RGB and xterm colors. These are+                       -- prettier, but work on a minority of terminal+                       -- emulators/multiplexers.+                       -- Use them only on your machine or when you are sure+                       -- of the terminal you are targetting.++                       S.Colour, rgbColor, paletteColor,+                       S.sRGB24, S.sRGBBounded, S.sRGB, S.sRGB24read,+                       xterm6LevelRGB, xterm24LevelGray, xtermSystem,+                        -- * Testing                        GRec,                        recordGame,@@ -144,6 +155,7 @@ import Text.LineBreak  import qualified Control.Monad as CM+import qualified Data.Colour.SRGB as S  -- $origins -- Placing a plane is sometimes more convenient if the coordinates origin
src/Terminal/Game/Draw.hs view
@@ -14,8 +14,10 @@  import Text.LineBreak -import qualified Data.Function       as F ( (&) )-import qualified Data.List           as L+import qualified Data.Colour.RGBSpace as S+import qualified Data.Function as F ( (&) )+import qualified Data.List as L+import qualified Data.Word as W import qualified System.Console.ANSI as CA  @@ -128,6 +130,13 @@ invert :: Plane -> Plane invert p = mapPlane reverseCell p +-- | Set RGB color+rgbColor :: S.Colour Float -> Plane -> Plane+rgbColor k p = mapPlane (rgbColorCell k) p++-- | Set Palette color+paletteColor :: W.Word8 -> Plane -> Plane+paletteColor k p = mapPlane (paletteColorCell k) p   -------------
src/Terminal/Game/Layer/Object/IO.hs view
@@ -286,8 +286,10 @@           sgrr | isReversed c = [CA.SetSwapForegroundBackground True]                | otherwise    = [] -          sgrc | Just (k, i) <- cellColor c = [CA.SetColor CA.Foreground i k]-               | otherwise                  = []+          sgrc | Just (ANSIColorInfo (k, i)) <- cellColor c = [CA.SetColor CA.Foreground i k]+               | Just (RGBColorInfo k)       <- cellColor c = [CA.SetRGBColor CA.Foreground k]+               | Just (PaletteColorInfo k)   <- cellColor c = [CA.SetPaletteColor CA.Foreground k]+               | otherwise                                  = []  oneTickSec :: Integer oneTickSec = 10 ^ (6 :: Integer)
src/Terminal/Game/Plane.hs view
@@ -11,11 +11,13 @@ 
 import Terminal.Game.Character
 
-import qualified Data.Array          as A
-import qualified Data.Bifunctor      as B
-import qualified Data.List.Split     as LS
-import qualified Data.Tuple          as T
-import qualified GHC.Generics        as G
+import qualified Data.Array as A
+import qualified Data.Bifunctor as B
+import qualified Data.Colour.RGBSpace as S
+import qualified Data.List.Split as LS
+import qualified Data.Tuple as T
+import qualified Data.Word as W
+import qualified GHC.Generics as G
 import qualified System.Console.ANSI as CA
 
 
@@ -39,11 +41,15 @@ type Bold     = Bool
 type Reversed = Bool
 
+data ColorInfo = ANSIColorInfo (CA.Color, CA.ColorIntensity)
+               | RGBColorInfo (S.Colour Float)
+               | PaletteColorInfo W.Word8
+               deriving (Show, Eq)
+
 -- can be an ASCIIChar or a special, transparent character
-data Cell = CellChar Char Bold
-                     Reversed (Maybe (CA.Color, CA.ColorIntensity))
+data Cell = CellChar Char Bold Reversed (Maybe ColorInfo)
           | Transparent
-          deriving (Show, Eq, Ord, G.Generic)
+          deriving (Show, Eq, G.Generic)
         -- I found no meaningful speed improvements by making this
         -- only w/ 1 constructor.
 
@@ -88,9 +94,17 @@           chm = win32SafeChar ch
 
 colorCell :: CA.Color -> CA.ColorIntensity -> Cell -> Cell
-colorCell k i (CellChar c b r _) = CellChar c b r (Just (k, i))
+colorCell k i (CellChar c b r _) = CellChar c b r (Just $ ANSIColorInfo (k, i))
 colorCell _ _ Transparent        = Transparent
 
+rgbColorCell :: S.Colour Float -> Cell -> Cell
+rgbColorCell k (CellChar c b r _) = CellChar c b r (Just $ RGBColorInfo k)
+rgbColorCell _ Transparent        = Transparent
+
+paletteColorCell :: W.Word8 -> Cell -> Cell
+paletteColorCell k (CellChar c b r _) = CellChar c b r (Just $ PaletteColorInfo k)
+paletteColorCell _ Transparent        = Transparent
+
 boldCell :: Cell -> Cell
 boldCell (CellChar c _ r k) = CellChar c True r k
 boldCell Transparent        = Transparent
@@ -180,7 +194,7 @@ cellChar (CellChar c _ _ _) = c
 cellChar Transparent        = ' '
 
-cellColor :: Cell -> Maybe (CA.Color, CA.ColorIntensity)
+cellColor :: Cell -> Maybe ColorInfo
 cellColor (CellChar _ _ _ k) = k
 cellColor Transparent        = Nothing