0

[tuify] API change the return type of `select_from_list()` · Issue #200 · r3bl-o...

 5 months ago
source link: https://github.com/r3bl-org/r3bl-open-core/issues/200
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Contributor

NadiaIdris

commented

Nov 12, 2023

edited by nazmulidris

Note - this is breaking change for existing dependents of this crate. We should have a migration strategy in place for them. Either preserve the existing API and add a new one, instead of this breaking change, or just submit a PR w/ the use of the new API to their repo (eg: ockam).

File: state.rs
https://github.com/r3bl-org/r3bl-open-core/blob/main/tuify/src/state.rs#L23-L49

  1. Change selected_items type to be SelectModeResult. Please see below.
  2. select_from_list function should return a SelectModeResult and not Option<Vec<String>>.
  3. Write tests.
pub struct State {
    /// Does not include the header row.
    pub max_display_height: ChUnit,
    pub max_display_width: ChUnit,
    /// This is not adjusted for
    /// [scroll_offset_row_index](State::scroll_offset_row_index).
    pub raw_caret_row_index: ChUnit,
    pub scroll_offset_row_index: ChUnit,
    pub items: Vec<String>,
    pub selected_items: SelectModeResult,
    pub header: String,
    pub selection_mode: SelectionMode,
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
enum SelectModeResult {
    Single(String),
    Multiple(Vec<String>),
    #[default]
    None,
}

Also add support to detect Ctrl+C. The behavior of pressing Ctrl+C is the same as pressing Esc.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK