Files: 9b8912a81188690277f8add60b236015174da8c9 / src / main.rs
2764 bytesRaw
1 | /* |
2 | use std::io; |
3 | use std::io::prelude::*; |
4 | |
5 | use std::sync::mpsc; |
6 | use std::thread::sleep; |
7 | use std::time::{Duration}; |
8 | |
9 | fn main () { |
10 | let metronome = Metronone::new(); |
11 | metronome().unwrap(); |
12 | } |
13 | |
14 | pub struct Metronone {} |
15 | |
16 | impl Metronome () { |
17 | pub fn new () -> <()> { |
18 | let stdin = io::stdin(); |
19 | let mut buffer = vec![0_u8; 2_usize.pow(8)]; |
20 | |
21 | loop { |
22 | let mut handle = stdin.lock(); |
23 | match handle.read(&mut buffer) { |
24 | Ok(num_bytes) => { |
25 | println!("{} bytes read", num_bytes); |
26 | let string = String::from_utf8(buffer.clone()).unwrap(); |
27 | }, |
28 | Err(error) => println!("error: {}", error), |
29 | } |
30 | |
31 | sleep(Duration::new(0, 30 * 1000 * 1000)); |
32 | } |
33 | } |
34 | */ |
35 | |
36 | /* |
37 | Copyright ยฉ 2013 Free Software Foundation, Inc |
38 | See licensing in LICENSE file |
39 | File: examples/ex_7.rs |
40 | Author: Jesse 'Jeaye' Wilkerson |
41 | Description: |
42 | Basic input and attribute example, using the Unicode-aware get_wch functions. |
43 | */ |
44 | |
45 | extern crate ncurses; |
46 | // extern crate ctrlc; |
47 | |
48 | use std::char; |
49 | use ncurses::{WchResult}; |
50 | // use std::sync::atomic::{AtomicBool, Ordering}; |
51 | // use std::sync::Arc; |
52 | |
53 | |
54 | // https://unicode.org/charts/PDF/U0000.pdf |
55 | static CHAR_SPACE: u32 = 0x0020; |
56 | static CHAR_RETURN: u32 = 0x000D; |
57 | static CHAR_NEWLINE: u32 = 0x000A; |
58 | |
59 | fn main() { |
60 | // let locale_conf = LcCategory::all; |
61 | // setlocale(locale_conf, "en_US.UTF-8"); |
62 | |
63 | /* Setup ncurses. */ |
64 | ncurses::initscr(); |
65 | |
66 | /* Enable mouse events. */ |
67 | ncurses::mousemask(ncurses::ALL_MOUSE_EVENTS as ncurses::mmask_t, None); |
68 | |
69 | /* Allow for extended keyboard (like F1). */ |
70 | ncurses::keypad(ncurses::stdscr(), true); |
71 | ncurses::noecho(); |
72 | |
73 | |
74 | /* |
75 | let running = Arc::new(AtomicBool::new(true)); |
76 | let r = running.clone(); |
77 | ctrlc::set_handler(move || { |
78 | r.store(false, Ordering::SeqCst); |
79 | }).expect("Error setting Ctrl-C handler"); |
80 | |
81 | while running.load(Ordering::SeqCst) { |
82 | */ |
83 | loop { |
84 | let ch = ncurses::wget_wch(ncurses::stdscr()); |
85 | |
86 | match ch { |
87 | Some(WchResult::KeyCode(ncurses::KEY_MOUSE)) => { |
88 | tap(); |
89 | } |
90 | |
91 | // https://github.com/jeaye/ncurses-rs/blob/master/src/constants.rs |
92 | Some(WchResult::KeyCode(_)) => {} |
93 | |
94 | // Some(WchResult::KeyCode(KEY_ENTER)) => beat(), |
95 | Some(WchResult::Char(ch)) => { |
96 | if (ch == CHAR_SPACE || ch == CHAR_NEWLINE) { |
97 | tap(); |
98 | } |
99 | } |
100 | |
101 | None => {} |
102 | } |
103 | |
104 | ncurses::refresh(); |
105 | } |
106 | |
107 | ncurses::endwin(); |
108 | } |
109 | |
110 | fn tap () { |
111 | ncurses::attron(ncurses::A_BOLD()); |
112 | ncurses::printw("\nBeat"); |
113 | ncurses::attroff(ncurses::A_BOLD()); |
114 | } |
115 |
Built with git-ssb-web