if sys.version_info >= (3, 8): from typing import Literal else: from typing_extensions import Literal # pragma: no cover
from ._loop import loop_last from .console import Console, ConsoleOptions, RenderableType, RenderResult from .control import Control from .segment import ControlType, Segment from .style import StyleType from .text import Text
class LiveRender: """Creates a renderable that may be updated.
Args:
renderable (RenderableType): Any renderable object.
style (StyleType, optional): An optional style to apply to the renderable. Defaults to "". """
def set_renderable(self, renderable: RenderableType) -> None: """Set a new renderable.
Args:
renderable (RenderableType): Any renderable object, including str. """
self.renderable = renderable
def position_cursor(self) -> Control: """Get control codes to move cursor to beginning of live render.
Returns:
Control: A control instance that may be printed. """ if self._shape isnotNone:
_, height = self._shape return Control(
ControlType.CARRIAGE_RETURN,
(ControlType.ERASE_IN_LINE, 2),
*(
(
(ControlType.CURSOR_UP, 1),
(ControlType.ERASE_IN_LINE, 2),
)
* (height - 1)
)
) return Control()
def restore_cursor(self) -> Control: """Get control codes to clear the render and restore the cursor to its previous position.
Returns:
Control: A Control instance that may be printed. """ if self._shape isnotNone:
_, height = self._shape return Control(
ControlType.CARRIAGE_RETURN,
*((ControlType.CURSOR_UP, 1), (ControlType.ERASE_IN_LINE, 2)) * height
) return Control()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.