Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tuify] API change the return type of select_from_list() #200

Closed
NadiaIdris opened this issue Nov 12, 2023 · 5 comments
Closed

[tuify] API change the return type of select_from_list() #200

NadiaIdris opened this issue Nov 12, 2023 · 5 comments
Assignees
Labels
api Anything related to making the API more usable by developers component: tuify

Comments

@NadiaIdris
Copy link
Contributor

NadiaIdris commented Nov 12, 2023

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.

@NadiaIdris
Copy link
Contributor Author

@Harshil-Jani I removed both of us from this issue for the time being (since we weren't working on this issue immediately) because I wanted to post it to Rust user forum to invite contributors to work on some issues. But my account is still on hold with them and I wasn't able to post them 😀. Trying to get my account "unblocked".

@r3bl-org r3bl-org deleted a comment from NadiaIdris Nov 24, 2023
@NadiaIdris NadiaIdris added api Anything related to making the API more usable by developers component: tuify labels Nov 25, 2023
@NadiaIdris NadiaIdris changed the title [tuify] Change the return type of select_from_list() Change the return type of select_from_list() Nov 25, 2023
@nazmulidris nazmulidris changed the title Change the return type of select_from_list() tuify API - change the return type of select_from_list() Nov 25, 2023
@nazmulidris nazmulidris changed the title tuify API - change the return type of select_from_list() [tuify] API change the return type of select_from_list() Nov 26, 2023
@zoo868e
Copy link

zoo868e commented Dec 1, 2023

Cool, can I give it a shot?

@zoo868e
Copy link

zoo868e commented Dec 1, 2023

Just a quick question: Why is the default value an empty string instead of None?

@NadiaIdris
Copy link
Contributor Author

Cool, can I give it a shot?

Great! I have assigned you to the issue. Let us know if you need any help on Discord https://discord.com/invite/rkBsNK83.

@NadiaIdris
Copy link
Contributor Author

Just a quick question: Why is the default value an empty string instead of None?

@zoo868e You are correct. The default should be None 👍🏼

zoo868e pushed a commit to zoo868e/r3bl-open-core that referenced this issue Dec 11, 2023
The commit addresses issue r3bl-org#200 in the Tuify, focusing on changing the
return type of the `select_from_list()` function. The modification
include updating function parameters and return types, adapting related
code in various files, and ensuring compatibility with the new
`SelectModeResult` enum. Additionally, adjustments are made to handle
single and multiple selection modes, improving code clarity and
maintainability.

Moreover, add Ctrl + C keybinding.
zoo868e pushed a commit to zoo868e/r3bl-open-core that referenced this issue Dec 12, 2023
The commit addresses issue r3bl-org#200 in the Tuify, focusing on changing the
return type of the `select_from_list()` function. The modification
include updating function parameters and return types, adapting related
code in various files, and ensuring compatibility with the new
`SelectModeResult` enum. Additionally, adjustments are made to handle
single and multiple selection modes, improving code clarity and
maintainability.

Moreover, add Ctrl + C keybinding.
@NadiaIdris NadiaIdris reopened this Dec 12, 2023
@nazmulidris nazmulidris linked a pull request Dec 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Anything related to making the API more usable by developers component: tuify
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants