Utilities

This module provides internal helper functions, video post-processing effects, and progress-bar utilities. Most users do not need to interact with these directly, but the public items are documented here for completeness.

String processing

Video effects

Progress bars

Context managers

CodeVideoRenderer.utils.noManimOutput() Generator[None, Any, None][source]

Context manager used to execute code without outputting Manim logs.

Within the with block, Manim’s standard output, standard error, and progress bars are suppressed. Streams are restored when the block exits.

Yields:

None

CodeVideoRenderer.utils.stripEmptyLines(text: str) str[source]

Remove empty lines from the beginning and end of a string.

Parameters:

text (str) – The input string to process.

Returns:

The string with empty lines removed from the beginning and end.

Return type:

str

CodeVideoRenderer.utils.typeName(item_type: Any) str[source]

Get the name of a type, handling union types and generic types.

Parameters:

item_type – The type or value to get the name of.

Returns:

The name of the type.

Return type:

str

CodeVideoRenderer.utils.addGlowEffect(input_path: StrPath, output_path: StrPath, output: bool) None[source]

Add a glow effect to a video.

Parameters:
  • input_path (StrPath) – Path to the input video file.

  • output_path (StrPath) – Path to save the output video file.

  • output (bool) – Whether to display progress bars.

Returns:

None

CodeVideoRenderer.utils.findSpacePositions(string: str) List[List[int]][source]

Find the 2D positions of all non-leading, non-trailing spaces in a string. Each position is represented as a list [row_index, column_index].

Parameters:

string (str) – A string.

Returns:

A list of 2D positions of all non-leading, non-trailing spaces. Each position is represented as a list [row_index, column_index].

Return type:

List[List[int]]

CodeVideoRenderer.utils.findEmptyLinePositions(string: str) List[int][source]

Find the line indices of all empty lines in a string.

Parameters:

string (str) – A string.

Returns:

A list of line indices of all empty lines.

Return type:

List[int]

CodeVideoRenderer.utils.replaceMiddleSpacesWithOccupyCharacter(string: str) str[source]

Replace all non-leading, non-trailing spaces in the input string with OCCUPY_CHARACTER. Retain leading and trailing spaces.

Parameters:

string (str) – Original string.

Returns:

Processed string with middle spaces replaced by OCCUPY_CHARACTER.

Return type:

str

class CodeVideoRenderer.utils.DefaultProgressBar(output: bool)[source]

Bases: Progress

Default progress bar used during video rendering.

This is a thin wrapper around rich.progress.Progress pre-configured with descriptive columns (task name, bar, completion count, percentage, time remaining, and transfer speed).

class CodeVideoRenderer.utils.RichProgressBarLogger(output: bool, title: str, init_state=None, bars=None, leave_bars=True, ignored_bars=None, logged_bars='all', print_messages=True, min_time_interval=0.1, ignore_bars_under=0)[source]

Bases: ProgressBarLogger

A progress logger that uses Rich to display progress bars.

This class bridges proglog (used by MoviePy) and rich progress bars, allowing the glow-effect post-processing step to show a native-looking progress indicator in the terminal.

new_tqdm_bar(bar)[source]

Create a Rich progress bar task for the given bar.

close_tqdm_bar(bar)[source]

Close the Rich progress bar task for the given bar.

bars_callback(bar, attr, value, old_value)[source]

Update the Rich progress bar task based on the attribute change.

stop()[source]

Stop the Rich progress bar.