Skip to content

Commit c206022

Browse files
committed
docs(readme): add migration section
1 parent 9ae8548 commit c206022

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ print(cs.italic.green("Success!"))
4747
- Strip ANSI escape codes with `strip_ansi`
4848
- Friendly to [CLI arguments](#cli-arguments): `--color` & `--no-color`
4949
- Support for [common envs](#force_color-no_color-clicolor_force-and-clicolor): [`FORCE_COLOR`](https://force-color.org/), [`NO_COLOR`](https://no-color.org/), [`CLICOLOR_FORCE` & `CLICOLOR`](https://bixense.com/clicolors/)
50+
- Curious how **coloredstrings** compares to other libraries? See [Migrating from other libraries](#migrating-from-other-libraries)
5051

5152
---
5253

@@ -348,6 +349,89 @@ print(purple("Neither is `purple`."))
348349

349350
---
350351

352+
## Migrating from other libraries
353+
354+
If you’ve used other Python color or formatting libraries before, `coloredstrings` will feel familiar but more robust and consistent. Below is a quick comparison of how it differs from popular alternatives:
355+
356+
### **colorama**
357+
- **colorama** provides low-level ANSI control and Windows compatibility but lacks a fluent API.
358+
- `coloredstrings` supports more colors, styles and requires no use of ANSI codes directly.
359+
- Example:
360+
```python
361+
# colorama
362+
from colorama import Fore, Style
363+
print(Fore.RED + 'Error' + Style.RESET_ALL)
364+
365+
# coloredstrings
366+
import coloredstrings as cs
367+
print(cs.red('Error'))
368+
```
369+
370+
### **termcolor**
371+
- **termcolor** focuses on basic named colors but doesn’t support chaining or RGB.
372+
- `coloredstrings` supports truecolor, background colors, attributes, and chaining.
373+
- Example:
374+
```python
375+
# termcolor
376+
from termcolor import colored
377+
print(colored('Warning!', 'yellow', attrs=['bold']))
378+
379+
# coloredstrings
380+
import coloredstrings as cs
381+
print(cs.bold.yellow('Warning!'))
382+
```
383+
- `coloredstrings` lacks nested styling bug presented in **termcolor**:
384+
```python
385+
# termcolor
386+
from termcolor import colored
387+
print(colored('Warning!', 'yellow', attrs=['bold']))
388+
389+
# coloredstrings
390+
import coloredstrings as cs
391+
print(cs.bold.yellow('Warning!'))
392+
```
393+
394+
### **yachalk**
395+
- **yachalk** inspired `coloredstrings`, but its mutable style builders can cause side effects.
396+
- `coloredstrings`’s `StyleBuilder` is **immutable**, ensuring no cross-contamination between styles.
397+
- Chain syntax and API are nearly identical expect that you don't need to remember a separate method for background coloring.
398+
- Example:
399+
```python
400+
# yachalk
401+
from yachalk import chalk
402+
print(chalk.blue.bg_red.bold("Hello world!"))
403+
404+
# coloredstrings
405+
import coloredstrings as cs
406+
print(cs.blue.on.red.blod("Hello world!"))
407+
```
408+
409+
### **rich**
410+
- **rich** is a full-featured library for terminal formatting, tables, markdown, and logging.
411+
- It’s excellent for large applications but too heavy for simple coloring.
412+
- `coloredstrings` aims to be **minimal, dependency-free, and Pythonic** for everyday terminal styling.
413+
- Example:
414+
```python
415+
# rich
416+
from rich.console import Console
417+
Console().print('[bold red]Error[/bold red] Something went wrong')
418+
419+
# coloredstrings
420+
import coloredstrings as cs
421+
print(cs.bold.red('Error:'), 'Something went wrong')
422+
```
423+
424+
In short:
425+
| Library | No dependencies | Chainable | Truecolor | Immutable Styles | No nested styling bug | Focus |
426+
|----------|---------------|------------|-------------|------------------|----|----|
427+
| colorama |||||| Compatibility |
428+
| termcolor |||||| Simplicity |
429+
| yachalk |||||| Modern styling |
430+
| rich |||||| Full-featured UI |
431+
| **coloredstrings** |||||| Lightweight styling |
432+
433+
---
434+
351435
## Contributing
352436

353437
I’d love your help to make coloredstrings even better!

0 commit comments

Comments
 (0)