String styling for your terminal.
.. image:: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_logo_aliased.svg :target: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_logo_aliased.svg :alt: sty_logo :width: 30% :class: intro-logo
|
|badge-total-downloads| |badge-monthly-downloads|
.. |badge-total-downloads| image:: https://static.pepy.tech/personalized-badge/sty?period=total&units=international_system&left_color=grey&right_color=lightgrey&left_text=downloads :target: https://static.pepy.tech/personalized-badge/sty?period=total&units=international_system&left_color=grey&right_color=lightgrey&left_text=downloads :alt: badge-total-downloads
.. |badge-monthly-downloads| image:: https://static.pepy.tech/personalized-badge/sty?period=month&units=international_system&left_color=grey&right_color=lightgrey&left_text=downloads/month :target: https://static.pepy.tech/personalized-badge/sty?period=month&units=international_system&left_color=grey&right_color=lightgrey&left_text=downloads/month :alt: badge-monthly-downloads
.. image:: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_demo.png :target: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_demo.png :alt: sty_demo :width: 100%
Code Changes:
Code Changes:
py.typed
file for better typing support. Thanks! @Eisfunkefrom .lib import
is now from sty.lib import
.help(x)
should be much more useful now.Other:
pipenv
with poetry
.make.py
build system.Sty's goal is to provide Python with a simple, customizable and performant string styling markup, which is decoupled from color palettes and terminal implementations.
bold
, italic
, underline
, etc.shim <https://github.com/feluxe/sty/issues/2#issuecomment-501890699>
__ to work.colorama
overrides sys.stdout
which causes a lot of trouble.semver <https://semver.org/>
__.>=3.7
for as long as possible.If you run into compatibility problems with sty, please file an issue <https://github.com/feluxe/sty/issues>
__!
.. code:: python
from sty import fg, bg, ef, rs
foo = fg.red + 'This is red text!' + fg.rs
bar = bg.blue + 'This has a blue background!' + bg.rs
baz = ef.italic + 'This is italic text' + rs.italic
qux = fg(201) + 'This is pink text using 8bit colors' + fg.rs
qui = fg(255, 10, 10) + 'This is red text using 24bit colors.' + fg.rs
# Add custom colors:
from sty import Style, RgbFg
fg.orange = Style(RgbFg(255, 150, 50))
buf = fg.orange + 'Yay, Im orange.' + fg.rs
print(foo, bar, baz, qux, qui, buf, sep='\n')
The code above will print like this in the terminal:
.. image:: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_example.png :target: https://raw.githubusercontent.com/feluxe/sty/master/assets/README_example.png :alt: example :width: 600px
You can use the Register
class or the default registers FgRegister
, BgRegister
, EfRegister
and RsRegister
to create your own registers:
.. code:: python
# Extending the default FgRegister
from sty import FgRegister, Style, RgbFg, Sgr
class MyFgRegister(FgRegister):
def __init__(self):
super().__init__()
self.purple = Style(Sgr(35))
self.blue = Style(Sgr(34))
self.orange = Style(RgbFg(255, 128, 0))
# ...
fg = MyFgRegister()
Documentation-Website: https://sty.mewo.dev
Documentation-Website-Source: https://github.com/feluxe/sty-docs