Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
pip._vendor.rich.syntax.Syntax Class Reference
Inheritance diagram for pip._vendor.rich.syntax.Syntax:
Inheritance graph
[legend]
Collaboration diagram for pip._vendor.rich.syntax.Syntax:
Collaboration graph
[legend]

Public Member Functions

SyntaxTheme get_theme (cls, Union[str, SyntaxTheme] name)
 
None __init__ (self, str code, Union[Lexer, str] lexer, *Union[str, SyntaxTheme] theme=DEFAULT_THEME, bool dedent=False, bool line_numbers=False, int start_line=1, Optional[Tuple[Optional[int], Optional[int]]] line_range=None, Optional[Set[int]] highlight_lines=None, Optional[int] code_width=None, int tab_size=4, bool word_wrap=False, Optional[str] background_color=None, bool indent_guides=False, PaddingDimensions padding=0)
 
"Syntax" from_path (cls, str path, str encoding="utf-8", Optional[Union[Lexer, str]] lexer=None, Union[str, SyntaxTheme] theme=DEFAULT_THEME, bool dedent=False, bool line_numbers=False, Optional[Tuple[int, int]] line_range=None, int start_line=1, Optional[Set[int]] highlight_lines=None, Optional[int] code_width=None, int tab_size=4, bool word_wrap=False, Optional[str] background_color=None, bool indent_guides=False, PaddingDimensions padding=0)
 
str guess_lexer (cls, str path, Optional[str] code=None)
 
Optional[Lexerlexer (self)
 
Text highlight (self, str code, Optional[Tuple[Optional[int], Optional[int]]] line_range=None)
 
None stylize_range (self, StyleType style, SyntaxPosition start, SyntaxPosition end)
 
"Measurement" __rich_measure__ (self, "Console" console, "ConsoleOptions" options)
 
RenderResult __rich_console__ (self, Console console, ConsoleOptions options)
 

Public Attributes

 code
 
 dedent
 
 line_numbers
 
 start_line
 
 line_range
 
 highlight_lines
 
 code_width
 
 tab_size
 
 word_wrap
 
 background_color
 
 background_style
 
 indent_guides
 
 padding
 

Protected Member Functions

Style _get_base_style (self)
 
Optional[Color_get_token_color (self, TokenType token_type)
 
Color _get_line_numbers_color (self, float blend=0.3)
 
int _numbers_column_width (self)
 
Tuple[Style, Style, Style_get_number_styles (self, Console console)
 
Iterable[Segment_get_syntax (self, Console console, ConsoleOptions options)
 
None _apply_stylized_ranges (self, Text text)
 
Tuple[bool, str] _process_code (self, str code)
 
- Protected Member Functions inherited from pip._vendor.rich.jupyter.JupyterMixin
Dict[str, str] _repr_mimebundle_ ("ConsoleRenderable" self, Sequence[str] include, Sequence[str] exclude, **Any kwargs)
 

Protected Attributes

 _lexer
 
 _theme
 
 _numbers_column_width
 

Static Protected Attributes

Type _pygments_style_class [PygmentsStyle]
 
SyntaxTheme _theme
 

Detailed Description

Construct a Syntax object to render syntax highlighted code.

Args:
    code (str): Code to highlight.
    lexer (Lexer | str): Lexer to use (see https://pygments.org/docs/lexers/)
    theme (str, optional): Color theme, aka Pygments style (see https://pygments.org/docs/styles/#getting-a-list-of-available-styles). Defaults to "monokai".
    dedent (bool, optional): Enable stripping of initial whitespace. Defaults to False.
    line_numbers (bool, optional): Enable rendering of line numbers. Defaults to False.
    start_line (int, optional): Starting number for line numbers. Defaults to 1.
    line_range (Tuple[int | None, int | None], optional): If given should be a tuple of the start and end line to render.
        A value of None in the tuple indicates the range is open in that direction.
    highlight_lines (Set[int]): A set of line numbers to highlight.
    code_width: Width of code to render (not including line numbers), or ``None`` to use all available width.
    tab_size (int, optional): Size of tabs. Defaults to 4.
    word_wrap (bool, optional): Enable word wrapping.
    background_color (str, optional): Optional background color, or None to use theme color. Defaults to None.
    indent_guides (bool, optional): Show indent guides. Defaults to False.
    padding (PaddingDimensions): Padding to apply around the syntax. Defaults to 0 (no padding).

Member Function Documentation

◆ _apply_stylized_ranges()

None pip._vendor.rich.syntax.Syntax._apply_stylized_ranges (   self,
Text  text 
)
protected
Apply stylized ranges to a text instance,
using the given code to determine the right portion to apply the style to.

Args:
    text (Text): Text instance to apply the style to.

◆ _get_base_style()

Style pip._vendor.rich.syntax.Syntax._get_base_style (   self)
protected
Get the base style.

◆ _get_number_styles()

Tuple[Style, Style, Style] pip._vendor.rich.syntax.Syntax._get_number_styles (   self,
Console  console 
)
protected
Get background, number, and highlight styles for line numbers.

◆ _get_syntax()

Iterable[Segment] pip._vendor.rich.syntax.Syntax._get_syntax (   self,
Console  console,
ConsoleOptions  options 
)
protected
Get the Segments for the Syntax object, excluding any vertical/horizontal padding

◆ _get_token_color()

Optional[Color] pip._vendor.rich.syntax.Syntax._get_token_color (   self,
TokenType  token_type 
)
protected
Get a color (if any) for the given token.

Args:
    token_type (TokenType): A token type tuple from Pygments.

Returns:
    Optional[Color]: Color from theme, or None for no color.

◆ _numbers_column_width()

int pip._vendor.rich.syntax.Syntax._numbers_column_width (   self)
protected
Get the number of characters used to render the numbers column.

◆ _process_code()

Tuple[bool, str] pip._vendor.rich.syntax.Syntax._process_code (   self,
str  code 
)
protected
Applies various processing to a raw code string
(normalises it so it always ends with a line return, dedents it if necessary, etc.)

Args:
    code (str): The raw code string to process

Returns:
    Tuple[bool, str]: the boolean indicates whether the raw code ends with a line return,
        while the string is the processed code.

◆ from_path()

"Syntax" pip._vendor.rich.syntax.Syntax.from_path (   cls,
str  path,
str   encoding = "utf-8",
Optional[Union[Lexer, str]]   lexer = None,
Union[str, SyntaxTheme]   theme = DEFAULT_THEME,
bool   dedent = False,
bool   line_numbers = False,
Optional[Tuple[int, int]]   line_range = None,
int   start_line = 1,
Optional[Set[int]]   highlight_lines = None,
Optional[int]   code_width = None,
int   tab_size = 4,
bool   word_wrap = False,
Optional[str]   background_color = None,
bool   indent_guides = False,
PaddingDimensions   padding = 0 
)
Construct a Syntax object from a file.

Args:
    path (str): Path to file to highlight.
    encoding (str): Encoding of file.
    lexer (str | Lexer, optional): Lexer to use. If None, lexer will be auto-detected from path/file content.
    theme (str, optional): Color theme, aka Pygments style (see https://pygments.org/docs/styles/#getting-a-list-of-available-styles). Defaults to "emacs".
    dedent (bool, optional): Enable stripping of initial whitespace. Defaults to True.
    line_numbers (bool, optional): Enable rendering of line numbers. Defaults to False.
    start_line (int, optional): Starting number for line numbers. Defaults to 1.
    line_range (Tuple[int, int], optional): If given should be a tuple of the start and end line to render.
    highlight_lines (Set[int]): A set of line numbers to highlight.
    code_width: Width of code to render (not including line numbers), or ``None`` to use all available width.
    tab_size (int, optional): Size of tabs. Defaults to 4.
    word_wrap (bool, optional): Enable word wrapping of code.
    background_color (str, optional): Optional background color, or None to use theme color. Defaults to None.
    indent_guides (bool, optional): Show indent guides. Defaults to False.
    padding (PaddingDimensions): Padding to apply around the syntax. Defaults to 0 (no padding).

Returns:
    [Syntax]: A Syntax object that may be printed to the console

◆ get_theme()

SyntaxTheme pip._vendor.rich.syntax.Syntax.get_theme (   cls,
Union[str, SyntaxTheme name 
)
Get a syntax theme instance.

◆ guess_lexer()

str pip._vendor.rich.syntax.Syntax.guess_lexer (   cls,
str  path,
Optional[str]   code = None 
)
Guess the alias of the Pygments lexer to use based on a path and an optional string of code.
If code is supplied, it will use a combination of the code and the filename to determine the
best lexer to use. For example, if the file is ``index.html`` and the file contains Django
templating syntax, then "html+django" will be returned. If the file is ``index.html``, and no
templating language is used, the "html" lexer will be used. If no string of code
is supplied, the lexer will be chosen based on the file extension..

Args:
     path (AnyStr): The path to the file containing the code you wish to know the lexer for.
     code (str, optional): Optional string of code that will be used as a fallback if no lexer
        is found for the supplied path.

Returns:
    str: The name of the Pygments lexer that best matches the supplied path/code.

◆ highlight()

Text pip._vendor.rich.syntax.Syntax.highlight (   self,
str  code,
Optional[Tuple[Optional[int], Optional[int]]]   line_range = None 
)
Highlight code and return a Text instance.

Args:
    code (str): Code to highlight.
    line_range(Tuple[int, int], optional): Optional line range to highlight.

Returns:
    Text: A text instance containing highlighted syntax.

◆ lexer()

Optional[Lexer] pip._vendor.rich.syntax.Syntax.lexer (   self)
The lexer for this syntax, or None if no lexer was found.

Tries to find the lexer by name if a string was passed to the constructor.

◆ stylize_range()

None pip._vendor.rich.syntax.Syntax.stylize_range (   self,
StyleType  style,
SyntaxPosition  start,
SyntaxPosition   end 
)
Adds a custom style on a part of the code, that will be applied to the syntax display when it's rendered.
Line numbers are 1-based, while column indexes are 0-based.

Args:
    style (StyleType): The style to apply.
    start (Tuple[int, int]): The start of the range, in the form `[line number, column index]`.
    end (Tuple[int, int]): The end of the range, in the form `[line number, column index]`.

The documentation for this class was generated from the following file: