colors: Colorize matrix block quotes.
This commit is contained in:
parent
c9ef4ac086
commit
7f71bf47a1
2 changed files with 20 additions and 7 deletions
|
@ -21,7 +21,7 @@ from __future__ import unicode_literals
|
||||||
# pylint: disable=redefined-builtin
|
# pylint: disable=redefined-builtin
|
||||||
from builtins import str
|
from builtins import str
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from matrix.globals import W
|
from matrix.globals import W, OPTIONS
|
||||||
from matrix.utils import string_strikethrough
|
from matrix.utils import string_strikethrough
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
@ -33,13 +33,9 @@ except ImportError:
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
import html
|
import html
|
||||||
from html.entities import name2codepoint
|
|
||||||
|
|
||||||
FormattedString = namedtuple('FormattedString', ['text', 'attributes'])
|
FormattedString = namedtuple('FormattedString', ['text', 'attributes'])
|
||||||
|
|
||||||
quote_wrapper = textwrap.TextWrapper(
|
|
||||||
initial_indent="> ", subsequent_indent="> ")
|
|
||||||
|
|
||||||
|
|
||||||
class Formatted():
|
class Formatted():
|
||||||
|
|
||||||
|
@ -47,6 +43,17 @@ class Formatted():
|
||||||
# type: (List[FormattedString]) -> None
|
# type: (List[FormattedString]) -> None
|
||||||
self.substrings = substrings
|
self.substrings = substrings
|
||||||
|
|
||||||
|
@property
|
||||||
|
def textwrapper(self):
|
||||||
|
return textwrap.TextWrapper(
|
||||||
|
width=67,
|
||||||
|
initial_indent="{}> ".format(
|
||||||
|
W.color(W.config_string(OPTIONS.options["quote"]))
|
||||||
|
),
|
||||||
|
subsequent_indent="{}> ".format(
|
||||||
|
W.color(W.config_string(OPTIONS.options["quote"]))
|
||||||
|
))
|
||||||
|
|
||||||
def is_formatted(self):
|
def is_formatted(self):
|
||||||
# type: (Formatted) -> bool
|
# type: (Formatted) -> bool
|
||||||
for string in self.substrings:
|
for string in self.substrings:
|
||||||
|
@ -268,7 +275,8 @@ class Formatted():
|
||||||
return string_strikethrough(string)
|
return string_strikethrough(string)
|
||||||
|
|
||||||
elif name == "quote" and value:
|
elif name == "quote" and value:
|
||||||
return quote_wrapper.fill(string.replace("\n", ""))
|
return self.textwrapper.fill(
|
||||||
|
W.string_remove_color(string.replace("\n", ""), ""))
|
||||||
|
|
||||||
elif name == "fgcolor" and value:
|
elif name == "fgcolor" and value:
|
||||||
return "{color_on}{text}{color_off}".format(
|
return "{color_on}{text}{color_off}".format(
|
||||||
|
|
|
@ -138,6 +138,11 @@ def matrix_config_init(config_file):
|
||||||
("Use a separate buffer for debug logs.")),
|
("Use a separate buffer for debug logs.")),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
color_options = [
|
||||||
|
Option("quote", "color", "", 0, 0, "lightgreen",
|
||||||
|
("Color for matrix style blockquotes"))
|
||||||
|
]
|
||||||
|
|
||||||
def add_global_options(section, options):
|
def add_global_options(section, options):
|
||||||
for option in options:
|
for option in options:
|
||||||
OPTIONS.options[option.name] = W.config_new_option(
|
OPTIONS.options[option.name] = W.config_new_option(
|
||||||
|
@ -149,7 +154,7 @@ def matrix_config_init(config_file):
|
||||||
section = W.config_new_section(config_file, "color", 0, 0, "", "", "", "",
|
section = W.config_new_section(config_file, "color", 0, 0, "", "", "", "",
|
||||||
"", "", "", "", "", "")
|
"", "", "", "", "", "")
|
||||||
|
|
||||||
# TODO color options
|
add_global_options(section, color_options)
|
||||||
|
|
||||||
section = W.config_new_section(config_file, "look", 0, 0, "", "", "", "",
|
section = W.config_new_section(config_file, "look", 0, 0, "", "", "", "",
|
||||||
"", "", "", "", "", "")
|
"", "", "", "", "", "")
|
||||||
|
|
Loading…
Add table
Reference in a new issue