nb_cli.cli.utils

async def find_exact_package(question, name, packages)

  • 参数

    • question (str)

    • name (str | None)

    • packages (list[T])

  • 返回

    • T

def run_sync(func)

  • 参数

    • func ((P) -> R)
  • 返回

    • (P) -> Coroutine[Any, Any, R]

def run_async(func)

  • 参数

    • func ((P) -> Coroutine[Any, Any, R])
  • 返回

    • (P) -> R

def humanize_data_size(bytes_, *, precision=3, threshold=0.92, use_si=False, negative_size="error")

  • 说明: Convert a byte count into a human-readable string (e.g., '1.23 MiB').

  • Args

    • bytes_ (int): The number of bytes to convert.

    • precision (int): Number of decimal places in the output.

    • threshold (float): Factor used to determine when to switch to a higher unit.

    • use_si (bool): If True, use base-1000 units (MB, GB); otherwise use base-1024 (MiB, GiB).

    • negative_size (Literal['error', 'n/a', 'negative']): strategy to control how to process negative size.

  • Returns

    • str: Human-readable size string.
  • Raises

    • ValueError: If bytes_ is negative and negative_size is set 'error'.

def split_text_by_wcswidth(text, width)

  • 参数

    • text (str)

    • width (int)

  • 返回

    • untyped

def format_package_results(hits, name_column_width=None, terminal_width=None)

  • 参数

    • hits (list[T])

    • name_column_width (int | None)

    • terminal_width (int | None)

  • 返回

    • str

def auto_fgcolor(bg, gamma=2.2, dark="#000000", light="#FFFFFF")

  • 说明: Automatically choose black or white foreground color based on background color for optimal contrast.

  • Args

    • bg (str): hex color string of the background color, in the format of "#RRGGBB".

    • gamma (float): the gamma value to correct the luminance.

    • dark (str): the dark color on brighter background, "#000000" by default.

    • light (str): the light color on darker background, "#FFFFFF" by default.

  • Returns

    • CT: Either the dark color or the bright color.

def advanced_search_filter(input_, module)

  • 参数

    • input_ (str | list[str])

    • module (T)

  • 返回

    • bool
  • 参数

    • input_ (str | list[str])

    • source (Iterable[T])

  • 返回

    • list[T]

def cut_text(text, max_width, max_lines=1)

  • 参数

    • text (str)

    • max_width (int)

    • max_lines (int)

  • 返回

    • str