MCPcopy
hub / github.com/Textualize/textual / Span

Class Span

src/textual/content.py:83–128  ·  view source on GitHub ↗

A style applied to a range of character offsets.

Source from the content-addressed store, hash-verified

81
82@rich.repr.auto
83class Span(NamedTuple):
84 """A style applied to a range of character offsets."""
85
86 start: int
87 end: int
88 style: Style | str
89
90 def __rich_repr__(self) -> rich.repr.Result:
91 yield self.start
92 yield self.end
93 yield "style", self.style
94
95 def extend(self, cells: int) -> "Span":
96 """Extend the span by the given number of cells.
97
98 Args:
99 cells (int): Additional space to add to end of span.
100
101 Returns:
102 Span: A span.
103 """
104 if cells:
105 start, end, style = self
106 return Span(start, end + cells, style)
107 return self
108
109 def _shift(self, distance: int) -> "Span":
110 """Shift a span a given distance.
111
112 Note that the start offset is clamped to 0.
113 The end offset is not clamped, as it is assumed this has already been checked by the caller.
114
115 Args:
116 distance: Number of characters to move.
117
118 Returns:
119 New Span.
120 """
121 if distance < 0:
122 start, end, style = self
123 return Span(
124 offset if (offset := start + distance) > 0 else 0, end + distance, style
125 )
126 else:
127 start, end, style = self
128 return Span(start + distance, end + distance, style)
129
130
131@rich.repr.auto

Callers 15

highlightFunction · 0.90
_to_contentFunction · 0.90
close_tagMethod · 0.90
test_highlightFunction · 0.90
test_from_rich_textFunction · 0.90
test_styledFunction · 0.90
test_getitemFunction · 0.90
test_stylizeFunction · 0.90
test_stylize_beforeFunction · 0.90
test_addFunction · 0.90
test_raddFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_highlightFunction · 0.72
test_from_rich_textFunction · 0.72
test_styledFunction · 0.72
test_getitemFunction · 0.72
test_stylizeFunction · 0.72
test_stylize_beforeFunction · 0.72
test_addFunction · 0.72
test_raddFunction · 0.72
test_from_markupFunction · 0.72
test_joinFunction · 0.72
test_assembleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…