Skip to content

Add irc.utils.irc_color_to_ansi()#249

Merged
prologic merged 1 commit intomasterfrom
irc_ansi_color
Sep 18, 2018
Merged

Add irc.utils.irc_color_to_ansi()#249
prologic merged 1 commit intomasterfrom
irc_ansi_color

Conversation

@spaceone
Copy link
Copy Markdown
Contributor

Translates IRC color/bold/etc codes into ANSI escape sequences, so that the output can be printed on a terminal.

Example:

from circuits.protocols.irc.utils import irc_color_to_ansi
colorstring = '\x0300white\x03 \x0301black\x03 \x0302blue\x03 \x0303green\x03 \x0304red\x03 '
colorstring += '\x0305brown\x03 \x0306magenta\x03 \x0307orange\x03 \x0308yellow\x03 '
colorstring += '\x0309lightgreen\x03 \x0310cyan\x03 \x0311lightcyan\x03 \x0312lightblue\x03 '
colorstring += '\x0313pink\x03 \x0314grey\x03 \x0315lightgrey\x03\x0f'
print(irc_color_to_ansi('hi \x02bold\x02 \x1ditalic\x1d \x1funderline\x1f \x1estrikethrough\x1e'))
print(irc_color_to_ansi(colorstring))
print(irc_color_to_ansi(colorstring.replace(' \x03', ' \x0301,')))

@spaceone spaceone requested a review from prologic September 17, 2018 22:49
@spaceone spaceone self-assigned this Sep 17, 2018
@spaceone
Copy link
Copy Markdown
Contributor Author

prologic
prologic previously approved these changes Sep 18, 2018
from circuits.protocols.irc.utils import irc_color_to_ansi
colorstring = '\x0300white\x03 \x0301black\x03 \x0302blue\x03 \x0303green\x03 \x0304red\x03 '
colorstring += '\x0305brown\x03 \x0306magenta\x03 \x0307orange\x03 \x0308yellow\x03 '
colorstring += '\x0309lightgreen\x03 \x0310cyan\x03 \x0311lightcyan\x03 \x0312lightblue\x03 '
colorstring += '\x0313pink\x03 \x0314grey\x03 \x0315lightgrey\x03\x0f'
print(irc_color_to_ansi('hi \x02bold\x02 \x1ditalic\x1d \x1funderline\x1f \x1estrikethrough\x1e'))
print(irc_color_to_ansi(colorstring))
print(irc_color_to_ansi(colorstring.replace(' \x03', ' \x0301,')))
@spaceone
Copy link
Copy Markdown
Contributor Author

I added a test case :-)

@prologic prologic merged commit 4923743 into master Sep 18, 2018
@spaceone spaceone deleted the irc_ansi_color branch November 29, 2018 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants