UI Layer

Command-line interface and user interaction components.

CLI

Command-line interface for Skim keyboard layout image generator.

This module provides the CLI entry points for the skim tool using Click. It defines the main command group and subcommands for generating keymap images and configuration files.

Commands:
  • skim generate: Generate keymap visualization images

  • skim configure: Generate or output configuration files

Example

Generate images from a keymap file:

$ skim generate --keymap layout.kbi --output-dir ./images

Generate with custom configuration:

$ skim -v INFO generate -k layout.vil -c config.yaml -f png

Create configuration from Keybard file:

$ skim configure -k layout.kbi -o skim-config.yaml

Read keymap from stdin:

$ cat keymap.json | skim generate - -o ./out
class skim.ui.cli.AliasedGroup(name=None, commands=None, invoke_without_command=False, no_args_is_help=None, subcommand_metavar=None, chain=False, result_callback=None, **kwargs)[source]

Bases: Group

Click Group that supports command name abbreviation.

Allows users to invoke commands using unique prefixes instead of full command names. For example, skim gen matches generate if no other command starts with “gen”.

Example

$ skim gen –keymap foo.kbi # Matches ‘generate’ $ skim conf -k bar.kbi # Matches ‘configure’

Parameters:
  • name (str | None)

  • commands (cabc.MutableMapping[str, Command] | cabc.Sequence[Command] | None)

  • invoke_without_command (bool)

  • no_args_is_help (bool | None)

  • subcommand_metavar (str | None)

  • chain (bool)

  • result_callback (t.Callable[..., t.Any] | None)

  • kwargs (t.Any)

get_command(ctx, cmd_name)[source]

Resolve a command by name or unique prefix.

Parameters:
  • ctx (Context) – Click context.

  • cmd_name (str) – Command name or prefix to resolve.

Return type:

Command | None

Returns:

Matching Command object, or None if not found.

Raises:

click.UsageError – If prefix matches multiple commands.

resolve_command(ctx, args)[source]

Resolve command and return full name for help text.

Return type:

tuple

Parameters:

Logging Configuration

Logging configuration for Skim CLI output.

This module provides logging setup with colored output and emoji indicators for different log levels. The configuration is optimized for CLI usage with progress feedback and debug information.

Log level formatting:
  • DEBUG: Green with bug emoji (🐞)

  • INFO: Normal with contextual emoji (from record.emoji)

  • WARNING: Yellow with warning emoji (⚠️)

  • ERROR/CRITICAL: Red with error emoji (🚨)

Example

>>> from skim.ui.logging_config import setup_logging
>>> setup_logging("INFO", quiet=False)
>>> import logging
>>> logger = logging.getLogger(__name__)
>>> logger.info("Processing...", extra={"emoji": "🔄"})
🔄 Processing...
class skim.ui.logging_config.ColoredFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

Custom log formatter with ANSI colors and emoji support.

Applies color coding based on log level and prepends optional emoji indicators to log messages. The emoji can be specified per-record using the “emoji” extra field.

ANSI color codes are used for terminal output:
  • DEBUG: Green

  • INFO: Default (reset)

  • WARNING: Yellow

  • ERROR+: Red

GREY

ANSI code for grey text.

GREEN

ANSI code for green text.

YELLOW

ANSI code for yellow text.

RED

ANSI code for red text.

BOLD_RED

ANSI code for bold red text.

BLUE

ANSI code for blue text.

RESET

ANSI code to reset formatting.

Example

>>> formatter = ColoredFormatter()
>>> handler.setFormatter(formatter)
GREY = '\x1b[38;5;240m'
GREEN = '\x1b[32m'
YELLOW = '\x1b[33m'
RED = '\x1b[31m'
BOLD_RED = '\x1b[31;1m'
BLUE = '\x1b[34m'
RESET = '\x1b[0m'
format(record)[source]

Format a log record with color and emoji.

Determines the appropriate color based on log level and prepends an emoji if specified in the record’s extra data.

Parameters:

record (LogRecord) – The log record to format.

Return type:

str

Returns:

Formatted string with ANSI color codes and optional emoji.

skim.ui.logging_config.setup_logging(verbosity, quiet)[source]

Configure the logging system for CLI output.

Sets up the root logger with colored output to stderr. The verbosity level can be specified as a string matching standard logging levels.

Parameters:
  • verbosity (str) – Log level as string. Valid values: “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”, “NONE”

  • quiet (bool) – If True, suppresses all log output regardless of verbosity. Equivalent to setting verbosity to “NONE”.

Return type:

None

Example

>>> setup_logging("INFO", quiet=False)
>>> logging.info("This will be shown")
>>> setup_logging("WARNING", quiet=False)
>>> logging.info("This will NOT be shown")
>>> setup_logging("DEBUG", quiet=True)
>>> logging.debug("This will NOT be shown (quiet=True)")