diff options
| author | 2026-10-05 00:47:02 +0000 | |
|---|---|---|
| committer | 2026-10-05 00:52:41 +0000 | |
| commit | 38706b1fac63041e24852b126a136d611f6b8cf3 (patch) | |
| tree | da2b202faf288519aa8614352c2f94992de7aae8 /src | |
| parent | 041dfd51d1d9e6707005836d4f6d1d3ac82301e3 (diff) | |
segunda iteração: sdl3 apenas pra áudio e timer; comandos emitidos pela stdin.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index d826539..0e08def 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,16 +1,16 @@ const sdl3 = @import("sdl3"); const std = @import("std"); +const posix = std.posix; const io = std.Io; -/// Frequency of the generated tone, in Hz (440 Hz is concert A). -const tone_hz = 440; -/// Amplitude of the generated tone, from 0.0 (silence) to 1.0 (full volume). -const tone_amplitude = 0.3; /// How long to sleep between event-loop iterations, in milliseconds. const poll_interval_ms = 50; const autumn_trees = "assets//autumn_trees.wav"; +// isso pra sistemas linux +const STDIN_FD: posix.fd_t = 0; + pub fn main( init: std.process.Init, ) !void { @@ -18,8 +18,8 @@ pub fn main( const log_app = sdl3.log.Category.application; - try sdl3.init(.{ .audio = true, .events = true }); - defer sdl3.quit(.{ .audio = true, .events = true }); + try sdl3.init(.{ .audio = true }); + defer sdl3.quit(.{ .audio = true }); try sdl3.mixer.init(); defer sdl3.mixer.quit(); @@ -42,12 +42,31 @@ pub fn main( try track.play(.{}); + // estado original do terminal + const termios_ro = try posix.tcgetattr(STDIN_FD); + + // ativa modo `raw` do terminal + var termios_rw = termios_ro; + + termios_rw.oflag.OPOST = false; + + termios_rw.iflag.IXON = false; + termios_rw.iflag.ICRNL = false; + + termios_rw.lflag.ECHO = false; + termios_rw.lflag.ICANON = false; + termios_rw.lflag.ISIG = false; + termios_rw.lflag.IEXTEN = false; + + try posix.tcsetattr(STDIN_FD, .FLUSH, termios_rw); + var quit_app = false; while (!quit_app) { - var buffer: [1024]u8 = undefined; + var buffer: [64]u8 = undefined; var stdin = io.File.stdin(); var stdin_reader = stdin.reader(init.io, &buffer); const reader_interface = &stdin_reader.interface; + // lê apenas um caractere da stdin const char = try reader_interface.peek(1); if (std.mem.eql(u8, char, " ")) { if (track.isPaused()) { @@ -62,6 +81,9 @@ pub fn main( sdl3.timer.delayMilliseconds(poll_interval_ms); } + // restaura terminal pro estado original ao final + try posix.tcsetattr(0, .FLUSH, termios_ro); + try track.stop(0); try log_app.logInfo("Quit.", .{}); } |
