Skip to content

Commit 540dc7f

Browse files
authored
Fix data tipe & paramter, runner
1 parent cf09e4d commit 540dc7f

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

src/main.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
use cursive::{align::HAlign, traits::*, views::*, Cursive};
2-
use std::{env, fs, path::Path};
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;
37

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

913
for entry in fs::read_dir(path).expect("Unable to list") {
1014
let entry = entry.expect("unable to get entry");
1115
let path = entry.path();
1216
let str = path.display().to_string();
1317

1418
if !str.contains("known_hosts") {
15-
arr.push(str);
19+
arr.push((str.clone(), str));
1620
}
1721
}
1822

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

2325
select.add_all(arr);
2426
select.set_on_submit(show_next_window);
2527

2628
let mut siv = Cursive::default();
27-
siv.add_layer(
28-
Dialog::around(select.scrollable().fixed_size((40, 10))).title("My Keys"),
29-
);
29+
30+
siv.add_layer(Dialog::around(select.scrollable().fixed_size((40, 10))).title("My Keys"));
3031
siv.run();
3132
}
3233

33-
fn show_next_window(siv: &mut Cursive, str: &str) {
34+
fn show_next_window(siv: &mut Cursive, str: &(String, String)) {
3435
siv.pop_layer();
3536

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

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

0 commit comments

Comments
 (0)