MCPcopy
hub / github.com/Textualize/rich / make_syntax

Function make_syntax

examples/fullscreen.py:86–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84
85
86def make_syntax() -> Syntax:
87 code = """\
88def ratio_resolve(total: int, edges: List[Edge]) -> List[int]:
89 sizes = [(edge.size or None) for edge in edges]
90
91 # While any edges haven't been calculated
92 while any(size is None for size in sizes):
93 # Get flexible edges and index to map these back on to sizes list
94 flexible_edges = [
95 (index, edge)
96 for index, (size, edge) in enumerate(zip(sizes, edges))
97 if size is None
98 ]
99 # Remaining space in total
100 remaining = total - sum(size or 0 for size in sizes)
101 if remaining <= 0:
102 # No room for flexible edges
103 sizes[:] = [(size or 0) for size in sizes]
104 break
105 # Calculate number of characters in a ratio portion
106 portion = remaining / sum((edge.ratio or 1) for _, edge in flexible_edges)
107
108 # If any edges will be less than their minimum, replace size with the minimum
109 for index, edge in flexible_edges:
110 if portion * edge.ratio <= edge.minimum_size:
111 sizes[index] = edge.minimum_size
112 break
113 else:
114 # Distribute flexible space and compensate for rounding error
115 # Since edge sizes can only be integers we need to add the remainder
116 # to the following line
117 _modf = modf
118 remainder = 0.0
119 for index, edge in flexible_edges:
120 remainder, size = _modf(portion * edge.ratio + remainder)
121 sizes[index] = int(size)
122 break
123 # Sizes now contains integers only
124 return cast(List[int], sizes)
125 """
126 syntax = Syntax(code, "python", line_numbers=True)
127 return syntax
128
129
130job_progress = Progress(

Callers 1

fullscreen.pyFile · 0.85

Calls 1

SyntaxClass · 0.90

Tested by

no test coverage detected