#!/usr/bin/envstack{- stack
--resolver lts-13.30
--install-ghc
script
--ghc-options -Werror
--ghc-options -Wall
--
-}--------------------------------------------------------------------------------moduleMain(main)where--------------------------------------------------------------------------------importData.Word(Word8)importData.ANSI.EscapeCode(Colour(Black,Blue,Green,Red,Yellow),Frecuency(Fast),background,blink,bold,faint,foreground,italic,sgr,underline)--------------------------------------------------------------------------------codes::[String]codes=mapf[0..107]wheref::Word8->Stringfn="\ESC["++shown++"m "++gn++"\ESC[m"gn=leftpad3(Just' ')$shownmain::IO()main=(putStrLn"# As in the `Example of use in C`:")>>(mapM_(putStrLn.concat)$chunksOf10$codes)>>(putStrLn"")>>(putStrLn"# Using the Data.ANSI.EscapeCode module:")>>(putStrLn.show.f$t)>>(putStrLn.show.g$t)>>(putStrLn.show.h$t)wheref=bold.blinkFast.foregroundTrueYellow.backgroundFalseRed.sgrg=underline.foregroundFalseBlack.backgroundTrueGreen.sgrh=faint.italic.foregroundFalseBlack.backgroundTrueBlue.sgrt="this is just some text"---------------------------------------------------------------------------------- HELPERSleftpad::Int->MaybeChar->String->Stringleftpadnmx=ifl>nthenxelsereplicate(n-l)c++xwherel=lengthxc=casemofJustv->vNothing->'.'chunksOf::Int->[a]->[[a]]chunksOf_[]=[ ]chunksOfnbs=x:chunksOfnxswhere(x,xs)=splitAtnbs---------------------------------------------------------------------------------- References---- ANSI escape code:-- * https://en.wikipedia.org/wiki/ANSI_escape_code#Example_of_use_in_C
src/package.cabal
cabal-version: 1.12
name: package
version: 0.11.0.0
build-type: Simple
executable ansi-color
main-is:
Main.hs
other-modules:
Paths_package
Data.ANSI.EscapeCode
hs-source-dirs:
./.
ghc-options:
---------------------------------------------------------------------------
-- GHC 8.6.4 Users Guide > 9. Using GHC > 9.2. Warnings and sanity-checking
-- * Base: https://downloads.haskell.org/~ghc/8.6.4/docs/html/users_guide/
-- * File: using-warnings.html
-- Warnings that are not enabled by -Wall:
---------------------------------------------------------------------------
-Wall
-Wincomplete-record-updates
-- -Wmonomorphism-restriction
-- -Wimplicit-prelude
-- -Wmissing-local-signatures
-Wmissing-exported-signatures
-- -Wmissing-export-lists
-- -Wmissing-import-lists
-Wmissing-home-modules
-Widentities
-Wredundant-constraints
-- Added since GHC 8.4
-Wpartial-fields
-- -Wmissed-specialisations
-- -Wall-missed-specialisations
---------------------------------------------------------------------------
-- Added to allow instance definition in other files, in order to keep the
-- Effect module SAFE so it can be imported by the Process
---------------------------------------------------------------------------
-Wno-orphans
-- Makes any warning into a fatal error.
-Werror
---------------------------------------------------------------------------
-- Deterministic builds (Uniques):
-- * https://gitlab.haskell.org/ghc/ghc/wikis/deterministic-builds#progress
-- * https://www.youtube.com/watch?v=FNzTk4P4fL4 (08 GHC Determinism ICFP)
---------------------------------------------------------------------------
-dinitial-unique=0
-dunique-increment=1
---------------------------------------------------------------------------
-- The -N flag built-in can be modified on runtime based on the system
-- hosting the binary for optimal performance:
-- - https://hackage.haskell.org/package/base/docs/GHC-Conc.html
-- * getNumProcessors
-- - https://hackage.haskell.org/package/base/docs/Control-Concurrent.html
-- * setNumCapabilities
---------------------------------------------------------------------------
-- 12.40. Safe Haskell > ... > 12.40.1.1. Strict type-safety (good style)
-- * Enforce good style, similar to the function of -Wall.
-XSafe
-fpackage-trust
-trust=base
-- Only Trustworthy packages can be trusted
-- * Base: https://downloads.haskell.org/~ghc/8.6.4/docs/html/users_guide/
-- * File: safe_haskell.html
---------------------------------------------------------------------------
-O2
-threaded
-rtsopts
-with-rtsopts=-N
build-depends:
-- Prelude
base
default-language:
Haskell98
#!/usr/bin/env bash
clear
src="$(stack path --local-install-root)/bin"tgt="./bin"echo"### Clearing binary files:"
find $tgt-mindepth 1 -name"*"-delete-printecho
echo"### Stack cleaning and building:"
stack build
echo
echo"### Copying binary to local $tgt:"if[!-d$tgt];then
mkdir-p$tgt;fi
cp-v$src/*$tgt/
echo
bin=$(ls$tgt)# We need to ls after binaries are createdecho"### Repoducible hashes:"for f in$bin;do
echo-e$(sha256sum$tgt/$f | cut-d" "-f 1): $fdone;echo
Code Output:
./build.bash && ./bin/ansi-color
### Clearing binary files:
./bin/ansi-color
### Stack cleaning and building:
### Copying binary to local ./bin:
'/home/johndoe/code/haskell/ansi-color/.stack-work/install/x86_64-linux-nix/e07ba7d58ca3cbf46d17cb550fd0dc7ccd1bfc735df47120e593b662560d5c08/8.6.5/bin/ansi-color' -> './bin/ansi-color'
### Repoducible hashes:
75843be327c60bb8f6c210111320a6370eb0997261a46d904d32db7f3b490bc7: ansi-color