forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate colored into a module (microsoft#2057)
* Encapsulate colored into a module * lint fix * add missing file * undo change * conform with original colored func * change import strategy --------- Co-authored-by: Eric Zhu <[email protected]>
- Loading branch information
1 parent
6745731
commit e35db7e
Showing
9 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, Literal | ||
|
||
try: | ||
from termcolor import colored | ||
except ImportError: | ||
# termcolor is an optional dependency - if it cannot be imported then no color is used. | ||
# Alternatively the envvar NO_COLOR can be used to disable color. | ||
# To allow for proper typing and for termcolor to be optional we need to re-define the types used in the lib here. | ||
# This is the direct function definition from termcolor. | ||
Attribute = Literal[ | ||
"bold", | ||
"dark", | ||
"underline", | ||
"blink", | ||
"reverse", | ||
"concealed", | ||
] | ||
|
||
Highlight = Literal[ | ||
"on_black", | ||
"on_grey", | ||
"on_red", | ||
"on_green", | ||
"on_yellow", | ||
"on_blue", | ||
"on_magenta", | ||
"on_cyan", | ||
"on_light_grey", | ||
"on_dark_grey", | ||
"on_light_red", | ||
"on_light_green", | ||
"on_light_yellow", | ||
"on_light_blue", | ||
"on_light_magenta", | ||
"on_light_cyan", | ||
"on_white", | ||
] | ||
|
||
Color = Literal[ | ||
"black", | ||
"grey", | ||
"red", | ||
"green", | ||
"yellow", | ||
"blue", | ||
"magenta", | ||
"cyan", | ||
"light_grey", | ||
"dark_grey", | ||
"light_red", | ||
"light_green", | ||
"light_yellow", | ||
"light_blue", | ||
"light_magenta", | ||
"light_cyan", | ||
"white", | ||
] | ||
|
||
def colored( | ||
text: object, | ||
color: Color | None = None, | ||
on_color: Highlight | None = None, | ||
attrs: Iterable[Attribute] | None = None, | ||
*, | ||
no_color: bool | None = None, | ||
force_color: bool | None = None, | ||
) -> str: | ||
return str(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters