Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Browser Widget

The browser widget provides a specialized interface for browsing and interacting with netidx hierarchies. It displays netidx paths in a tree structure with keyboard navigation, selection, and cursor movement support.

APIs

mod browser: sig {
    type MoveCursor = [`Left(i64), `Right(i64), `Up(i64), `Down(i64)];

    /// Creates a browser widget for navigating netidx hierarchies
    val browser: fn(
        ?#cursor: MoveCursor,
        ?#selected_row: &string,
        #selected_path: &string,
        ?#size: &Size,
        string
    ) -> Widget;
}

Parameters

  • cursor - Programmatic cursor movement: Left(n), Right(n), Up(n), Down(n)
  • selected_row (output) - Display name of the selected row
  • selected_path (output, required) - Full path of the currently selected item
  • size (output) - Rendered size of the browser

Examples

Basic Usage

use tui;
use tui::browser;

let selected_path: string = never();

browser(
    #size: {width: 40, height: 10},
    #selected_path: &selected_path,
    "/"  // Start browsing from root
)

Basic Browser Widget

Basic Navigation

use tui;
use tui::browser;
use tui::input_handler;

let path = "/";
let selected_path: string = never();
let selected_row: string = never();
let cursor: MoveCursor = never();

let handle_event = |e: Event| -> [`Stop, `Continue] select e {
    `Key(k) => select k.kind {
        `Press => select k.code {
            e@ `Up => { cursor <- e ~ `Up(1); `Stop },
            e@ `Down => { cursor <- e ~ `Down(1); `Stop },
            e@ `Left => { cursor <- e ~ `Left(1); `Stop },
            e@ `Right => { cursor <- e ~ `Right(1); `Stop },
            e@ `Enter => { path <- e ~ selected_row; `Stop },
            _ => `Continue
        },
        _ => `Continue
    },
    _ => `Continue
};

input_handler(
    #handle: &handle_event,
    &browser(
        #size: {width: 80, height: 24},
        #cursor,
        #selected_path: &selected_path,
        #selected_row: &selected_row,
        path
    )
)

Browser With Navigation

See Also

  • list - For simpler selection interfaces
  • table - For tabular data display
  • block - For containing browsers with borders