Skip to content

Colored text output in Python using ANSI escape sequences

License

Notifications You must be signed in to change notification settings

jeremyephron/styled-str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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):

pip3 install styled-str

Usage

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

from styled_str import Styled

s = Styled('Hello World! ', fg='cyan', bg='white', style=['bold', 'underlined'])

# Print it out
print(s)

# Use it in a larger string
print("He said, '" + s + "'")

# Format it worry-free!
print(f'Title: {s:>20}')

# String functions logically operate on underlying data
print(s.strip()) # prints styled 'Hello World!'

# ...and much more!

About

Colored text output in Python using ANSI escape sequences

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages