add color print

This commit is contained in:
Jaewook Lee
2024-07-20 22:20:57 +09:00
parent 2ee43369eb
commit 3e520e18e3

15
color-print/README.md Normal file
View File

@@ -0,0 +1,15 @@
```python
def rprint(*args, color='blue', sep=' ', end='\n', flush=False):
palette = ['black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white']
color = f'\033[3{palette.index(color)}m'
RESET = "\033[0m"
print(f'{color}{sep.join(args)}{RESET}', end=end, flush=flush)
rprint('hello') # blue 'hello'
rprint('hello', color='red') # red 'hello'
```