this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

use std.Io.Duration to specify queryTerminal timeout

authored by

Jeffrey C. Ollie and committed by
Tim Culverhouse
65e8ed31 c6bba620

+48 -31
+3 -3
README.md
··· 72 72 .target = target, 73 73 .optimize = optimize, 74 74 }); 75 - 75 + 76 76 // add vaxis dependency to module 77 77 const vaxis = b.dependency("vaxis", .{ 78 78 .target = target, 79 79 .optimize = optimize, 80 80 }); 81 81 exe_mod.addImport("vaxis", vaxis.module("vaxis")); 82 - 82 + 83 83 //create executable 84 84 const exe = b.addExecutable(.{ 85 85 .name = "project_foo", ··· 330 330 331 331 // Sends queries to terminal to detect certain features. This should always 332 332 // be called after entering the alt screen, if you are using the alt screen 333 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 333 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 334 334 335 335 while (true) { 336 336 // nextEvent blocks until an event is in the queue
+19 -11
build.zig
··· 47 47 view, 48 48 vt, 49 49 }; 50 + var examples: std.EnumMap(Example, *std.Build.Module) = .init(.{}); 51 + inline for (std.meta.fields(Example)) |field| { 52 + const example: Example = @enumFromInt(field.value); 53 + examples.put( 54 + example, 55 + b.createModule(.{ 56 + .root_source_file = b.path( 57 + b.fmt("examples/{t}.zig", .{example}), 58 + ), 59 + .target = target, 60 + .optimize = optimize, 61 + .imports = &.{ 62 + .{ .name = "vaxis", .module = vaxis_mod }, 63 + }, 64 + }), 65 + ); 66 + } 50 67 const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input; 51 68 const example_step = b.step("example", "Run example"); 52 69 const example = b.addExecutable(.{ 53 - .name = "example", 54 - .root_module = b.createModule(.{ 55 - .root_source_file = b.path( 56 - b.fmt("examples/{s}.zig", .{@tagName(example_option)}), 57 - ), 58 - .target = target, 59 - .optimize = optimize, 60 - .imports = &.{ 61 - .{ .name = "vaxis", .module = vaxis_mod }, 62 - }, 63 - }), 70 + .name = b.fmt("example-{t}", .{example_option}), 71 + .root_module = examples.get(example_option) orelse unreachable, 64 72 }); 65 73 66 74 const example_run = b.addRunArtifact(example);
+1 -1
examples/cli.zig
··· 20 20 try loop.start(); 21 21 defer loop.stop(); 22 22 23 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 23 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 24 24 25 25 var text_input = TextInput.init(alloc); 26 26 defer text_input.deinit();
+1 -1
examples/image.zig
··· 31 31 std.log.warn("BBBB", .{}); 32 32 try vx.enterAltScreen(tty.writer()); 33 33 std.log.warn("CCCC", .{}); 34 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 34 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 35 35 36 36 std.log.warn("DDDD", .{}); 37 37 var read_buffer: [1024 * 1024]u8 = undefined; // 1MB buffer
+1 -1
examples/main.zig
··· 21 21 22 22 // Optionally enter the alternate screen 23 23 try vx.enterAltScreen(tty.writer()); 24 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 24 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 25 25 26 26 // We'll adjust the color index every keypress 27 27 var color_idx: u8 = 0;
+1 -1
examples/table.zig
··· 39 39 try loop.start(); 40 40 defer loop.stop(); 41 41 try vx.enterAltScreen(tty.writer()); 42 - try vx.queryTerminal(tty.writer(), 250 * std.time.ns_per_ms); 42 + try vx.queryTerminal(tty.writer(), .fromMilliseconds(250)); 43 43 44 44 const logo = 45 45 \\░█░█░█▀█░█░█░▀█▀░█▀▀░░░▀█▀░█▀█░█▀▄░█░░░█▀▀░
+1 -1
examples/text_input.zig
··· 60 60 try writer.flush(); 61 61 // Sends queries to terminal to detect certain features. This should 62 62 // _always_ be called, but is left to the application to decide when 63 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 63 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 64 64 65 65 // The main event loop. Vaxis provides a thread safe, blocking, buffered 66 66 // queue which can serve as the primary event queue for an application
+1 -1
examples/text_view.zig
··· 25 25 defer loop.stop(); 26 26 27 27 try vx.enterAltScreen(tty.writer()); 28 - try vx.queryTerminal(tty.writer(), 20 * std.time.ns_per_s); 28 + try vx.queryTerminal(tty.writer(), .fromSeconds(20)); 29 29 30 30 var text_view = TextView{}; 31 31 var text_view_buffer = TextView.Buffer{};
+1 -1
examples/vaxis.zig
··· 26 26 defer loop.stop(); 27 27 28 28 try vx.enterAltScreen(tty.writer()); 29 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 29 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 30 30 31 31 try vx.queryColor(tty.writer(), .fg); 32 32 try vx.queryColor(tty.writer(), .bg);
+1 -1
examples/view.zig
··· 54 54 defer loop.stop(); 55 55 try vx.enterAltScreen(writer); 56 56 try writer.flush(); 57 - try vx.queryTerminal(tty.writer(), 20 * std.time.ns_per_s); 57 + try vx.queryTerminal(tty.writer(), .fromSeconds(20)); 58 58 59 59 // Initialize Views 60 60 // - Large Map
+1 -1
examples/vt.zig
··· 25 25 defer loop.stop(); 26 26 27 27 try vx.enterAltScreen(writer); 28 - try vx.queryTerminal(writer, 1 * std.time.ns_per_s); 28 + try vx.queryTerminal(writer, .fromSeconds(1)); 29 29 30 30 const vt_opts: vaxis.widgets.Terminal.Options = .{ 31 31 .winsize = .{
+3 -4
src/Loop.zig
··· 275 275 else => { 276 276 switch (event) { 277 277 .key_press => |key| { 278 - // Check for a cursor position response for our explicity width query. This will 278 + // Check for a cursor position response for our explicitly width query. This will 279 279 // always be an F3 key with shift = true, and we must be looking for queries 280 280 if (key.codepoint == vaxis.Key.f3 and 281 281 key.mods.shift and ··· 433 433 var vx = try vaxis.init(io, std.testing.allocator, &env_map, .{}); 434 434 defer vx.deinit(std.testing.allocator, tty.writer()); 435 435 436 - var loop: vaxis.Loop(Event) = .{ .tty = &tty, .vaxis = &vx }; 437 - try loop.init(io); 436 + var loop: vaxis.Loop(Event) = .init(io, &tty, &vx); 438 437 439 438 try loop.start(); 440 439 defer loop.stop(); 441 440 442 441 // Optionally enter the alternate screen 443 442 try vx.enterAltScreen(tty.writer()); 444 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_ms); 443 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 445 444 }
+13 -3
src/Vaxis.zig
··· 254 254 /// 255 255 /// This call will block until Vaxis.query_futex is woken up, or the timeout. 256 256 /// Event loops can wake up this futex when cap_da1 is received 257 - pub fn queryTerminal(self: *Vaxis, tty: *std.Io.Writer, timeout_ns: u64) !void { 257 + pub fn queryTerminal(self: *Vaxis, tty: *std.Io.Writer, timeout: std.Io.Duration) !void { 258 258 try self.queryTerminalSend(tty); 259 - // 1 second timeout 260 - try std.Io.futexWaitTimeout(self.io, atomic.Value(u32), &self.query_futex, .init(0), .{ .duration = .{ .clock = .real, .raw = .fromNanoseconds(timeout_ns) } }); 259 + try std.Io.futexWaitTimeout( 260 + self.io, 261 + atomic.Value(u32), 262 + &self.query_futex, 263 + .init(0), 264 + .{ 265 + .duration = .{ 266 + .clock = .real, 267 + .raw = timeout, 268 + }, 269 + }, 270 + ); 261 271 self.queries_done.store(true, .unordered); 262 272 try self.enableDetectedFeatures(tty); 263 273 }
+1 -1
src/vxfw/App.zig
··· 65 65 try loop.postEvent(.focus_in); 66 66 67 67 try vx.enterAltScreen(tty.writer()); 68 - try vx.queryTerminal(tty.writer(), 1 * std.time.ns_per_s); 68 + try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 69 69 try vx.setBracketedPaste(tty.writer(), true); 70 70 try vx.subscribeToColorSchemeUpdates(tty.writer()); 71 71