Skip to content

Commit cf09e4d

Browse files
authored
Refactor
1 parent a2a751b commit cf09e4d

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

src/main.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
use cursive::align::HAlign;
2-
use cursive::traits::*;
3-
use cursive::views::{Dialog, SelectView, TextView};
4-
use cursive::Cursive;
5-
use std::fs;
6-
use std::path::Path;
1+
use cursive::{align::HAlign, traits::*, views::*, Cursive};
2+
use std::{env, fs, path::Path};
73

84
fn main() {
9-
let home = std::env::var("HOME").unwrap();
5+
let home: String = env::var("HOME").unwrap();
106
let path = Path::new(&home).join(".ssh");
11-
let mut arr = Vec::new();
7+
let mut arr: Vec<String> = Vec::new();
128

139
for entry in fs::read_dir(path).expect("Unable to list") {
1410
let entry = entry.expect("unable to get entry");
@@ -20,22 +16,27 @@ fn main() {
2016
}
2117
}
2218

23-
let mut select = SelectView::new().h_align(HAlign::Center).autojump();
19+
let mut select = SelectView::<String>::new()
20+
.h_align(HAlign::Center)
21+
.autojump();
2422

25-
select.add_all_str(arr);
23+
select.add_all(arr);
2624
select.set_on_submit(show_next_window);
2725

28-
let mut siv = cursive::default();
29-
30-
siv.add_layer(Dialog::around(select.scrollable().fixed_size((40, 10))).title("My Keys"));
26+
let mut siv = Cursive::default();
27+
siv.add_layer(
28+
Dialog::around(select.scrollable().fixed_size((40, 10))).title("My Keys"),
29+
);
3130
siv.run();
3231
}
3332

3433
fn show_next_window(siv: &mut Cursive, str: &str) {
3534
siv.pop_layer();
3635

3736
let contents = fs::read_to_string(str).expect("Should have been able to read the file");
38-
let text = contents;
37+
let text: String = contents;
3938

40-
siv.add_layer(Dialog::around(TextView::new(text)).button("Quit", |s| s.quit()));
39+
siv.add_layer(
40+
Dialog::around(TextView::new(text)).button("Quit", |s| s.quit()),
41+
);
4142
}

0 commit comments

Comments
 (0)