commits
Now that the writer interfaces are no longer generic, the anyWriter term does not
make sense. This commit renames it to just writer() to match idiomatic zig usage.
TestTty init function was missing the buffer parameter that PosixTty
requires. Update TestTty.init to accept a buffer: []u8 parameter to
match the consistent interface pattern used by PosixTty.
This ensures both TTY implementations have compatible initialization
signatures for polymorphic usage.
Amp-Thread-ID: https://ampcode.com/threads/T-970f3138-9911-4509-9c12-cd008b09aa0d
Co-authored-by: Amp <amp@ampcode.com>
Update the documentation to reflect the current minimum Zig
version requirement after bumping it in build.zig.zon.
Amp-Thread-ID: https://ampcode.com/threads/T-d7d30501-29b2-4efe-a39a-200167bdf876
Co-authored-by: Amp <amp@ampcode.com>
Update minimum_zig_version from 0.14.0 to 0.15.1 to reflect the
actual Zig version required for building the library with the
current codebase changes.
Amp-Thread-ID: https://ampcode.com/threads/T-d7d30501-29b2-4efe-a39a-200167bdf876
Co-authored-by: Amp <amp@ampcode.com>
This prevents reporting kitty mouse leave events as spurious mouse clicks.
Unicode is not actually used by Screen anyway,
and Vaxis.init cannot return with Vaxis.screen.unicode assigned
as the pointer to Vaxis.unicode could be dangling.
The initial Vaxis without .screen.unicode
makes {Window,widgets.View}.gwidth a footgun.
This also fixes the vt example.
Fixes: 58bc3fd43d77 ("deps: update zg")
* vxfw(Border): add BorderLabels to Border widget
* - changed enum names to snake_case.
- used Grapheme Iterator instead of old range based loop.
- used `ctx.stringWidth()` instead of `text.len`.
- added empty label guard.
* modified loop to use stringWidth instead of i range
* - Added trailing comma at the end of BorderLabel alignment enum definition.
- Changed from `.width=1` to `.width=width`
* - Added @intCast for width
* fix zig fmt errors
Update the zigimg dependency to a newer version that changes the
fromFilePath API to require a read buffer parameter. Add 1MB read
buffers to both the image example and the Vaxis.loadImage function
to accommodate this new requirement.
This ensures the image example compiles successfully and the library
can continue to load images from file paths using the updated zigimg
interface.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
The fuzzy example was using the old ArrayList initialization pattern
and method signatures that changed in Zig 0.15. This updates the code
to use the new ArrayList API:
- Change ArrayList.init(allocator) to ArrayList{}
- Update append/appendSlice/deinit/clearAndFree calls to pass allocator
- Replace deprecated std.io.getStdOut() with std.posix.write()
- Fix variable shadowing conflict with stdout variable
Also includes minor formatting fixes and test mode early return in
Loop.zig to prevent infinite loops during testing.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update the final three examples (split_view, table, text_input) to work with
the new Writer API and fix ArrayList compatibility issues with newer Zig
versions throughout the vxfw framework.
Changes:
- Fix table.zig and text_input.zig to use Tty.init() buffer parameter
- Replace old bufferedWriter pattern with direct anyWriter() calls
- Update vxfw framework ArrayList usage to use new API requiring allocator
parameters for deinit(), append(), clearAndFree(), and toOwnedSlice()
- Fix Table widget ArrayList initialization
- Update hitTest method signatures to properly pass allocator parameters
All examples that don't require external dependencies (zigimg) or platform-
specific features now compile successfully with the updated Writer API.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update multiple examples to work with the new Tty.init() API that requires
a buffer parameter and fix related writer interface issues.
Changes:
- Add buffer parameter to Tty.init() calls in cli.zig, image.zig, vaxis.zig,
view.zig, and vt.zig
- Fix anyWriter() method signatures in tty.zig to accept const pointers
- Update App.zig in vxfw framework to handle buffer allocation
- Replace bufferedWriter usage pattern in view.zig with direct anyWriter calls
- Fix const-related writer interface issues
Most examples now compile successfully with the new Writer API. Some examples
like counter.zig and scroll.zig have additional issues with ArrayList API
changes that are unrelated to the Writer modifications.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update the codebase to use *std.io.Writer instead of std.io.AnyWriter
throughout the API surface. This change makes the writer interface more
consistent with the standard library's current patterns.
Changes include:
- Update all Vaxis function signatures to accept *std.io.Writer parameters
- Modify anyWriter() methods in tty implementations to return *std.io.Writer
- Replace writeBytesNTimes and writeByteNTimes calls with for loops since
std.io.Writer doesn't provide these convenience methods
- Update Tty.init() to require a buffer parameter for the new writer interface
- Fix examples/main.zig to work with the updated API
- Add early return in Loop.ttyRun() during tests to prevent infinite loops
This maintains API compatibility while aligning with std.io.Writer patterns.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-b6d69168-29b7-4ebf-b98f-a38a4e95a0db
Co-authored-by: Amp <amp@ampcode.com>
Replace the custom VTable-based writer implementations in both PosixTty
and WindowsTty with std.fs.File.Writer.initStreaming(). This change
eliminates approximately 50 lines of custom drain logic while providing
better performance through built-in optimizations.
The File.Writer streaming mode is ideal for TTY operations since TTYs
are non-seekable streams. The standard library implementation provides
vectored I/O operations, efficient syscalls like sendfile when
appropriate, and cross-platform compatibility.
All existing APIs remain unchanged - write(), anyWriter(), and
bufferedWriter() methods continue to work as before. Buffer management
is now handled entirely by the standard library rather than custom
code.
Amp-Thread-ID: https://ampcode.com/threads/T-b6d69168-29b7-4ebf-b98f-a38a4e95a0db
Co-authored-by: Amp <amp@ampcode.com>
Change PosixTty and WindowsTty init functions to accept a buffer slice
instead of creating a fixed-size buffer internally. This allows callers
to control buffer size and allocation strategy.
The buffer field in both structs is changed from [4096]u8 to []u8,
and the init functions now take a buffer: []u8 parameter that gets
assigned to the struct field.
Amp-Thread-ID: https://ampcode.com/threads/T-1502f393-0cb2-4350-975b-5c6305f60969
Co-authored-by: Amp <amp@ampcode.com>
Apply the same Writer API integration to WindowsTty that was done for
PosixTty. This provides consistent buffered writing capabilities across
both Windows and POSIX platforms using Zig 0.15.1's new Writer API.
The embedded writer uses @fieldParentPtr to access the parent WindowsTty
instance from the drain function, enabling efficient writes to the
Windows console handle when the buffer is full or flushed.
Add write() method and update opaqueWrite() to use the embedded writer
instead of direct windows.WriteFile() calls, providing automatic
buffering for better performance by reducing system call overhead.
Amp-Thread-ID: https://ampcode.com/threads/T-e1192d32-b3c3-43a6-b434-33fe5664bf0a
Co-authored-by: Amp <amp@ampcode.com>
Integrate Zig 0.15.1's new Writer API into the PosixTty structure by
embedding a std.io.Writer field with a 4096-byte buffer. This provides
buffered writing capabilities with proper VTable implementation.
The embedded writer uses @fieldParentPtr to access the parent PosixTty
instance from the drain function, enabling efficient writes to the
terminal file descriptor when the buffer is full or flushed.
Updated write() and opaqueWrite() methods to use the embedded writer
instead of direct posix.write() calls, providing automatic buffering
for better performance by reducing system call overhead.
Amp-Thread-ID: https://ampcode.com/threads/T-e1192d32-b3c3-43a6-b434-33fe5664bf0a
Co-authored-by: Amp <amp@ampcode.com>
The Zig fetcher is really finicky when it comes to proxies, even more so
when it comes to Git dependencies. Given that both GitHub and Codeberg
have tarball archive downloads I don't see why we need to use a Git clone
at all here
Use upstream. Instead of using the 0.14.1 release we are opting for this
commit since it includes the removal of `usingnamespace`, which means we
can have incremental compilation
Misuse of contractions.
See also:
- https://search.brave.com/search?q=it%27s+vs+its
- https://www.merriam-webster.com/grammar/when-to-use-its-vs-its
Fix vxfw.Surface.satisfiesContraints to properly check constraints.
Implement the kitty scaled text extension. We do this by adding a Scale
struct to the core Cell structure. The scale struct defines the scale,
numerator, denominator, and vertical positioning. We also query
independently for scaled text vs explicit width text.
Users of scaled text must be very careful of how they model their cells,
as cells must be written ahead of time with knowledge of the
capabilities of the underlying terminal. Libvaxis does not move contents
of cells based on scale (ie 3 contiguous cells of scale=2 with contents
"abc" will not transform into what you think - the user of the library
must take car to put a, b, and c into appropriate cells. Libvaxis will
do the work to prevent overwriting the cell). Capability can be checked
in the vx.caps.scaled_text value.
This reduces the time in Vaxis.render. I ran perf several times for ~60
seconds each time on example/vaxis.zig.
Before => 15.17% in Vaxis.render
After => 14.15% in Vaxis.render
This was introduced in zig 0.14
TestTty init function was missing the buffer parameter that PosixTty
requires. Update TestTty.init to accept a buffer: []u8 parameter to
match the consistent interface pattern used by PosixTty.
This ensures both TTY implementations have compatible initialization
signatures for polymorphic usage.
Amp-Thread-ID: https://ampcode.com/threads/T-970f3138-9911-4509-9c12-cd008b09aa0d
Co-authored-by: Amp <amp@ampcode.com>
* vxfw(Border): add BorderLabels to Border widget
* - changed enum names to snake_case.
- used Grapheme Iterator instead of old range based loop.
- used `ctx.stringWidth()` instead of `text.len`.
- added empty label guard.
* modified loop to use stringWidth instead of i range
* - Added trailing comma at the end of BorderLabel alignment enum definition.
- Changed from `.width=1` to `.width=width`
* - Added @intCast for width
* fix zig fmt errors
Update the zigimg dependency to a newer version that changes the
fromFilePath API to require a read buffer parameter. Add 1MB read
buffers to both the image example and the Vaxis.loadImage function
to accommodate this new requirement.
This ensures the image example compiles successfully and the library
can continue to load images from file paths using the updated zigimg
interface.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
The fuzzy example was using the old ArrayList initialization pattern
and method signatures that changed in Zig 0.15. This updates the code
to use the new ArrayList API:
- Change ArrayList.init(allocator) to ArrayList{}
- Update append/appendSlice/deinit/clearAndFree calls to pass allocator
- Replace deprecated std.io.getStdOut() with std.posix.write()
- Fix variable shadowing conflict with stdout variable
Also includes minor formatting fixes and test mode early return in
Loop.zig to prevent infinite loops during testing.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update the final three examples (split_view, table, text_input) to work with
the new Writer API and fix ArrayList compatibility issues with newer Zig
versions throughout the vxfw framework.
Changes:
- Fix table.zig and text_input.zig to use Tty.init() buffer parameter
- Replace old bufferedWriter pattern with direct anyWriter() calls
- Update vxfw framework ArrayList usage to use new API requiring allocator
parameters for deinit(), append(), clearAndFree(), and toOwnedSlice()
- Fix Table widget ArrayList initialization
- Update hitTest method signatures to properly pass allocator parameters
All examples that don't require external dependencies (zigimg) or platform-
specific features now compile successfully with the updated Writer API.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update multiple examples to work with the new Tty.init() API that requires
a buffer parameter and fix related writer interface issues.
Changes:
- Add buffer parameter to Tty.init() calls in cli.zig, image.zig, vaxis.zig,
view.zig, and vt.zig
- Fix anyWriter() method signatures in tty.zig to accept const pointers
- Update App.zig in vxfw framework to handle buffer allocation
- Replace bufferedWriter usage pattern in view.zig with direct anyWriter calls
- Fix const-related writer interface issues
Most examples now compile successfully with the new Writer API. Some examples
like counter.zig and scroll.zig have additional issues with ArrayList API
changes that are unrelated to the Writer modifications.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Update the codebase to use *std.io.Writer instead of std.io.AnyWriter
throughout the API surface. This change makes the writer interface more
consistent with the standard library's current patterns.
Changes include:
- Update all Vaxis function signatures to accept *std.io.Writer parameters
- Modify anyWriter() methods in tty implementations to return *std.io.Writer
- Replace writeBytesNTimes and writeByteNTimes calls with for loops since
std.io.Writer doesn't provide these convenience methods
- Update Tty.init() to require a buffer parameter for the new writer interface
- Fix examples/main.zig to work with the updated API
- Add early return in Loop.ttyRun() during tests to prevent infinite loops
This maintains API compatibility while aligning with std.io.Writer patterns.
Amp-Thread-ID: https://ampcode.com/threads/T-04d58023-ce84-479f-8974-6c8fad9ce9e5
Co-authored-by: Amp <amp@ampcode.com>
Replace the custom VTable-based writer implementations in both PosixTty
and WindowsTty with std.fs.File.Writer.initStreaming(). This change
eliminates approximately 50 lines of custom drain logic while providing
better performance through built-in optimizations.
The File.Writer streaming mode is ideal for TTY operations since TTYs
are non-seekable streams. The standard library implementation provides
vectored I/O operations, efficient syscalls like sendfile when
appropriate, and cross-platform compatibility.
All existing APIs remain unchanged - write(), anyWriter(), and
bufferedWriter() methods continue to work as before. Buffer management
is now handled entirely by the standard library rather than custom
code.
Amp-Thread-ID: https://ampcode.com/threads/T-b6d69168-29b7-4ebf-b98f-a38a4e95a0db
Co-authored-by: Amp <amp@ampcode.com>
Change PosixTty and WindowsTty init functions to accept a buffer slice
instead of creating a fixed-size buffer internally. This allows callers
to control buffer size and allocation strategy.
The buffer field in both structs is changed from [4096]u8 to []u8,
and the init functions now take a buffer: []u8 parameter that gets
assigned to the struct field.
Amp-Thread-ID: https://ampcode.com/threads/T-1502f393-0cb2-4350-975b-5c6305f60969
Co-authored-by: Amp <amp@ampcode.com>
Apply the same Writer API integration to WindowsTty that was done for
PosixTty. This provides consistent buffered writing capabilities across
both Windows and POSIX platforms using Zig 0.15.1's new Writer API.
The embedded writer uses @fieldParentPtr to access the parent WindowsTty
instance from the drain function, enabling efficient writes to the
Windows console handle when the buffer is full or flushed.
Add write() method and update opaqueWrite() to use the embedded writer
instead of direct windows.WriteFile() calls, providing automatic
buffering for better performance by reducing system call overhead.
Amp-Thread-ID: https://ampcode.com/threads/T-e1192d32-b3c3-43a6-b434-33fe5664bf0a
Co-authored-by: Amp <amp@ampcode.com>
Integrate Zig 0.15.1's new Writer API into the PosixTty structure by
embedding a std.io.Writer field with a 4096-byte buffer. This provides
buffered writing capabilities with proper VTable implementation.
The embedded writer uses @fieldParentPtr to access the parent PosixTty
instance from the drain function, enabling efficient writes to the
terminal file descriptor when the buffer is full or flushed.
Updated write() and opaqueWrite() methods to use the embedded writer
instead of direct posix.write() calls, providing automatic buffering
for better performance by reducing system call overhead.
Amp-Thread-ID: https://ampcode.com/threads/T-e1192d32-b3c3-43a6-b434-33fe5664bf0a
Co-authored-by: Amp <amp@ampcode.com>
Implement the kitty scaled text extension. We do this by adding a Scale
struct to the core Cell structure. The scale struct defines the scale,
numerator, denominator, and vertical positioning. We also query
independently for scaled text vs explicit width text.
Users of scaled text must be very careful of how they model their cells,
as cells must be written ahead of time with knowledge of the
capabilities of the underlying terminal. Libvaxis does not move contents
of cells based on scale (ie 3 contiguous cells of scale=2 with contents
"abc" will not transform into what you think - the user of the library
must take car to put a, b, and c into appropriate cells. Libvaxis will
do the work to prevent overwriting the cell). Capability can be checked
in the vx.caps.scaled_text value.