项目作者: jeremyephron

项目描述 :
Colored text output in Python using ANSI escape sequences
高级语言: Python
项目地址: git://github.com/jeremyephron/styled-str.git
创建时间: 2019-12-20T15:07:48Z
项目社区:https://github.com/jeremyephron/styled-str

开源协议:MIT License

下载


styled-str

styled-str is a package for creating strings styled with ANSI escape sequences.
The motivation for writing this package was that many existing string-styling
modules do not implement logical string behavior, like properly formatting the
string, indexing, containment, all of which are useless if they don’t ignore
the styling.

The Styled object should exhibit logical behavior with respect to all string
functions.

Installation

Install using pip (Python3):

  1. pip3 install styled-str

Usage

Import the module and create a string with your desired styles:

  1. from styled_str import Styled
  2. s = Styled('Hello World! ', fg='cyan', bg='white', style=['bold', 'underlined'])
  3. # Print it out
  4. print(s)
  5. # Use it in a larger string
  6. print("He said, '" + s + "'")
  7. # Format it worry-free!
  8. print(f'Title: {s:>20}')
  9. # String functions logically operate on underlying data
  10. print(s.strip()) # prints styled 'Hello World!'
  11. # ...and much more!