feat(tui): add rename functionality

This commit is contained in:
objz committed 2026-01-10 16:38:14 +01:00
1 parent 9e65fb43d8
commit df3d6b24c2
4 files changed
+98 -4

No files matched your search

+44
View File
@@ -392,6 +392,42 @@ impl App {
new_instance::handle_key(&key_event, &mut self.profiles_state);
}
_ => {
if self.focused == FocusedArea::Profiles && self.profiles_state.renaming.is_some() {
match key_event.code {
KeyCode::Enter => {
let new_name = self.profiles_state.renaming.take().unwrap_or_default();
if let Some(inst) = self.profiles_state.selected_instance() {
let old_name = inst.name.clone();
match self.instance_manager.rename(&old_name, &new_name) {
Ok(()) => {
if let Some(inst) = self.profiles_state.instances.iter_mut().find(|i| i.name == old_name) {
inst.name = new_name.trim().to_string();
}
}
Err(e) => {
tracing::error!("Rename failed: {}", e);
}
}
}
}
KeyCode::Esc => {
self.profiles_state.renaming = None;
}
KeyCode::Backspace => {
if let Some(ref mut name) = self.profiles_state.renaming {
name.pop();
}
}
KeyCode::Char(c) => {
if let Some(ref mut name) = self.profiles_state.renaming {
name.push(c);
}
}
_ => {}
}
return Ok(());
}
if self.focused == FocusedArea::Profiles && self.profiles_state.search.active {
self.profiles_state.handle_key(&key_event);
return Ok(());
@@ -468,6 +504,14 @@ impl App {
}
}
}
KeyCode::Char('r')
if self.focused == FocusedArea::Profiles
&& !self.profiles_state.search.active =>
{
if let Some(inst) = self.profiles_state.selected_instance() {
self.profiles_state.renaming = Some(inst.name.clone());
}
}
KeyCode::Esc
if self.focused == FocusedArea::Profiles
&& !self.profiles_state.search.active =>
+1
View File
@@ -186,6 +186,7 @@ pub fn render(
("Esc", " kill"),
("a", " add"),
("d", " delete"),
("r", " rename"),
("/", " search"),
])
} else {
+22 -4
View File
@@ -51,6 +51,7 @@ pub struct State {
pub scrollbar_state: ScrollbarState,
pub show_popup: bool,
pub search: SearchState,
pub renaming: Option<String>,
}
impl State {
@@ -62,6 +63,7 @@ impl State {
scrollbar_state: ScrollbarState::default(),
show_popup: false,
search: SearchState::default(),
renaming: None,
};
if count > 0 {
s.list_state.selected = Some(0);
@@ -249,10 +251,26 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
"\u{258c} ",
Style::default().fg(loader_color(instance.loader)),
);
let name_line = Line::from(vec![
stripe.clone(),
Span::styled(instance.name.as_str(), name_style),
]);
let is_renaming = context.is_selected && state.renaming.is_some();
let name_line = if is_renaming {
let rename_val = state.renaming.as_deref().unwrap_or("");
Line::from(vec![
stripe.clone(),
Span::styled(rename_val, Style::default().fg(THEME.colors.foreground)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.add_modifier(Modifier::SLOW_BLINK),
),
])
} else {
Line::from(vec![
stripe.clone(),
Span::styled(instance.name.as_str(), name_style),
])
};
let (meta_text, meta_text_style) = match get_run_state(&instance.name) {
Some(RunState::Authenticating) => (