ddp_utils.console.rich_adapter¶
import ddp_utils.console.rich_adapter
Coordinate Rich rendering with DDP terminal cursor and output ownership.
The adapter disables Rich LiveRender cursor restoration, translates Rich
control segments into ConsoleCursor operations, and routes rendered
text through the owning DDP console when one is available.
Examples
Install a DDP-aware console as Rich’s process-wide console:
from ddp_utils.console.rich_adapter import install_global_adapter
install_global_adapter()
- ddp_utils.console.rich_adapter.patch_rich_live_render() None¶
Make Rich
LiveRendercursor positioning inert once per process.The original methods are retained on
LiveRenderunder private backup attributes. A lock makes repeated and concurrent calls idempotent.Examples
Apply the compatibility patch before constructing a custom console:
patch_rich_live_render()
- class ddp_utils.console.rich_adapter.DDPRichConsole(cursor: ConsoleCursor | None = None, ddp_console: 'DDPConsole' | None = None, **kwargs)¶
Bases:
ConsoleRender Rich output through DDP cursor and console coordination.
Construction forces terminal rendering, disables Rich’s legacy Windows mode, and applies
patch_rich_live_render(). Rendered text is forwarded to the owning DDP console while Rich control segments are translated intoConsoleCursorcalls.Examples
Create a standalone adapter with an explicit cursor:
console = DDPRichConsole(cursor=ConsoleCursor(warn=False))
Initialize the Rich adapter and its DDP coordination objects.
Parameters
Name
Type
Description
cursor
Optional[ConsoleCursor]
Cursor controller used for translated Rich control codes. A non-warning controller is created when omitted.
ddp_console
Optional['DDPConsole']
Owning DDP console that receives rendered text.
**kwargs
Additional
rich.console.Consolearguments.file,legacy_windows, andforce_terminalare always overridden.Examples
Bind Rich rendering to an existing DDP console:
adapter = DDPRichConsole( cursor=ddp_console.cursor, ddp_console=ddp_console, color_system="auto", )
- control(*control: Control) None¶
Append Rich control segments to the managed output buffer.
Parameters
Name
Type
Description
*control
Control
Rich control objects whose segments should be buffered.
Examples
Buffer a terminal title control for coordinated flushing:
console.control(Control.title("Worker"))
- print(*args, **kwargs) None¶
Render Rich content and immediately flush through DDP coordination.
Parameters
Name
Description
*args
Positional arguments accepted by
RichConsole.print.**kwargs
Keyword arguments accepted by
RichConsole.print.Examples
Render styled text through the DDP output path:
console.print("[green]Complete[/green]")
- log(*args, **kwargs) None¶
Render a Rich log entry and flush through DDP coordination.
Parameters
Name
Description
*args
Positional arguments accepted by
RichConsole.log.**kwargs
Keyword arguments accepted by
RichConsole.log.Examples
Emit a timestamped diagnostic entry:
console.log("Connected", log_locals=False)
- show_cursor(show: bool = True) bool¶
Set terminal cursor visibility through the DDP controller.
Parameters
Name
Type
Description
show
bool
Show the cursor when true; hide it otherwise.
Returns
Type
Description
bool
True after dispatching the cursor operation.
Examples
Hide the cursor while rendering an animated view:
console.show_cursor(False)
- set_alt_screen(enable: bool = True) bool¶
Delegate alternate-screen switching to Rich’s implementation.
Parameters
Name
Type
Description
enable
bool
Enter the alternate screen when true; leave it otherwise.
Returns
Type
Description
bool
Rich’s success indication for the control operation.
Examples
Enter the alternate screen for a full-screen display:
console.set_alt_screen(True)
- set_window_title(title: str) bool¶
Set the terminal window title through the DDP cursor controller.
Parameters
Name
Type
Description
title
str
Replacement terminal window title.
Returns
Type
Description
bool
True after dispatching the title operation.
Examples
Identify the active worker in the terminal title:
console.set_window_title("DDP worker")
- ddp_utils.console.rich_adapter.install_global_adapter() None¶
Replace Rich’s process-wide console with a DDP-aware adapter.
The adapter reuses the singleton DDP console’s cursor and output pipeline. Existing and future calls to
rich.get_consolereturn the new instance.Examples
Install the adapter during console bootstrap:
install_global_adapter()