28
28
29
29
30
30
class AllowStyle (Enum ):
31
- """Values for ``cmd2.ansi.allow_style``"""
31
+ """Values for ``cmd2.ansi.allow_style``. """
32
32
33
33
ALWAYS = 'Always' # Always output ANSI style sequences
34
34
NEVER = 'Never' # Remove ANSI style sequences from all output
35
35
TERMINAL = 'Terminal' # Remove ANSI style sequences if the output is not going to the terminal
36
36
37
37
def __str__ (self ) -> str :
38
- """Return value instead of enum name for printing in cmd2's set command"""
38
+ """Return value instead of enum name for printing in cmd2's set command. """
39
39
return str (self .value )
40
40
41
41
def __repr__ (self ) -> str :
42
- """Return quoted value instead of enum description for printing in cmd2's set command"""
42
+ """Return quoted value instead of enum description for printing in cmd2's set command. """
43
43
return repr (self .value )
44
44
45
45
@@ -124,7 +124,7 @@ def widest_line(text: str) -> int:
124
124
125
125
126
126
def style_aware_write (fileobj : IO [str ], msg : str ) -> None :
127
- """Write a string to a fileobject and strip its ANSI style sequences if required by allow_style setting
127
+ """Write a string to a fileobject and strip its ANSI style sequences if required by allow_style setting.
128
128
129
129
:param fileobj: the file object being written to
130
130
:param msg: the string being written
@@ -183,63 +183,63 @@ def clear_line(clear_type: int = 2) -> str:
183
183
# Base classes which are not intended to be used directly
184
184
####################################################################################
185
185
class AnsiSequence :
186
- """Base class to create ANSI sequence strings"""
186
+ """Base class to create ANSI sequence strings. """
187
187
188
188
def __add__ (self , other : Any ) -> str :
189
189
"""Support building an ANSI sequence string when self is the left operand
190
- e.g. Fg.LIGHT_MAGENTA + "hello"
190
+ e.g. Fg.LIGHT_MAGENTA + "hello".
191
191
"""
192
192
return str (self ) + str (other )
193
193
194
194
def __radd__ (self , other : Any ) -> str :
195
195
"""Support building an ANSI sequence string when self is the right operand
196
- e.g. "hello" + Fg.RESET
196
+ e.g. "hello" + Fg.RESET.
197
197
"""
198
198
return str (other ) + str (self )
199
199
200
200
201
201
class FgColor (AnsiSequence ):
202
- """Base class for ANSI Sequences which set foreground text color"""
202
+ """Base class for ANSI Sequences which set foreground text color. """
203
203
204
204
205
205
class BgColor (AnsiSequence ):
206
- """Base class for ANSI Sequences which set background text color"""
206
+ """Base class for ANSI Sequences which set background text color. """
207
207
208
208
209
209
####################################################################################
210
210
# Implementations intended for direct use
211
211
####################################################################################
212
212
class Cursor :
213
- """Create ANSI sequences to alter the cursor position"""
213
+ """Create ANSI sequences to alter the cursor position. """
214
214
215
215
@staticmethod
216
216
def UP (count : int = 1 ) -> str :
217
- """Move the cursor up a specified amount of lines (Defaults to 1)"""
217
+ """Move the cursor up a specified amount of lines (Defaults to 1). """
218
218
return f"{ CSI } { count } A"
219
219
220
220
@staticmethod
221
221
def DOWN (count : int = 1 ) -> str :
222
- """Move the cursor down a specified amount of lines (Defaults to 1)"""
222
+ """Move the cursor down a specified amount of lines (Defaults to 1). """
223
223
return f"{ CSI } { count } B"
224
224
225
225
@staticmethod
226
226
def FORWARD (count : int = 1 ) -> str :
227
- """Move the cursor forward a specified amount of lines (Defaults to 1)"""
227
+ """Move the cursor forward a specified amount of lines (Defaults to 1). """
228
228
return f"{ CSI } { count } C"
229
229
230
230
@staticmethod
231
231
def BACK (count : int = 1 ) -> str :
232
- """Move the cursor back a specified amount of lines (Defaults to 1)"""
232
+ """Move the cursor back a specified amount of lines (Defaults to 1). """
233
233
return f"{ CSI } { count } D"
234
234
235
235
@staticmethod
236
236
def SET_POS (x : int , y : int ) -> str :
237
- """Set the cursor position to coordinates which are 1-based"""
237
+ """Set the cursor position to coordinates which are 1-based. """
238
238
return f"{ CSI } { y } ;{ x } H"
239
239
240
240
241
241
class TextStyle (AnsiSequence , Enum ):
242
- """Create text style ANSI sequences"""
242
+ """Create text style ANSI sequences. """
243
243
244
244
# Resets all styles and colors of text
245
245
RESET_ALL = 0
@@ -264,7 +264,7 @@ class TextStyle(AnsiSequence, Enum):
264
264
def __str__ (self ) -> str :
265
265
"""Return ANSI text style sequence instead of enum name
266
266
This is helpful when using a TextStyle in an f-string or format() call
267
- e.g. my_str = f"{TextStyle.UNDERLINE_ENABLE}hello{TextStyle.UNDERLINE_DISABLE}"
267
+ e.g. my_str = f"{TextStyle.UNDERLINE_ENABLE}hello{TextStyle.UNDERLINE_DISABLE}".
268
268
"""
269
269
return f"{ CSI } { self .value } m"
270
270
@@ -297,7 +297,7 @@ class Fg(FgColor, Enum):
297
297
def __str__ (self ) -> str :
298
298
"""Return ANSI color sequence instead of enum name
299
299
This is helpful when using an Fg in an f-string or format() call
300
- e.g. my_str = f"{Fg.BLUE}hello{Fg.RESET}"
300
+ e.g. my_str = f"{Fg.BLUE}hello{Fg.RESET}".
301
301
"""
302
302
return f"{ CSI } { self .value } m"
303
303
@@ -330,7 +330,7 @@ class Bg(BgColor, Enum):
330
330
def __str__ (self ) -> str :
331
331
"""Return ANSI color sequence instead of enum name
332
332
This is helpful when using a Bg in an f-string or format() call
333
- e.g. my_str = f"{Bg.BLACK}hello{Bg.RESET}"
333
+ e.g. my_str = f"{Bg.BLACK}hello{Bg.RESET}".
334
334
"""
335
335
return f"{ CSI } { self .value } m"
336
336
@@ -601,7 +601,7 @@ class EightBitFg(FgColor, Enum):
601
601
def __str__ (self ) -> str :
602
602
"""Return ANSI color sequence instead of enum name
603
603
This is helpful when using an EightBitFg in an f-string or format() call
604
- e.g. my_str = f"{EightBitFg.SLATE_BLUE_1}hello{Fg.RESET}"
604
+ e.g. my_str = f"{EightBitFg.SLATE_BLUE_1}hello{Fg.RESET}".
605
605
"""
606
606
return f"{ CSI } 38;5;{ self .value } m"
607
607
@@ -872,7 +872,7 @@ class EightBitBg(BgColor, Enum):
872
872
def __str__ (self ) -> str :
873
873
"""Return ANSI color sequence instead of enum name
874
874
This is helpful when using an EightBitBg in an f-string or format() call
875
- e.g. my_str = f"{EightBitBg.KHAKI_3}hello{Bg.RESET}"
875
+ e.g. my_str = f"{EightBitBg.KHAKI_3}hello{Bg.RESET}".
876
876
"""
877
877
return f"{ CSI } 48;5;{ self .value } m"
878
878
@@ -883,7 +883,7 @@ class RgbFg(FgColor):
883
883
"""
884
884
885
885
def __init__ (self , r : int , g : int , b : int ) -> None :
886
- """RgbFg initializer
886
+ """RgbFg initializer.
887
887
888
888
:param r: integer from 0-255 for the red component of the color
889
889
:param g: integer from 0-255 for the green component of the color
@@ -898,7 +898,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
898
898
def __str__ (self ) -> str :
899
899
"""Return ANSI color sequence instead of enum name
900
900
This is helpful when using an RgbFg in an f-string or format() call
901
- e.g. my_str = f"{RgbFg(0, 55, 100)}hello{Fg.RESET}"
901
+ e.g. my_str = f"{RgbFg(0, 55, 100)}hello{Fg.RESET}".
902
902
"""
903
903
return self ._sequence
904
904
@@ -909,7 +909,7 @@ class RgbBg(BgColor):
909
909
"""
910
910
911
911
def __init__ (self , r : int , g : int , b : int ) -> None :
912
- """RgbBg initializer
912
+ """RgbBg initializer.
913
913
914
914
:param r: integer from 0-255 for the red component of the color
915
915
:param g: integer from 0-255 for the green component of the color
@@ -924,7 +924,7 @@ def __init__(self, r: int, g: int, b: int) -> None:
924
924
def __str__ (self ) -> str :
925
925
"""Return ANSI color sequence instead of enum name
926
926
This is helpful when using an RgbBg in an f-string or format() call
927
- e.g. my_str = f"{RgbBg(100, 255, 27)}hello{Bg.RESET}"
927
+ e.g. my_str = f"{RgbBg(100, 255, 27)}hello{Bg.RESET}".
928
928
"""
929
929
return self ._sequence
930
930
0 commit comments