Skip to content

Instantly share code, notes, and snippets.

@enricostano
Created April 25, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enricostano/16d3eb5aff947fe455f6 to your computer and use it in GitHub Desktop.
Save enricostano/16d3eb5aff947fe455f6 to your computer and use it in GitHub Desktop.
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

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