blob: 57271f5786e43026c56ef10414e08a2c0e64c8c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use unicode_width::UnicodeWidthStr;
use std::io::Write;
use std::time::Duration;
use rodio::{OutputStream, Sink};
use rodio::source::{SineWave, Source};
fn main() {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let mut stdout = std::io::stdout().lock();
for line in std::io::stdin().lines() {
let line: String = line
.unwrap()
.chars()
.map(|c| if c == '\t' { String::from(" ").repeat(8) } else { c.to_string() })
.collect();
let len = UnicodeWidthStr::width(&*line) as f32;
stdout.write_fmt(format_args!("{}\n", line)).unwrap();
sink.append(SineWave::new(44.0 * len)
.take_duration(Duration::from_secs_f32(0.1))
.amplify(0.20));
sink.sleep_until_end();
}
}
|