Skip to content

Instantly share code, notes, and snippets.

@enricostano
Created April 25, 2015 14:55
Show Gist options
  • Select an option

  • Save enricostano/16d3eb5aff947fe455f6 to your computer and use it in GitHub Desktop.

Select an option

Save enricostano/16d3eb5aff947fe455f6 to your computer and use it in GitHub Desktop.

Revisions

  1. enricostano created this gist Apr 25, 2015.
    65 changes: 65 additions & 0 deletions main.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    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();
    }