OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python311
/
lib
/
python3.11
/
site-packages
/
rich
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
01/09/2025 02:18:04 AM
rwxr-xr-x
📄
__init__.py
5.92 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
__main__.py
8.14 KB
05/14/2024 03:18:15 PM
rw-r--r--
📁
__pycache__
-
05/14/2024 03:18:15 PM
rwxr-xr-x
📄
_cell_widths.py
9.97 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_emoji_codes.py
136.95 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_emoji_replace.py
1.04 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_export_format.py
2.08 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_extension.py
241 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
_fileno.py
799 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
_inspect.py
9.47 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_log_render.py
3.14 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_loop.py
1.21 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_null_file.py
1.35 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_palettes.py
6.9 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_pick.py
423 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
_ratio.py
5.33 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_spinners.py
19.45 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_stack.py
351 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
_timer.py
417 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
_win32_console.py
22.25 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_windows.py
1.86 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_windows_renderer.py
2.69 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
_wrap.py
3.32 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
abc.py
878 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
align.py
10.08 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
ansi.py
6.74 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
bar.py
3.19 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
box.py
10.53 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
cells.py
4.67 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
color.py
17.8 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
color_triplet.py
1.03 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
columns.py
6.96 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
console.py
96.78 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
constrain.py
1.26 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
containers.py
5.37 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
control.py
6.45 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
default_styles.py
7.86 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
diagnose.py
924 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
emoji.py
2.41 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
errors.py
642 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
file_proxy.py
1.64 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
filesize.py
2.45 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
highlighter.py
9.36 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
json.py
4.9 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
jupyter.py
3.15 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
layout.py
13.62 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
live.py
13.94 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
live_render.py
3.57 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
logging.py
11.61 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
markdown.py
25.55 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
markup.py
8.23 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
measure.py
5.18 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
padding.py
4.84 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
pager.py
828 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
palette.py
3.21 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
panel.py
10.45 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
pretty.py
34.97 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
progress.py
58.3 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
progress_bar.py
7.97 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
prompt.py
11.03 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
protocol.py
1.33 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
py.typed
0 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
region.py
166 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
repr.py
4.32 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
rule.py
4.48 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
scope.py
2.76 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
screen.py
1.54 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
segment.py
23.64 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
spinner.py
4.24 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
status.py
4.32 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
style.py
26.44 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
styled.py
1.21 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
syntax.py
34.54 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
table.py
38.71 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
terminal_theme.py
3.29 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
text.py
46.19 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
theme.py
3.69 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
themes.py
102 bytes
05/14/2024 03:18:15 PM
rw-r--r--
📄
traceback.py
28.84 KB
05/14/2024 03:18:15 PM
rw-r--r--
📄
tree.py
8.89 KB
05/14/2024 03:18:15 PM
rw-r--r--
Editing: align.py
Close
import sys from itertools import chain from typing import TYPE_CHECKING, Iterable, Optional if sys.version_info >= (3, 8): from typing import Literal else: from typing_extensions import Literal # pragma: no cover from .constrain import Constrain from .jupyter import JupyterMixin from .measure import Measurement from .segment import Segment from .style import StyleType if TYPE_CHECKING: from .console import Console, ConsoleOptions, RenderableType, RenderResult AlignMethod = Literal["left", "center", "right"] VerticalAlignMethod = Literal["top", "middle", "bottom"] class Align(JupyterMixin): """Align a renderable by adding spaces if necessary. Args: renderable (RenderableType): A console renderable. align (AlignMethod): One of "left", "center", or "right"" style (StyleType, optional): An optional style to apply to the background. vertical (Optional[VerticalAlignMethod], optional): Optional vertical align, one of "top", "middle", or "bottom". Defaults to None. pad (bool, optional): Pad the right with spaces. Defaults to True. width (int, optional): Restrict contents to given width, or None to use default width. Defaults to None. height (int, optional): Set height of align renderable, or None to fit to contents. Defaults to None. Raises: ValueError: if ``align`` is not one of the expected values. """ def __init__( self, renderable: "RenderableType", align: AlignMethod = "left", style: Optional[StyleType] = None, *, vertical: Optional[VerticalAlignMethod] = None, pad: bool = True, width: Optional[int] = None, height: Optional[int] = None, ) -> None: if align not in ("left", "center", "right"): raise ValueError( f'invalid value for align, expected "left", "center", or "right" (not {align!r})' ) if vertical is not None and vertical not in ("top", "middle", "bottom"): raise ValueError( f'invalid value for vertical, expected "top", "middle", or "bottom" (not {vertical!r})' ) self.renderable = renderable self.align = align self.style = style self.vertical = vertical self.pad = pad self.width = width self.height = height def __repr__(self) -> str: return f"Align({self.renderable!r}, {self.align!r})" @classmethod def left( cls, renderable: "RenderableType", style: Optional[StyleType] = None, *, vertical: Optional[VerticalAlignMethod] = None, pad: bool = True, width: Optional[int] = None, height: Optional[int] = None, ) -> "Align": """Align a renderable to the left.""" return cls( renderable, "left", style=style, vertical=vertical, pad=pad, width=width, height=height, ) @classmethod def center( cls, renderable: "RenderableType", style: Optional[StyleType] = None, *, vertical: Optional[VerticalAlignMethod] = None, pad: bool = True, width: Optional[int] = None, height: Optional[int] = None, ) -> "Align": """Align a renderable to the center.""" return cls( renderable, "center", style=style, vertical=vertical, pad=pad, width=width, height=height, ) @classmethod def right( cls, renderable: "RenderableType", style: Optional[StyleType] = None, *, vertical: Optional[VerticalAlignMethod] = None, pad: bool = True, width: Optional[int] = None, height: Optional[int] = None, ) -> "Align": """Align a renderable to the right.""" return cls( renderable, "right", style=style, vertical=vertical, pad=pad, width=width, height=height, ) def __rich_console__( self, console: "Console", options: "ConsoleOptions" ) -> "RenderResult": align = self.align width = console.measure(self.renderable, options=options).maximum rendered = console.render( Constrain( self.renderable, width if self.width is None else min(width, self.width) ), options.update(height=None), ) lines = list(Segment.split_lines(rendered)) width, height = Segment.get_shape(lines) lines = Segment.set_shape(lines, width, height) new_line = Segment.line() excess_space = options.max_width - width style = console.get_style(self.style) if self.style is not None else None def generate_segments() -> Iterable[Segment]: if excess_space <= 0: # Exact fit for line in lines: yield from line yield new_line elif align == "left": # Pad on the right pad = Segment(" " * excess_space, style) if self.pad else None for line in lines: yield from line if pad: yield pad yield new_line elif align == "center": # Pad left and right left = excess_space // 2 pad = Segment(" " * left, style) pad_right = ( Segment(" " * (excess_space - left), style) if self.pad else None ) for line in lines: if left: yield pad yield from line if pad_right: yield pad_right yield new_line elif align == "right": # Padding on left pad = Segment(" " * excess_space, style) for line in lines: yield pad yield from line yield new_line blank_line = ( Segment(f"{' ' * (self.width or options.max_width)}\n", style) if self.pad else Segment("\n") ) def blank_lines(count: int) -> Iterable[Segment]: if count > 0: for _ in range(count): yield blank_line vertical_height = self.height or options.height iter_segments: Iterable[Segment] if self.vertical and vertical_height is not None: if self.vertical == "top": bottom_space = vertical_height - height iter_segments = chain(generate_segments(), blank_lines(bottom_space)) elif self.vertical == "middle": top_space = (vertical_height - height) // 2 bottom_space = vertical_height - top_space - height iter_segments = chain( blank_lines(top_space), generate_segments(), blank_lines(bottom_space), ) else: # self.vertical == "bottom": top_space = vertical_height - height iter_segments = chain(blank_lines(top_space), generate_segments()) else: iter_segments = generate_segments() if self.style: style = console.get_style(self.style) iter_segments = Segment.apply_style(iter_segments, style) yield from iter_segments def __rich_measure__( self, console: "Console", options: "ConsoleOptions" ) -> Measurement: measurement = Measurement.get(console, options, self.renderable) return measurement class VerticalCenter(JupyterMixin): """Vertically aligns a renderable. Warn: This class is deprecated and may be removed in a future version. Use Align class with `vertical="middle"`. Args: renderable (RenderableType): A renderable object. """ def __init__( self, renderable: "RenderableType", style: Optional[StyleType] = None, ) -> None: self.renderable = renderable self.style = style def __repr__(self) -> str: return f"VerticalCenter({self.renderable!r})" def __rich_console__( self, console: "Console", options: "ConsoleOptions" ) -> "RenderResult": style = console.get_style(self.style) if self.style is not None else None lines = console.render_lines( self.renderable, options.update(height=None), pad=False ) width, _height = Segment.get_shape(lines) new_line = Segment.line() height = options.height or options.size.height top_space = (height - len(lines)) // 2 bottom_space = height - top_space - len(lines) blank_line = Segment(f"{' ' * width}", style) def blank_lines(count: int) -> Iterable[Segment]: for _ in range(count): yield blank_line yield new_line if top_space > 0: yield from blank_lines(top_space) for line in lines: yield from line yield new_line if bottom_space > 0: yield from blank_lines(bottom_space) def __rich_measure__( self, console: "Console", options: "ConsoleOptions" ) -> Measurement: measurement = Measurement.get(console, options, self.renderable) return measurement if __name__ == "__main__": # pragma: no cover from rich.console import Console, Group from rich.highlighter import ReprHighlighter from rich.panel import Panel highlighter = ReprHighlighter() console = Console() panel = Panel( Group( Align.left(highlighter("align='left'")), Align.center(highlighter("align='center'")), Align.right(highlighter("align='right'")), ), width=60, style="on dark_blue", title="Align", ) console.print( Align.center(panel, vertical="middle", style="on red", height=console.height) )