git ssb

0+

dinoworm 🐛 / metronome



Commit 9b8912a81188690277f8add60b236015174da8c9

terminal beats

Michael Williams committed on 5/12/2018, 2:33:00 PM
Parent: 2138ff1d0d8e0e410cbf1d5d0676dfd960019e0c

Files changed

Cargo.lockchanged
Cargo.tomlchanged
src/main.rschanged
README.mdadded
Cargo.lockView
@@ -1,4 +1,37 @@
11 [[package]]
2 +name = "gcc"
3 +version = "0.3.54"
4 +source = "registry+https://github.com/rust-lang/crates.io-index"
5 +
6 +[[package]]
7 +name = "libc"
8 +version = "0.2.40"
9 +source = "registry+https://github.com/rust-lang/crates.io-index"
10 +
11 +[[package]]
212 name = "metronome"
313 version = "0.1.0"
14 +dependencies = [
15 + "ncurses 5.91.0 (registry+https://github.com/rust-lang/crates.io-index)",
16 +]
417
18 +[[package]]
19 +name = "ncurses"
20 +version = "5.91.0"
21 +source = "registry+https://github.com/rust-lang/crates.io-index"
22 +dependencies = [
23 + "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
24 + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
25 + "pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
26 +]
27 +
28 +[[package]]
29 +name = "pkg-config"
30 +version = "0.3.11"
31 +source = "registry+https://github.com/rust-lang/crates.io-index"
32 +
33 +[metadata]
34 +"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
35 +"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
36 +"checksum ncurses 5.91.0 (registry+https://github.com/rust-lang/crates.io-index)" = "431cc11a5225e21cb85ea479858ac2e0b3c7a67c9506016cd8818de15dcdc8f1"
37 +"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
Cargo.tomlView
@@ -3,4 +3,10 @@
33 version = "0.1.0"
44 authors = ["Michael Williams <michael.williams@enspiral.com>"]
55
66 [dependencies]
7 +# ctrlc = { version = "3.0", features = ["termination"] }
8 +# ncurses = { version = "5.91.0", features = "wide" }
9 +
10 +[dependencies.ncurses]
11 +version = "5.91.0"
12 +features = ["wide"]
src/main.rsView
@@ -1,28 +1,114 @@
1 +/*
12 use std::io;
23 use std::io::prelude::*;
34
5 +use std::sync::mpsc;
46 use std::thread::sleep;
57 use std::time::{Duration};
68
79 fn main () {
10 + let metronome = Metronone::new();
811 metronome().unwrap();
912 }
1013
11-fn metronome () -> io::Result<()> {
12- let stdin = io::stdin();
13- let mut buffer = vec![0_u8; 2_usize.pow(8)];
14 +pub struct Metronone {}
1415
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 + */
1583 loop {
16- let mut handle = stdin.lock();
84 + let ch = ncurses::wget_wch(ncurses::stdscr());
1785
18- match handle.read(&mut buffer) {
19- Ok(num_bytes) => {
20- println!("{} bytes read", num_bytes);
21- let string = String::from_utf8(buffer.clone()).unwrap();
22- },
23- Err(error) => println!("error: {}", error),
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 => {}
24102 }
25103
26- sleep(Duration::new(0, 30 * 1000));
104 + ncurses::refresh();
27105 }
106 +
107 + ncurses::endwin();
28108 }
109 +
110 +fn tap () {
111 + ncurses::attron(ncurses::A_BOLD());
112 + ncurses::printw("\nBeat");
113 + ncurses::attroff(ncurses::A_BOLD());
114 +}
README.mdView
@@ -1,0 +1,5 @@
1 +## notes
2 +
3 +```shell
4 +sudo apt install libncursesw5-dev
5 +```

Built with git-ssb-web