Feat: WIP terse code documentation

This commit is contained in:
2026-02-26 01:08:16 +01:00
parent 71bd09d5ea
commit e1cf57918e
47 changed files with 499 additions and 24 deletions

View File

@@ -56,7 +56,26 @@ struct Args {
buffer: Option<u32>,
}
#[cfg(unix)]
fn redirect_stderr() -> Option<std::fs::File> {
use std::os::fd::FromRawFd;
let mut fds = [0i32; 2];
if unsafe { libc::pipe(fds.as_mut_ptr()) } != 0 {
return None;
}
unsafe {
libc::dup2(fds[1], libc::STDERR_FILENO);
libc::close(fds[1]);
libc::fcntl(fds[0], libc::F_SETFL, libc::O_NONBLOCK);
Some(std::fs::File::from_raw_fd(fds[0]))
}
}
fn main() -> io::Result<()> {
#[cfg(unix)]
let mut stderr_pipe = redirect_stderr();
#[cfg(unix)]
engine::realtime::lock_memory();
@@ -171,6 +190,26 @@ fn main() -> io::Result<()> {
app.ui.flash(&err, 3000, state::FlashKind::Error);
}
#[cfg(unix)]
if let Some(ref mut pipe) = stderr_pipe {
use std::io::Read;
let max_len = terminal.size().map(|s| s.width as usize).unwrap_or(80).saturating_sub(16);
let mut buf = [0u8; 1024];
while let Ok(n) = pipe.read(&mut buf) {
if n == 0 {
break;
}
let text = String::from_utf8_lossy(&buf[..n]);
for line in text.lines() {
let line = line.trim();
if !line.is_empty() {
let capped = if line.len() > max_len { &line[..max_len] } else { line };
app.ui.flash(capped, 5000, state::FlashKind::Error);
}
}
}
}
app.playback.playing = playing.load(Ordering::Relaxed);
while let Ok(midi_cmd) = midi_rx.try_recv() {