Support full color pair (fg/bg) for each color.
This commit is contained in:
parent
041c15e811
commit
141814bb84
5 changed files with 82 additions and 23 deletions
|
@ -53,7 +53,12 @@ from .colors import Formatted
|
||||||
from .config import RedactType
|
from .config import RedactType
|
||||||
from .globals import SCRIPT_NAME, SERVERS, W, TYPING_NOTICE_TIMEOUT
|
from .globals import SCRIPT_NAME, SERVERS, W, TYPING_NOTICE_TIMEOUT
|
||||||
from .utf import utf8_decode
|
from .utf import utf8_decode
|
||||||
from .utils import server_ts_to_weechat, shorten_sender, string_strikethrough
|
from .utils import (
|
||||||
|
server_ts_to_weechat,
|
||||||
|
shorten_sender,
|
||||||
|
string_strikethrough,
|
||||||
|
color_pair,
|
||||||
|
)
|
||||||
|
|
||||||
OwnMessages = NamedTuple(
|
OwnMessages = NamedTuple(
|
||||||
"OwnMessages",
|
"OwnMessages",
|
||||||
|
@ -1446,7 +1451,9 @@ class RoomBuffer(object):
|
||||||
"message{del_color}>{ncolor}").format(
|
"message{del_color}>{ncolor}").format(
|
||||||
del_color=W.color("chat_delimiters"),
|
del_color=W.color("chat_delimiters"),
|
||||||
ncolor=W.color("reset"),
|
ncolor=W.color("reset"),
|
||||||
error_color=W.color(G.CONFIG.color.error_message))
|
error_color=W.color(color_pair(
|
||||||
|
G.CONFIG.color.error_message_fg,
|
||||||
|
G.CONFIG.color.error_message_bg)))
|
||||||
|
|
||||||
last_line.message = message
|
last_line.message = message
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,9 @@ from pygments.util import ClassNotFound
|
||||||
|
|
||||||
from . import globals as G
|
from . import globals as G
|
||||||
from .globals import W
|
from .globals import W
|
||||||
from .utils import string_strikethrough, string_color_and_reset
|
from .utils import (string_strikethrough,
|
||||||
|
string_color_and_reset,
|
||||||
|
color_pair)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from HTMLParser import HTMLParser
|
from HTMLParser import HTMLParser
|
||||||
|
@ -59,10 +61,12 @@ class Formatted(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def textwrapper(self):
|
def textwrapper(self):
|
||||||
|
quote_pair = color_pair(G.CONFIG.color.quote_fg,
|
||||||
|
G.CONFIG.color.quote_bg)
|
||||||
return textwrap.TextWrapper(
|
return textwrap.TextWrapper(
|
||||||
width=67,
|
width=67,
|
||||||
initial_indent="{}> ".format(W.color(G.CONFIG.color.quote)),
|
initial_indent="{}> ".format(W.color(quote_pair)),
|
||||||
subsequent_indent="{}> ".format(W.color(G.CONFIG.color.quote)),
|
subsequent_indent="{}> ".format(W.color(quote_pair)),
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_formatted(self):
|
def is_formatted(self):
|
||||||
|
@ -302,8 +306,10 @@ class Formatted(object):
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_by_name(value)
|
lexer = get_lexer_by_name(value)
|
||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
return string_color_and_reset(string,
|
return string_color_and_reset(
|
||||||
G.CONFIG.color.untagged_code)
|
string,
|
||||||
|
color_pair(G.CONFIG.color.untagged_code_fg,
|
||||||
|
G.CONFIG.color.untagged_code_bg))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
style = get_style_by_name(G.CONFIG.look.pygments_style)
|
style = get_style_by_name(G.CONFIG.look.pygments_style)
|
||||||
|
@ -361,11 +367,11 @@ class Formatted(object):
|
||||||
|
|
||||||
# If we're quoted code add quotation marks now.
|
# If we're quoted code add quotation marks now.
|
||||||
if key == "code" and attributes["quote"]:
|
if key == "code" and attributes["quote"]:
|
||||||
|
fg = G.CONFIG.color.quote_fg
|
||||||
|
bg = G.CONFIG.color.quote_bg
|
||||||
text = indent(
|
text = indent(
|
||||||
text,
|
text,
|
||||||
"{}>{} ".format(
|
string_color_and_reset(">", color_pair(fg, bg)) + " ",
|
||||||
W.color(G.CONFIG.color.quote), W.color("reset")
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# If we're code don't remove multiple newlines blindly
|
# If we're code don't remove multiple newlines blindly
|
||||||
|
|
|
@ -642,44 +642,80 @@ class MatrixConfig(WeechatConfig):
|
||||||
|
|
||||||
color_options = [
|
color_options = [
|
||||||
Option(
|
Option(
|
||||||
"quote",
|
"quote_fg",
|
||||||
"color",
|
"color",
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"lightgreen",
|
"lightgreen",
|
||||||
("Color for matrix style blockquotes"),
|
"Foreground color for matrix style blockquotes",
|
||||||
),
|
),
|
||||||
Option(
|
Option(
|
||||||
"error_message",
|
"quote_bg",
|
||||||
|
"color",
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"default",
|
||||||
|
"Background counterpart of quote_fg",
|
||||||
|
),
|
||||||
|
Option(
|
||||||
|
"error_message_fg",
|
||||||
"color",
|
"color",
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"darkgray",
|
"darkgray",
|
||||||
("Color for error messages that appear inside a room buffer ("
|
("Foreground color for error messages that appear inside a "
|
||||||
"e.g. when a message errors out when sending or when a "
|
"room buffer (e.g. when a message errors out when sending or "
|
||||||
"message is redacted)"),
|
"when a message is redacted)"),
|
||||||
),
|
),
|
||||||
Option(
|
Option(
|
||||||
"unconfirmed_message",
|
"error_message_bg",
|
||||||
|
"color",
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"default",
|
||||||
|
"Background counterpart of error_message_fg.",
|
||||||
|
),
|
||||||
|
Option(
|
||||||
|
"unconfirmed_message_fg",
|
||||||
"color",
|
"color",
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"darkgray",
|
"darkgray",
|
||||||
("Color for messages that are printed out but the server "
|
("Foreground color for messages that are printed out but the "
|
||||||
"hasn't confirmed the that he received them."),
|
"server hasn't confirmed the that he received them."),
|
||||||
),
|
),
|
||||||
Option(
|
Option(
|
||||||
"untagged_code",
|
"unconfirmed_message_bg",
|
||||||
|
"color",
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"default",
|
||||||
|
"Background counterpart of unconfirmed_message_fg."
|
||||||
|
),
|
||||||
|
Option(
|
||||||
|
"untagged_code_fg",
|
||||||
"color",
|
"color",
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"blue",
|
"blue",
|
||||||
("Color for code without a language specifier. Also used for "
|
("Foreground color for code without a language specifier. "
|
||||||
"`inline code`."),
|
"Also used for `inline code`."),
|
||||||
|
),
|
||||||
|
Option(
|
||||||
|
"untagged_code_bg",
|
||||||
|
"color",
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"default",
|
||||||
|
"Background counterpart of untagged_code_fg",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -798,7 +798,8 @@ class MatrixServer(object):
|
||||||
plain_message = formatted.to_weechat()
|
plain_message = formatted.to_weechat()
|
||||||
plain_message = W.string_remove_color(plain_message, "")
|
plain_message = W.string_remove_color(plain_message, "")
|
||||||
attributes = DEFAULT_ATTRIBUTES.copy()
|
attributes = DEFAULT_ATTRIBUTES.copy()
|
||||||
attributes["fgcolor"] = G.CONFIG.color.unconfirmed_message
|
attributes["fgcolor"] = G.CONFIG.color.unconfirmed_message_fg
|
||||||
|
attributes["bgcolor"] = G.CONFIG.color.unconfirmed_message_bg
|
||||||
new_formatted = Formatted([FormattedString(
|
new_formatted = Formatted([FormattedString(
|
||||||
plain_message,
|
plain_message,
|
||||||
attributes
|
attributes
|
||||||
|
|
|
@ -123,3 +123,12 @@ def string_color(string, color):
|
||||||
lines = ("{}{}{}".format(W.color(color), line, W.color("resetcolor"))
|
lines = ("{}{}{}".format(W.color(color), line, W.color("resetcolor"))
|
||||||
for line in lines)
|
for line in lines)
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def color_pair(color_fg, color_bg):
|
||||||
|
"""Make a color pair from a pair of colors."""
|
||||||
|
|
||||||
|
if color_bg:
|
||||||
|
return "{},{}".format(color_fg, color_bg)
|
||||||
|
else:
|
||||||
|
return color_fg
|
||||||
|
|
Loading…
Add table
Reference in a new issue