kowainik / colourista Goto Github PK
View Code? Open in Web Editor NEWβοΈβπ Convenient interface for printing colourful messages
Home Page: https://kowainik.github.io/projects/colourista
License: Mozilla Public License 2.0
βοΈβπ Convenient interface for printing colourful messages
Home Page: https://kowainik.github.io/projects/colourista
License: Mozilla Public License 2.0
even though there are no build errors caused by the library itself
We have human-readable aliases for IO printing functions. Currently they are just aliases to corresponding functions blueMessage
, yellowMessage
, etc. But I thought that maybe they can append some indicator to hint their meaning. Currently I can think only of the following unicode symbols:
successMessage
: βinfoMessage
: βWe also have:
skipMessage
warningMessage
errorMessage
So when you info infoMessage "Some information"
, you will have
β Some information
What do you think? We need to decide on symbols for other functions as well...
Formatting with bold
and italic
has no effect when running in powershell/cmd on Windows (win10, winver=1809). Most probably, this is a limitation of the underlying ansi-terminal
, not colourista
, but I wanted to make this known nevertheless.
Example (colourista-0.0.0.0, lts-15.0, ghc-8.8.2):
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Colourista
main :: IO ()
main = do
putStrLn $ formatWith [bold, red, cyanBg] "ΠΠΈΡΠΈΠ»Π»ΠΈΡΠ° bold red cyanBg"
putStrLn $ formatWith [bold, red, cyanBg] "Latin bold red cyanBg"
putStrLn $ formatWith [bold, italic, red, cyanBg] "Latin bold italic red cyanBg"
putStrLn $ formatWith [] "Latin"
successMessage "Done"
yields in my powershell (with required unicode-enabling settings, of course)
Cmd (with chcp 65001
) behaves similarly.
Not sure, as a separate test suite or with doctest
, but it would be nice to have some simple automatic tests E.g.:
yellow
adds proper code by defaultformatWith
worksAnd remove Travis and AppVeyor.
As I saw currently user can only select colours mentioned in this data type.
There shouldn't be too difficult to add additional function and maybe data type to wrap Colour
from colour
package so that user can write a message with any foreground or background colour (thanks to the this line). That would require to add colour
package in the dependency list and to add some additional function available for users. If you think that this is a good idea, I can start working on this.
π π
π
Often enough we write code like
myFormat s = red <> bold <> s <> reset
I think we should have a function like this:
formatWith :: [String] -> (String/Text) -> (String/Text)
So it can be called like this:
formatWith [red, bold] myText
stack.yaml
sDifferent functions to work with prompt.
Example functions:
https://github.com/kowainik/summoner/blob/60de4f2f087e5bd2beaad9253e7eded731cfbaaf/summoner-cli/src/Summoner/Question.hs
Specifically, colourista-0.1.0.1
can be expanded to base < 4.19
.
To specify indentation:
indent :: IsString str => Int -> str
I find myself writing
b :: Text -> Text
b = formatWith [bold]
i :: Text -> Text
i = formatWith [italic]
again and again.
I propose to add a module in colourista
with such functions for faster small styling.
What do you think @chshersh ?
It would be nice if colourista
could support automatic disabling and enabling of colouring, so we can easily disable/enable colours in our code. We want to have a solution that satisfies the following requirements:
I'll describe one possible solution below.
One way to do this is to use the ImplicitParams
Haskell language extension. It contains the following parts:
data ColourMode = EnableColour | DisableColour
type HasColourMode = (?colourMode :: ColourMode)
withColourMode :: (HasColourMode, IsString str) => str -> str
withColourMode = case ?colourMode of
EnableColour -> str
DisableColour -> ""
red :: (HasColourMode, IsString str) => str
red = withColourMode $ fromString $ setSGRCode [SetColor Foreground Vivid Red]
{-# SPECIALIZE red :: HasColourMode => String #-}
{-# SPECIALIZE red :: HasColourMode => Text #-}
{-# SPECIALIZE red :: HasColourMode => ByteString #-}
EnableColour
default:
-- ?color = EnableColor
instance IP "colourMode" ColourMode where
ip = EnableColour
Implementation cost: patch each function.
Pros:
--no-colour
option or something like this.Cons
HasColourMode
constraint.Additionally we need to add tests for this:
Of course, only if it's possible.
See this comment: #9 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.