Giter VIP home page Giter VIP logo

colourista's People

Contributors

chshersh avatar danieljharvey avatar dependabot[bot] avatar felixonmars avatar mpilgrem avatar skaex avatar tfausak avatar tomjaguarpaw avatar vrom911 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

colourista's Issues

Add unicode indicators to *Message functions

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...

Font modifications are not applied in Windows

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)
image
Cmd (with chcp 65001) behaves similarly.

Add some tests

Not sure, as a separate test suite or with doctest, but it would be nice to have some simple automatic tests E.g.:

  • Verify that yellow adds proper code by default
  • Verify that formatWith works

Ability to choose any RGB color

As I saw currently user can only select colours mentioned in this data type.

https://github.com/feuerbach/ansi-terminal/blob/5d65f48485182320ea05f90b5b002003515c089b/src/System/Console/ANSI/Types.hs#L39-L47

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.
πŸŽ„ πŸŽ… 🎁

Cleanup repo

  • Common stanzas
  • Delete redundant stack.yamls
  • Use GHC-8.8.2

Colourista.Short

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 ?

[RFC] Ability to disable and enable colouring

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:

  1. Allows specifying the colour only in a single place in the application.
  2. Colours the text by default, if no option is specified.
  3. Doesn't involve code duplication.
  4. Doesn't require code recompilation to change colouring settings.

I'll describe one possible solution below.

-XImplicitParams

One way to do this is to use the ImplicitParams Haskell language extension. It contains the following parts:

  1. Implement simple enum to control colouring mode.
    data ColourMode = EnableColour | DisableColour
  2. Introduce a constraint with implicit params:
    type HasColourMode = (?colourMode :: ColourMode)
  3. Patch each function to pattern-math on a colour:
    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 #-}
  4. Implement magic instance described in this blog post to make EnableColour default:
    -- ?color = EnableColor
    instance IP "colourMode" ColourMode where
        ip = EnableColour

Cons and pros

Implementation cost: patch each function.

Pros:

  1. All existing code should work without any changes.
  2. We can easily disable/enable colouring by defining a single variable in a single module after we parse --no-colour option or something like this.

Cons

  1. Each function that performs colouring or calls colouring function should add HasColourMode constraint.
  2. You don't have compile-time guarantees if you forget to add such constraint somewhere.
  3. This involves using non-common GHC feature.

Additionally we need to add tests for this:

  • Check that disabling colour mode actually disables colour codes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.