licence_audit/picker

Interactive tri-state picker built on the etch TUI backend.

Each item is in one of three states: Allow, Deny, or Ignore. Pressing space cycles a single item through the states; a/d/i apply a state to every item.

Usage:

case picker.pick(“Choose licence policy:”, labels, allow, deny) { Ok(picker.Selection(allow, deny)) -> … Error(picker.Cancelled) -> … }

Types

pub type Choice {
  Allow
  Deny
  Ignore
}

Constructors

  • Allow
  • Deny
  • Ignore
pub type PickerError {
  Cancelled
  NotInteractive
}

Constructors

  • Cancelled
  • NotInteractive
pub type PickerKey {
  MoveUp
  MoveDown
  CycleCurrent
  AllowAll
  DenyAll
  IgnoreAll
}

Constructors

  • MoveUp
  • MoveDown
  • CycleCurrent
  • AllowAll
  • DenyAll
  • IgnoreAll
pub type Selection {
  Selection(allow: List(String), deny: List(String))
}

Constructors

  • Selection(allow: List(String), deny: List(String))
pub opaque type State

Values

pub fn cycle_at_index(state: State, index: Int) -> State
pub fn handle_picker_key(state: State, key: PickerKey) -> State
pub fn new_state(
  title: String,
  labels: List(String),
  allow: List(String),
  deny: List(String),
) -> State
pub fn pick(
  title: String,
  labels: List(String),
  allow: List(String),
  deny: List(String),
) -> Result(Selection, PickerError)

Present an interactive tri-state prompt.

  • title is shown above the list.
  • labels are the choices in display order.
  • Items whose label is in allow start as Allow.
  • Items whose label is in deny start as Deny.
  • Everything else (including newly discovered licences) starts as Ignore.

Returns a Selection containing only the labels marked Allow and Deny (ignored labels are omitted from both lists), or Cancelled on Esc / Ctrl-C / q.

pub fn pick_with_terminal_check(
  title: String,
  labels: List(String),
  allow: List(String),
  deny: List(String),
  stdin_is_tty stdin_is_tty: fn() -> Bool,
  stdout_is_tty stdout_is_tty: fn() -> Bool,
) -> Result(Selection, PickerError)
pub fn state_choices(state: State) -> List(#(String, Choice))
pub fn state_cursor(state: State) -> Int
pub fn state_selection(state: State) -> Selection
✨ Search Document