From 439c6cf24e89730d3271baf10e5706df1cdecedf Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:36:28 +0200 Subject: [PATCH] treewide: add and apply stylish-haskell Link: https://github.com/danth/stylix/pull/519 --- flake.nix | 1 + palette-generator/Ai/Evolutionary.hs | 14 +++++++------- palette-generator/Data/Colour.hs | 8 ++++---- palette-generator/Stylix/Main.hs | 20 ++++++++++---------- palette-generator/Stylix/Output.hs | 8 ++++---- palette-generator/Stylix/Palette.hs | 24 +++++++++++++----------- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/flake.nix b/flake.nix index 2a2108d7..c05fbfee 100644 --- a/flake.nix +++ b/flake.nix @@ -101,6 +101,7 @@ hooks = { deadnix.enable = true; statix.enable = true; + stylish-haskell.enable = true; typos.enable = true; yamllint.enable = true; }; diff --git a/palette-generator/Ai/Evolutionary.hs b/palette-generator/Ai/Evolutionary.hs index 634bfd11..c6a0c8be 100644 --- a/palette-generator/Ai/Evolutionary.hs +++ b/palette-generator/Ai/Evolutionary.hs @@ -2,12 +2,12 @@ module Ai.Evolutionary ( Species(..), evolve ) where -import Data.Ord ( Down(Down), comparing ) -import Data.Vector ( (!) ) -import qualified Data.Vector as V -import Data.Vector.Algorithms.Intro ( selectBy ) -import System.Random ( randomRIO ) -import Text.Printf ( printf ) +import Data.Ord (Down (Down), comparing) +import Data.Vector ((!)) +import qualified Data.Vector as V +import Data.Vector.Algorithms.Intro (selectBy) +import System.Random (randomRIO) +import Text.Printf (printf) numSurvivors :: Int numSurvivors = 500 @@ -96,7 +96,7 @@ selectSurvivors environment population = shouldContinue :: [Double] -- ^ Fitness history -> Bool shouldContinue (x:y:_) = x /= y -shouldContinue _ = True +shouldContinue _ = True evolutionLoop :: Species e g => e -- ^ Environment diff --git a/palette-generator/Data/Colour.hs b/palette-generator/Data/Colour.hs index db189062..45dc33d3 100644 --- a/palette-generator/Data/Colour.hs +++ b/palette-generator/Data/Colour.hs @@ -1,13 +1,13 @@ module Data.Colour ( LAB(..), RGB(..), deltaE, lab2rgb, rgb2lab ) where data LAB = LAB { lightness :: Double - , channelA :: Double - , channelB :: Double + , channelA :: Double + , channelB :: Double } -data RGB = RGB { red :: Double +data RGB = RGB { red :: Double , green :: Double - , blue :: Double + , blue :: Double } -- Based on https://github.com/antimatter15/rgb-lab/blob/master/color.js diff --git a/palette-generator/Stylix/Main.hs b/palette-generator/Stylix/Main.hs index d4a49e60..2170d624 100644 --- a/palette-generator/Stylix/Main.hs +++ b/palette-generator/Stylix/Main.hs @@ -1,13 +1,13 @@ -import Ai.Evolutionary ( evolve ) -import Codec.Picture ( DynamicImage, convertRGB8, readImage ) -import Data.Colour ( lab2rgb ) -import qualified Data.Vector as V -import Stylix.Output ( makeOutputTable ) -import Stylix.Palette ( ) -import System.Environment ( getArgs ) -import System.Exit ( die ) -import System.Random ( setStdGen, mkStdGen ) -import Text.JSON ( encode ) +import Ai.Evolutionary (evolve) +import Codec.Picture (DynamicImage, convertRGB8, readImage) +import Data.Colour (lab2rgb) +import qualified Data.Vector as V +import Stylix.Output (makeOutputTable) +import Stylix.Palette () +import System.Environment (getArgs) +import System.Exit (die) +import System.Random (mkStdGen, setStdGen) +import Text.JSON (encode) -- | Load an image file. loadImage :: String -- ^ Path to the file diff --git a/palette-generator/Stylix/Output.hs b/palette-generator/Stylix/Output.hs index 9d6733cf..682d4212 100644 --- a/palette-generator/Stylix/Output.hs +++ b/palette-generator/Stylix/Output.hs @@ -1,10 +1,10 @@ module Stylix.Output ( makeOutputTable ) where -import Data.Colour ( RGB(RGB) ) +import Data.Colour (RGB (RGB)) import qualified Data.Vector as V -import Data.Word ( Word8 ) -import Text.JSON ( JSObject, toJSObject ) -import Text.Printf ( printf ) +import Data.Word (Word8) +import Text.JSON (JSObject, toJSObject) +import Text.Printf (printf) toHexNum :: Double -> Word8 toHexNum = truncate diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 1102a338..1b8b0d78 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -1,14 +1,16 @@ -{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} module Stylix.Palette ( ) where -import Ai.Evolutionary ( Species(..) ) -import Codec.Picture ( Image(imageWidth, imageHeight), PixelRGB8(PixelRGB8), pixelAt ) -import Data.Colour ( LAB(lightness), RGB(RGB), deltaE, rgb2lab ) -import Data.List ( delete ) -import Data.Vector ( (//) ) -import qualified Data.Vector as V -import System.Random ( randomRIO ) +import Ai.Evolutionary (Species (..)) +import Codec.Picture (Image (imageHeight, imageWidth), + PixelRGB8 (PixelRGB8), pixelAt) +import Data.Colour (LAB (lightness), RGB (RGB), deltaE, rgb2lab) +import Data.List (delete) +import Data.Vector ((//)) +import qualified Data.Vector as V +import System.Random (randomRIO) -- | Extract the primary scale from a palette. primary :: V.Vector a -> V.Vector a @@ -73,9 +75,9 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where scheme = case polarity of "either" -> min lightScheme darkScheme - "light" -> lightScheme - "dark" -> darkScheme - _ -> error ("Invalid polarity: " ++ polarity) + "light" -> lightScheme + "dark" -> darkScheme + _ -> error ("Invalid polarity: " ++ polarity) {- For light themes, the background is bright and the text is dark.