@@ -179,6 +179,20 @@ def __init__(
179179 def __str__ (self ) -> str :
180180 return self ._text
181181
182+ @property
183+ def _is_regular (self ) -> bool :
184+ """Check if the line is regular (spans.start > span.end for all spans).
185+
186+ This is a debugging aid, and unlikely to be useful in your app.
187+
188+ Returns:
189+ `True` if the content is regular, `False` if it is not (and broken).
190+ """
191+ for span in self .spans :
192+ if span .end <= span .start :
193+ return False
194+ return True
195+
182196 @cached_property
183197 def markup (self ) -> str :
184198 """Get content markup to render this Text.
@@ -374,6 +388,26 @@ def styled(
374388 )
375389 return new_content
376390
391+ @classmethod
392+ def blank (cls , width : int , style : Style | str | None = None ) -> Content :
393+ """Get a Content instance consisting of spaces.
394+
395+ Args:
396+ width: Width of blank content (number of spaces).
397+ style: Style of blank.
398+
399+ Returns:
400+ Content instance.
401+ """
402+ if not width :
403+ return EMPTY_CONTENT
404+ blank = cls (
405+ " " * width ,
406+ [Span (0 , width , style )] if style else None ,
407+ cell_length = width ,
408+ )
409+ return blank
410+
377411 @classmethod
378412 def assemble (
379413 cls ,
@@ -431,7 +465,10 @@ def assemble(
431465 position += len (part .plain )
432466 if end :
433467 text_append (end )
434- return cls ("" .join (text ), spans , strip_control_codes = strip_control_codes )
468+ assembled_content = cls (
469+ "" .join (text ), spans , strip_control_codes = strip_control_codes
470+ )
471+ return assembled_content
435472
436473 def simplify (self ) -> Content :
437474 """Simplify spans by joining contiguous spans together.
@@ -786,19 +823,22 @@ def get_text_at(offset: int) -> "Content":
786823 if stop >= len (self .plain ):
787824 return self
788825 text = self .plain [:stop ]
789- return Content (
826+ sliced_content = Content (
790827 text ,
791828 self ._trim_spans (text , self ._spans ),
792829 strip_control_codes = False ,
793830 )
794831 else :
795832 text = self .plain [start :stop ]
796833 spans = [
797- span ._shift (- start ) for span in self ._spans if span .end > start
834+ span ._shift (- start )
835+ for span in self ._spans
836+ if span .end - start > 0
798837 ]
799- return Content (
838+ sliced_content = Content (
800839 text , self ._trim_spans (text , spans ), strip_control_codes = False
801840 )
841+ return sliced_content
802842
803843 else :
804844 # This would be a bit of work to implement efficiently
0 commit comments