Skip to content

Instantly share code, notes, and snippets.

@enricostano
Created Apr 25, 2015
Embed
What would you like to do?
extern crate ncurses;
use std::fs::{self, ReadDir};
use std::path::Path;
use std::char;
use ncurses::*;
fn print_entries(dir: std::fs::ReadDir) {
for entry in dir {
match entry {
Ok(e) => {
let path = e.path();
let file_name = path.file_name();
attron(A_BOLD() | A_BLINK());
match file_name {
Some(f) => {
let string = f.to_str();
match string {
Some(s) => {
printw(format!("\n{}", s));
},
None => {
}
}
},
None => {
printw("Ouch!");
}
}
attroff(A_BOLD() | A_BLINK());
},
Err(e) => println!("Error: {}", e)
}
}
}
fn main() {
let path = Path::new("/home/enrico/Downloads");
let dir = fs::read_dir(&path);
/* Setup ncurses. */
initscr();
raw();
/* Allow for extended keyboard (like F1). */
keypad(stdscr, true);
noecho();
/* Prompt for a character. */
printw("Enter a character: ");
match dir {
Ok(d) => print_entries(d),
Err(e) => println!("Error: {}", e)
}
/* Refresh, showing the previous message. */
refresh();
/* Wait for one more character before exiting. */
getch();
endwin();
}
@enricostano
Copy link
Author

enricostano commented Apr 25, 2015

src/main.rs:21:24: 21:43 error: mismatched types:
 expected `&str`,
    found `collections::string::String`
(expected &-ptr,
    found struct `collections::string::String`) [E0308]
src/main.rs:21                 printw(format!("\n{}", s));
                                      ^~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment