termstr: Let termstr's style be given with optional arguments
This commit is contained in:
parent
6deb413090
commit
b82dbc3d71
2 changed files with 4 additions and 1 deletions
|
|
@ -211,7 +211,7 @@ def join(seperator, parts):
|
|||
|
||||
class TermStr(collections.UserString):
|
||||
|
||||
def __init__(self, data, style=CharStyle()):
|
||||
def __init__(self, data, style=CharStyle(), **kwargs):
|
||||
if isinstance(style, tuple):
|
||||
self.data = data
|
||||
self.style = style
|
||||
|
|
@ -220,6 +220,8 @@ class TermStr(collections.UserString):
|
|||
self.data, self.style = data.data, data.style
|
||||
except AttributeError:
|
||||
self.data = _pad_wide_chars(data).expandtabs()
|
||||
if kwargs != {}:
|
||||
style = CharStyle(**kwargs)
|
||||
self.style = (style,) * len(self.data)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ class TermStrTests(unittest.TestCase):
|
|||
self.assertEqual(baz[2:], termstr.TermStr(" z"))
|
||||
baz = termstr.TermStr("⭐⭐")
|
||||
self.assertEqual(len(baz), 4)
|
||||
self.assertEqual(termstr.TermStr("foo", is_bold=True), termstr.TermStr("foo").bold())
|
||||
|
||||
def test_from_term(self):
|
||||
def test_round_trip(term_str):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue