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 .globals import SCRIPT_NAME, SERVERS, W, TYPING_NOTICE_TIMEOUT
|
||||
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",
|
||||
|
@ -1446,7 +1451,9 @@ class RoomBuffer(object):
|
|||
"message{del_color}>{ncolor}").format(
|
||||
del_color=W.color("chat_delimiters"),
|
||||
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
|
||||
|
||||
|
|
|
@ -35,7 +35,9 @@ from pygments.util import ClassNotFound
|
|||
|
||||
from . import globals as G
|
||||
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:
|
||||
from HTMLParser import HTMLParser
|
||||
|
@ -59,10 +61,12 @@ class Formatted(object):
|
|||
|
||||
@property
|
||||
def textwrapper(self):
|
||||
quote_pair = color_pair(G.CONFIG.color.quote_fg,
|
||||
G.CONFIG.color.quote_bg)
|
||||
return textwrap.TextWrapper(
|
||||
width=67,
|
||||
initial_indent="{}> ".format(W.color(G.CONFIG.color.quote)),
|
||||
subsequent_indent="{}> ".format(W.color(G.CONFIG.color.quote)),
|
||||
initial_indent="{}> ".format(W.color(quote_pair)),
|
||||
subsequent_indent="{}> ".format(W.color(quote_pair)),
|
||||
)
|
||||
|
||||
def is_formatted(self):
|
||||
|
@ -302,8 +306,10 @@ class Formatted(object):
|
|||
try:
|
||||
lexer = get_lexer_by_name(value)
|
||||
except ClassNotFound:
|
||||
return string_color_and_reset(string,
|
||||
G.CONFIG.color.untagged_code)
|
||||
return string_color_and_reset(
|
||||
string,
|
||||
color_pair(G.CONFIG.color.untagged_code_fg,
|
||||
G.CONFIG.color.untagged_code_bg))
|
||||
|
||||
try:
|
||||
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 key == "code" and attributes["quote"]:
|
||||
fg = G.CONFIG.color.quote_fg
|
||||
bg = G.CONFIG.color.quote_bg
|
||||
text = indent(
|
||||
text,
|
||||
"{}>{} ".format(
|
||||
W.color(G.CONFIG.color.quote), W.color("reset")
|
||||
),
|
||||
string_color_and_reset(">", color_pair(fg, bg)) + " ",
|
||||
)
|
||||
|
||||
# If we're code don't remove multiple newlines blindly
|
||||
|
|
|
@ -642,44 +642,80 @@ class MatrixConfig(WeechatConfig):
|
|||
|
||||
color_options = [
|
||||
Option(
|
||||
"quote",
|
||||
"quote_fg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"lightgreen",
|
||||
("Color for matrix style blockquotes"),
|
||||
"Foreground color for matrix style blockquotes",
|
||||
),
|
||||
Option(
|
||||
"error_message",
|
||||
"quote_bg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"default",
|
||||
"Background counterpart of quote_fg",
|
||||
),
|
||||
Option(
|
||||
"error_message_fg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"darkgray",
|
||||
("Color for error messages that appear inside a room buffer ("
|
||||
"e.g. when a message errors out when sending or when a "
|
||||
"message is redacted)"),
|
||||
("Foreground color for error messages that appear inside a "
|
||||
"room buffer (e.g. when a message errors out when sending or "
|
||||
"when a message is redacted)"),
|
||||
),
|
||||
Option(
|
||||
"unconfirmed_message",
|
||||
"error_message_bg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"default",
|
||||
"Background counterpart of error_message_fg.",
|
||||
),
|
||||
Option(
|
||||
"unconfirmed_message_fg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"darkgray",
|
||||
("Color for messages that are printed out but the server "
|
||||
"hasn't confirmed the that he received them."),
|
||||
("Foreground color for messages that are printed out but the "
|
||||
"server hasn't confirmed the that he received them."),
|
||||
),
|
||||
Option(
|
||||
"untagged_code",
|
||||
"unconfirmed_message_bg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"default",
|
||||
"Background counterpart of unconfirmed_message_fg."
|
||||
),
|
||||
Option(
|
||||
"untagged_code_fg",
|
||||
"color",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"blue",
|
||||
("Color for code without a language specifier. Also used for "
|
||||
"`inline code`."),
|
||||
("Foreground color for code without a language specifier. "
|
||||
"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 = W.string_remove_color(plain_message, "")
|
||||
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(
|
||||
plain_message,
|
||||
attributes
|
||||
|
|
|
@ -123,3 +123,12 @@ def string_color(string, color):
|
|||
lines = ("{}{}{}".format(W.color(color), line, W.color("resetcolor"))
|
||||
for line in 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