Alaja.CLI.Pagination (Alaja v1.0.0)

Copy Markdown View Source

Interactive pagination utilities for CLI output.

Provides functions for paginating long lists of items with keyboard navigation.

Summary

Functions

Prompts for a page number and returns the 0-indexed page. Returns :stay if invalid input.

Handles navigation input and returns the next page number. Returns :quit to exit pagination.

Maps a key to its navigation action.

Returns the navigation help message.

Gets the slice of items for a given page.

Reads a key from the user with a prompt.

Calculates the number of pages needed for a given total items and page size.

Functions

goto_page(total_pages)

@spec goto_page(non_neg_integer()) :: non_neg_integer() | :stay

Prompts for a page number and returns the 0-indexed page. Returns :stay if invalid input.

handle_nav(key, current_page, total_pages)

@spec handle_nav(String.t(), non_neg_integer(), non_neg_integer()) ::
  non_neg_integer() | :quit

Handles navigation input and returns the next page number. Returns :quit to exit pagination.

map_key(key)

@spec map_key(String.t()) :: atom()

Maps a key to its navigation action.

page_items(items, page, page_size)

@spec page_items([any()], non_neg_integer(), pos_integer()) :: [any()]

Gets the slice of items for a given page.

read_key(prompt \\ "Press key: ")

@spec read_key(String.t()) :: String.t()

Reads a key from the user with a prompt.

total_pages(total_items, page_size)

@spec total_pages(non_neg_integer(), pos_integer()) :: non_neg_integer()

Calculates the number of pages needed for a given total items and page size.