Giter Site home page Giter Site logo

style's Introduction

style

Build Status PyPI version

style is a simple terminal string styling package. Its API is a port of the popular chalk package for javascript.

Install

$ pip install style

Usage

import style

print(style.red('Hello', style.bold('world') + '!'))

API

style.style*[.style](*objects, sep=' ')

Chain styles and call the last one as a method with an argument. Order doesn't matter, and later styles take precedence in case of a conflict, e.g. style.red.yellow.green is equivalent to style.green. Styles can be nested.

Multiple arguments will be separated by sep, a space by default.

style.enabled

Color support is automatically detected, but can also be changed manually.

  • set style.enabled to True or False
  • use the command line parameter --color or --no-color

Styles

+---------------------+-------------------------------------+-------------------------------------------+ | Modifiers | Colors | Background colors | +=====================+===============+=====================+==================+========================+ | - bold | - black | - light_black | - on_black | - on_light_black | | - dim | - red | - light_red | - on_red | - on_light_red | | - italic | - green | - light_green | - on_green | - on_light_green | | - underline | - yellow | - light_yellow | - on_yellow | - on_light_yellow | | - inverse | - blue | - light_blue | - on_blue | - on_light_blue | | - hidden | - magenta | - light_magenta | - on_magenta | - on_light_magenta | | - strikethrough | - cyan | - light_cyan | - on_cyan | - on_light_cyan | | | - white | - light_white | - on_white | - on_light_white | +---------------------+---------------+---------------------+------------------+------------------------+

style's People

Contributors

lmittmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

style's Issues

How to turn off bold?

Great package! Usability question:

Say I've got:

print(style.white('โ€ข', style.bold.white(' [{}] {}'.format(name, style.dim.white('{}'.format(msg))))))

I want to replace 'dim' with just the normal, unbolded text... but I can't figure out how to do that. i.e., I want to turn off bold after using it in the same line.

3 tests failing

Are these tests currently failing for anyone else?

test_multiple_strings (clr.test.test_style_builder.StyleBuilderTestCase) ... FAIL
test_single_string (clr.test.test_style_builder.StyleBuilderTestCase) ... FAIL
test_style_chaining (clr.test.test_style_builder.StyleBuilderTestCase) ... FAIL

======================================================================
FAIL: test_multiple_strings (clr.test.test_style_builder.StyleBuilderTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-style-1.0.0.drv-0/source/clr/test/test_style_builder.py", line 16, in test_multiple_strings
    self.assertTrue('31' in clr.red('test1', 'test2'))
AssertionError: False is not true

======================================================================
FAIL: test_single_string (clr.test.test_style_builder.StyleBuilderTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-style-1.0.0.drv-0/source/clr/test/test_style_builder.py", line 11, in test_single_string
    self.assertTrue('31' in clr.red('test'))
AssertionError: False is not true

======================================================================
FAIL: test_style_chaining (clr.test.test_style_builder.StyleBuilderTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-style-1.0.0.drv-0/source/clr/test/test_style_builder.py", line 20, in test_style_chaining
    self.assertTrue('31;47;1' in clr.red.bgWhite.bold('test'))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 3 tests in 0.001s

FAILED (failures=3)

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.