mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 23:21:08 +03:00
charselect: add explicit recent category, show category in UI
The default behavior for charselect is to show the recent category if you have previously used it, otherwise, show the default emotion category. refs: https://github.com/wez/wezterm/issues/2163
This commit is contained in:
parent
a599567423
commit
16bf00c63c
@ -320,6 +320,7 @@ pub struct PaneSelectArguments {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||||
pub enum CharSelectGroup {
|
pub enum CharSelectGroup {
|
||||||
|
RecentlyUsed,
|
||||||
SmileysAndEmotion,
|
SmileysAndEmotion,
|
||||||
PeopleAndBody,
|
PeopleAndBody,
|
||||||
AnimalsAndNature,
|
AnimalsAndNature,
|
||||||
@ -336,6 +337,7 @@ pub enum CharSelectGroup {
|
|||||||
impl CharSelectGroup {
|
impl CharSelectGroup {
|
||||||
pub fn next(self) -> Self {
|
pub fn next(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
|
Self::RecentlyUsed => Self::SmileysAndEmotion,
|
||||||
Self::SmileysAndEmotion => Self::PeopleAndBody,
|
Self::SmileysAndEmotion => Self::PeopleAndBody,
|
||||||
Self::PeopleAndBody => Self::AnimalsAndNature,
|
Self::PeopleAndBody => Self::AnimalsAndNature,
|
||||||
Self::AnimalsAndNature => Self::FoodAndDrink,
|
Self::AnimalsAndNature => Self::FoodAndDrink,
|
||||||
@ -346,7 +348,7 @@ impl CharSelectGroup {
|
|||||||
Self::Symbols => Self::Flags,
|
Self::Symbols => Self::Flags,
|
||||||
Self::Flags => Self::NerdFonts,
|
Self::Flags => Self::NerdFonts,
|
||||||
Self::NerdFonts => Self::UnicodeNames,
|
Self::NerdFonts => Self::UnicodeNames,
|
||||||
Self::UnicodeNames => Self::SmileysAndEmotion,
|
Self::UnicodeNames => Self::RecentlyUsed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,7 +362,7 @@ impl Default for CharSelectGroup {
|
|||||||
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||||
pub struct CharSelectArguments {
|
pub struct CharSelectArguments {
|
||||||
#[dynamic(default)]
|
#[dynamic(default)]
|
||||||
pub group: CharSelectGroup,
|
pub group: Option<CharSelectGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq, FromDynamic, ToDynamic)]
|
||||||
|
@ -49,7 +49,7 @@ enum Character {
|
|||||||
struct Alias {
|
struct Alias {
|
||||||
name: Cow<'static, str>,
|
name: Cow<'static, str>,
|
||||||
character: Character,
|
character: Character,
|
||||||
group: Option<CharSelectGroup>,
|
group: CharSelectGroup,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Alias {
|
impl Alias {
|
||||||
@ -139,7 +139,7 @@ fn build_aliases() -> Vec<Alias> {
|
|||||||
aliases.push(Alias {
|
aliases.push(Alias {
|
||||||
name: Cow::Owned(r.name.clone()),
|
name: Cow::Owned(r.name.clone()),
|
||||||
character,
|
character,
|
||||||
group: None,
|
group: CharSelectGroup::RecentlyUsed,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ fn build_aliases() -> Vec<Alias> {
|
|||||||
Alias {
|
Alias {
|
||||||
name: Cow::Borrowed(emoji.name()),
|
name: Cow::Borrowed(emoji.name()),
|
||||||
character: Character::Emoji(emoji),
|
character: Character::Emoji(emoji),
|
||||||
group: Some(group),
|
group,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if let Some(short) = emoji.shortcode() {
|
if let Some(short) = emoji.shortcode() {
|
||||||
@ -171,7 +171,7 @@ fn build_aliases() -> Vec<Alias> {
|
|||||||
Alias {
|
Alias {
|
||||||
name: Cow::Borrowed(short),
|
name: Cow::Borrowed(short),
|
||||||
character: Character::Emoji(emoji),
|
character: Character::Emoji(emoji),
|
||||||
group: Some(group),
|
group,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ fn build_aliases() -> Vec<Alias> {
|
|||||||
name,
|
name,
|
||||||
value: char::from_u32(*value).unwrap(),
|
value: char::from_u32(*value).unwrap(),
|
||||||
},
|
},
|
||||||
group: Some(CharSelectGroup::UnicodeNames),
|
group: CharSelectGroup::UnicodeNames,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ fn build_aliases() -> Vec<Alias> {
|
|||||||
name,
|
name,
|
||||||
value: *value,
|
value: *value,
|
||||||
},
|
},
|
||||||
group: Some(CharSelectGroup::NerdFonts),
|
group: CharSelectGroup::NerdFonts,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -242,10 +242,7 @@ fn compute_matches(selection: &str, aliases: &[Alias], group: CharSelectGroup) -
|
|||||||
aliases
|
aliases
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_idx, a)| match a.group {
|
.filter(|(_idx, a)| a.group == group)
|
||||||
Some(g) => g == group,
|
|
||||||
None => true,
|
|
||||||
})
|
|
||||||
.map(|(idx, _a)| idx)
|
.map(|(idx, _a)| idx)
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
@ -306,11 +303,21 @@ fn compute_matches(selection: &str, aliases: &[Alias], group: CharSelectGroup) -
|
|||||||
|
|
||||||
impl CharSelector {
|
impl CharSelector {
|
||||||
pub fn new(_term_window: &mut TermWindow, args: &CharSelectArguments) -> Self {
|
pub fn new(_term_window: &mut TermWindow, args: &CharSelectArguments) -> Self {
|
||||||
|
let aliases = build_aliases();
|
||||||
|
let has_recents = aliases[0].group == CharSelectGroup::RecentlyUsed;
|
||||||
|
let group = args.group.unwrap_or_else(|| {
|
||||||
|
if has_recents {
|
||||||
|
CharSelectGroup::RecentlyUsed
|
||||||
|
} else {
|
||||||
|
CharSelectGroup::default()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
element: RefCell::new(None),
|
element: RefCell::new(None),
|
||||||
selection: RefCell::new(String::new()),
|
selection: RefCell::new(String::new()),
|
||||||
group: RefCell::new(args.group),
|
group: RefCell::new(group),
|
||||||
aliases: build_aliases(),
|
aliases,
|
||||||
matches: RefCell::new(None),
|
matches: RefCell::new(None),
|
||||||
selected_row: RefCell::new(0),
|
selected_row: RefCell::new(0),
|
||||||
top_row: RefCell::new(0),
|
top_row: RefCell::new(0),
|
||||||
@ -321,6 +328,7 @@ impl CharSelector {
|
|||||||
fn compute(
|
fn compute(
|
||||||
term_window: &mut TermWindow,
|
term_window: &mut TermWindow,
|
||||||
selection: &str,
|
selection: &str,
|
||||||
|
group: CharSelectGroup,
|
||||||
aliases: &[Alias],
|
aliases: &[Alias],
|
||||||
matches: &MatchResults,
|
matches: &MatchResults,
|
||||||
max_rows_on_screen: usize,
|
max_rows_on_screen: usize,
|
||||||
@ -341,16 +349,32 @@ impl CharSelector {
|
|||||||
let (padding_left, padding_top) = term_window.padding_left_top();
|
let (padding_left, padding_top) = term_window.padding_left_top();
|
||||||
let border = term_window.get_os_border();
|
let border = term_window.get_os_border();
|
||||||
let top_pixel_y = top_bar_height + padding_top + border.top.get() as f32;
|
let top_pixel_y = top_bar_height + padding_top + border.top.get() as f32;
|
||||||
let mut elements =
|
|
||||||
vec![
|
let label = match group {
|
||||||
Element::new(&font, ElementContent::Text(format!("Select: {selection}_")))
|
CharSelectGroup::RecentlyUsed => "Recent",
|
||||||
.colors(ElementColors {
|
CharSelectGroup::SmileysAndEmotion => "Emotion",
|
||||||
border: BorderColor::default(),
|
CharSelectGroup::PeopleAndBody => "People",
|
||||||
bg: LinearRgba::TRANSPARENT.into(),
|
CharSelectGroup::AnimalsAndNature => "Animals",
|
||||||
text: term_window.config.pane_select_fg_color.to_linear().into(),
|
CharSelectGroup::FoodAndDrink => "Food",
|
||||||
})
|
CharSelectGroup::TravelAndPlaces => "Travel",
|
||||||
.display(DisplayType::Block),
|
CharSelectGroup::Activities => "Activities",
|
||||||
];
|
CharSelectGroup::Objects => "Objects",
|
||||||
|
CharSelectGroup::Symbols => "Symbols",
|
||||||
|
CharSelectGroup::Flags => "Flags",
|
||||||
|
CharSelectGroup::NerdFonts => "NerdFonts",
|
||||||
|
CharSelectGroup::UnicodeNames => "Unicode",
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut elements = vec![Element::new(
|
||||||
|
&font,
|
||||||
|
ElementContent::Text(format!("{label}: {selection}_")),
|
||||||
|
)
|
||||||
|
.colors(ElementColors {
|
||||||
|
border: BorderColor::default(),
|
||||||
|
bg: LinearRgba::TRANSPARENT.into(),
|
||||||
|
text: term_window.config.pane_select_fg_color.to_linear().into(),
|
||||||
|
})
|
||||||
|
.display(DisplayType::Block)];
|
||||||
|
|
||||||
for (display_idx, alias) in matches
|
for (display_idx, alias) in matches
|
||||||
.matches
|
.matches
|
||||||
@ -627,6 +651,7 @@ impl Modal for CharSelector {
|
|||||||
let element = Self::compute(
|
let element = Self::compute(
|
||||||
term_window,
|
term_window,
|
||||||
selection,
|
selection,
|
||||||
|
group,
|
||||||
&self.aliases,
|
&self.aliases,
|
||||||
matches,
|
matches,
|
||||||
max_rows_on_screen,
|
max_rows_on_screen,
|
||||||
|
Loading…
Reference in New Issue
Block a user