Skip to content

Commit 67b4c50

Browse files
author
yashksaini-coder
committed
Refactor selection logic in App and enhance main function to display currently selected virtual environment with a dry-run delete option
1 parent fd3c504 commit 67b4c50

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/app.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::scanner::VenvInfo;
22

33
pub struct App {
44
pub venvs: Vec<VenvInfo>,
5-
pub selected: usize, // index of selected venv
5+
pub selected: usize,
66
}
77

88
impl App {
@@ -13,21 +13,18 @@ impl App {
1313
}
1414
}
1515

16-
/// Move selection up
1716
pub fn previous(&mut self) {
1817
if self.selected > 0 {
1918
self.selected -= 1;
2019
}
2120
}
2221

23-
/// Move selection down
2422
pub fn next(&mut self) {
2523
if self.selected + 1 < self.venvs.len() {
2624
self.selected += 1;
2725
}
2826
}
2927

30-
/// Get the currently selected venv, if any
3128
pub fn selected_venv(&self) -> Option<&VenvInfo> {
3229
self.venvs.get(self.selected)
3330
}

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ use std::env;
77
use app::App;
88
use scanner::scan_for_venvs;
99
use ui::draw_ui;
10+
use utils::delete_venv;
1011

1112
fn main() {
1213
let cwd = env::current_dir().unwrap();
1314
let venvs = scan_for_venvs(&cwd);
1415

1516
let mut app = App::new(venvs);
1617

17-
// Simulate some navigation
1818
draw_ui(&app);
19+
1920
println!("\n-- Moving down --");
2021
app.next();
2122
draw_ui(&app);
23+
2224
println!("\n-- Moving up --");
2325
app.previous();
2426
draw_ui(&app);
27+
28+
if let Some(sel) = app.selected_venv() {
29+
println!("\nCurrently selected venv: {}", sel.path.display());
30+
println!("[Dry-run] Would delete: {}", sel.path.display());
31+
// Uncomment to actually delete:
32+
delete_venv(&sel.path).unwrap();
33+
}
2534
}

0 commit comments

Comments
 (0)