@@ -101,23 +101,22 @@ def width_of_current_line(self) -> int:
101
101
"""Return an estimate of the width so far in the current line."""
102
102
return get_line_width (self ._current_line )
103
103
104
- def markup (self , text : str , ** kw : bool ) -> str :
105
- esc = []
106
- for name in kw :
104
+ def markup (self , text : str , ** markup : bool ) -> str :
105
+ for name in markup :
107
106
if name not in self ._esctable :
108
107
raise ValueError ("unknown markup: {!r}" .format (name ))
109
- if kw [ name ] :
110
- esc . append ( self ._esctable [name ])
111
- if esc and self . hasmarkup :
112
- text = "" .join ("\x1b [%sm" % cod for cod in esc ) + text + "\x1b [0m"
108
+ if self . hasmarkup :
109
+ esc = [ self ._esctable [name ] for name , on in markup . items () if on ]
110
+ if esc :
111
+ text = "" .join ("\x1b [%sm" % cod for cod in esc ) + text + "\x1b [0m"
113
112
return text
114
113
115
114
def sep (
116
115
self ,
117
116
sepchar : str ,
118
117
title : Optional [str ] = None ,
119
118
fullwidth : Optional [int ] = None ,
120
- ** kw : bool
119
+ ** markup : bool
121
120
) -> None :
122
121
if fullwidth is None :
123
122
fullwidth = self .fullwidth
@@ -147,26 +146,24 @@ def sep(
147
146
if len (line ) + len (sepchar .rstrip ()) <= fullwidth :
148
147
line += sepchar .rstrip ()
149
148
150
- self .line (line , ** kw )
149
+ self .line (line , ** markup )
151
150
152
- def write (self , msg : str , * , flush : bool = False , ** kw : bool ) -> None :
151
+ def write (self , msg : str , * , flush : bool = False , ** markup : bool ) -> None :
153
152
if msg :
154
153
current_line = msg .rsplit ("\n " , 1 )[- 1 ]
155
154
if "\n " in msg :
156
155
self ._current_line = current_line
157
156
else :
158
157
self ._current_line += current_line
159
158
160
- if self .hasmarkup and kw :
161
- markupmsg = self .markup (msg , ** kw )
162
- else :
163
- markupmsg = msg
164
- self ._file .write (markupmsg )
159
+ msg = self .markup (msg , ** markup )
160
+
161
+ self ._file .write (msg )
165
162
if flush :
166
163
self .flush ()
167
164
168
- def line (self , s : str = "" , ** kw : bool ) -> None :
169
- self .write (s , ** kw )
165
+ def line (self , s : str = "" , ** markup : bool ) -> None :
166
+ self .write (s , ** markup )
170
167
self .write ("\n " )
171
168
172
169
def flush (self ) -> None :
0 commit comments