sh2mp4

sh2mp4 - Records shell commands to MP4 videos

sh2mp4.terminal

Terminal (xterm) management for command execution

TerminalManager Objects

class TerminalManager()

Manages an xterm instance for command execution

start

async def start(command: str) -> None

Start xterm and execute the command

signal_recorder_ready

def signal_recorder_ready() -> None

Signal that the recorder is ready and command can proceed

wait_for_completion

async def wait_for_completion() -> int

Wait for the terminal/command to complete and return exit code

is_running

async def is_running() -> bool

Check if the terminal is still running

stop

async def stop() -> None

Stop the terminal and clean up

sh2mp4.peep

Live preview of X displays for debugging recordings

list_displays

async def list_displays() -> int

List all available X displays

peep_display

async def peep_display(display_name: str, interval: float = 0.1) -> int

Monitor an X display and show live preview using chafa

create_parser

def create_parser() -> argparse.ArgumentParser

Create argument parser for peep command

main_async

async def main_async(args) -> int

Async main function

main

def main() -> int

Main entry point for peep command

sh2mp4.asciicast

Asciinema cast file handling and optimization

CastConfig Objects

class CastConfig(NamedTuple)

Configuration for recording a cast file

get_cast_dimensions

def get_cast_dimensions(cast_file: Path) -> tuple[int, int]

Get optimal dimensions for cast file recording

get_cast_command

def get_cast_command(cast_file: Path, playback_speed: float = 1.0) -> str

Get the command to play back a cast file

get_cast_config

def get_cast_config(cast_file: Path,
                    playback_speed: float = 1.0,
                    base_fps: int = 30) -> CastConfig

Get complete configuration for recording a cast file

sh2mp4.args

Argument parsing for sh2mp4

parse_args

def parse_args(argv: Optional[list[str]] = None) -> argparse.Namespace

Parse command line arguments - simple and straightforward

parse_and_validate_args

def parse_and_validate_args(
        argv: Optional[list[str]] = None) -> argparse.Namespace

Legacy wrapper - just parse args normally

sh2mp4.fonts

Font handling and character dimension calculation

FontMetrics Objects

@dataclass
class FontMetrics()

Character dimensions for a specific font and size

get_font_metrics

def get_font_metrics(font_name: str, font_size: int) -> FontMetrics

Get character dimensions for a font and size. Falls back to pre-measured values for DejaVu Sans Mono.

measure_font

def measure_font(font_name: str, font_size: int) -> FontMetrics

Dynamically measure font character dimensions using tkinter

measure_all_fonts

def measure_all_fonts() -> Dict[str, Dict[int, FontMetrics]]

Measure all common monospace fonts at various sizes

calculate_window_dimensions

def calculate_window_dimensions(cols: int, lines: int, font_name: str,
                                font_size: int) -> Tuple[int, int]

Calculate pixel dimensions for terminal window

sh2mp4.themes

Terminal color themes for sh2mp4

Theme Objects

@dataclass
class Theme()

Represents a terminal color theme

colors

Colors 0-15

xterm_args

@property
def xterm_args() -> list[str]

Generate xterm arguments for this theme

get_theme

def get_theme(name: str) -> Theme

Get a theme by name, falling back to default

list_themes

def list_themes() -> list[str]

List available theme names

sh2mp4.measure_fonts

Font measurement utility for sh2mp4

main

def main() -> int

Main entry point for measure-fonts command

sh2mp4.display

Virtual display management using Xvfb

DisplayManager Objects

class DisplayManager()

Manages a virtual X display using Xvfb

start

async def start(width: int, height: int) -> None

Start the virtual display and window manager

stop

async def stop() -> None

Stop the display and clean up

is_ready

async def is_ready() -> bool

Check if the display is ready for use

sh2mp4.ascii_preview

Simple ASCII art preview for terminal display

image_to_ascii

def image_to_ascii(image_path: Path,
                   width: int = 80,
                   height: int = 24) -> Optional[str]

Convert an image to ASCII art for terminal display

colored_blocks_preview

def colored_blocks_preview(image_path: Path,
                           width: int = 80,
                           height: int = 24) -> Optional[str]

Convert image to colored Unicode block characters

sh2mp4.xserver

X server management utilities

XServerInfo Objects

class XServerInfo()

Information about an X server

find_available_display

async def find_available_display() -> int

Find the next available X display number

is_display_in_use

async def is_display_in_use(display_num: int) -> bool

Check if a display number is already in use

list_running_xservers

async def list_running_xservers() -> List[XServerInfo]

List all currently running X servers

get_newest_xserver

async def get_newest_xserver() -> Optional[XServerInfo]

Get the most recently started X server

test_display_connection

async def test_display_connection(display_name: str) -> bool

Test if we can connect to a display

sh2mp4.check_deps

Check dependencies for sh2mp4

check_command

def check_command(cmd: str) -> bool

Check if a command is available in PATH

check_locale

def check_locale() -> bool

Check if en_US.UTF-8 locale is available

check_monospace_fonts

def check_monospace_fonts() -> bool

Check if monospace fonts are available

main

def main() -> int

Check all dependencies and report status

sh2mp4.recorder

Screen recording using ffmpeg

Recorder Objects

class Recorder()

Handles screen recording with ffmpeg

start

async def start() -> None

Start recording the display

stop

async def stop() -> int

Stop recording and return exit code

is_running

async def is_running() -> bool

Check if recording is active

sh2mp4.__main__

Main entry point for sh2mp4

record_command

async def record_command(args) -> int

Main recording function

main

def main() -> int

Main entry point