Commit graph

53 commits

Author SHA1 Message Date
Tim Culverhouse
93ac8e00f8 vaxis: add support for color scheme updates 2024-05-26 06:52:06 -05:00
Tim Culverhouse
6b9f91986c vaxis: add support for color reports (OSC 4, 10, 11, 12)
Add support for querying colors (index, foreground, background, and
cursor)
2024-05-24 10:59:20 -05:00
Tim Culverhouse
465c01e403 chore: remove TODO from tty 2024-05-23 15:41:59 -05:00
Tim Culverhouse
11dcd099fa tty: correctly handle partial reads 2024-05-23 15:39:08 -05:00
CJ van den Berg
1c11333717 tty: do not close /dev/tty on macos
Attempting to close /dev/tty may block indefinitely on macos if another
thread is already blocked on a read operation. As there is no practical
use for closing /dev/tty on exit besides unblocking other threads (which
does not work on macos anyway) we can just skip the close call.
2024-05-23 12:38:11 -05:00
CJ van den Berg
55809160b9 vaxis: detect pixel mouse mode and translate coordinates to cell offsets
This detects support for pixel mouse mode so it can be enabled only
if supported.

This also translates pixel coordinates to something more compatible
with plaine cell coordinates. This make it much easier to write
applications that support both.
2024-05-22 15:04:26 -05:00
CJ van den Berg
d48826c0b1 vaxis: add osc52 copy/paste support 2024-05-22 13:51:19 -05:00
Tim Culverhouse
dea1a875e0 chore: zig fmt 2024-05-12 20:27:24 -05:00
00JCIV00
ca0371bc44 Updated 'os' to 'posix' for Zig v0.12-3457 2024-05-12 20:25:51 -05:00
00JCIV00
a07d4f19a7 Reorganized Namespaces
- Consolidated `main.zig` into `vaxis.zig` as the new library entry point.
- Exposed more Types throughout the library for more transparent doc navigation.
- Reorganized certain Modules and Types to be more coherent and readable.
- Re-generated docs to reflect these changes.
2024-05-12 20:25:51 -05:00
CJ van den Berg
8819e192cc vaxis: export Parser, Tty and getWinsize for applications that cannot use Loop 2024-05-09 19:14:49 -05:00
Tim Culverhouse
a0db41f87c render: add cli renderer
Add a renderer for applications running on the primary screen. This
renderer uses relative cursor positioning, and works with all the same
primitives as the alternate screen.

Fix a bug where repositioning was never turned back to false. This was a
nasty one with huge perf implications.

Set internal cells to a space and default on init. This prevents us from
writing them. As a result, we now issue a hardware clear on resize.
2024-05-02 12:50:33 -05:00
Tim Culverhouse
50242b984b loop: fully clean up tty when stopping event loop
Previously, stopping the read thread would not fully clean up the tty.
This could result in issues such as #9 where the terminal state was
borked upon return to shell or if temporarily exiting the TUI.

Fixes: #9
2024-04-30 16:42:10 -05:00
Tim Culverhouse
df2f936317 tty: handle key_release events 2024-04-30 08:55:26 -05:00
Tim Culverhouse
8a71cd4c85 zg: complete replacement of ziglyph with zg 2024-04-29 14:00:08 -05:00
Tim Culverhouse
9fec6f122b core: replace ziglyph.GraphemeIterator with zg version
ziglyph is being replaced by zg. Replace all calls to ziglyph grapheme
iterator with the zg version
2024-04-29 13:03:01 -05:00
Tim Culverhouse
41f76e8f03 vaxis: refactor to split Loop and Vaxis
Refactor the main API to split Loop and Vaxis types. This enables the
core Vaxis type to be more easily referenced in other types, since it
doesn't require a comptime type parameter. This will make the switch to
the zg unicode library easier.
2024-04-29 12:26:50 -05:00
Tim Culverhouse
e37790904f update min zig version, readme 2024-03-21 19:29:26 -05:00
Tim Culverhouse
981909cce9 tty: remove unused quit_fd field 2024-03-19 13:41:01 -05:00
Tim Culverhouse
a505d67276 core: close read thread via DSR
Request a device status report to trigger a read. Wait for the thread to
join in the main loop to ensure that the read thread has fully closed.
This should prevent the need for polling and a quit_fd, and a separate
mechanism on macos.
2024-03-19 13:41:01 -05:00
Rylee Lyman
c65dab952c fix: use select on macOS
the man page for macOS `poll(2)` says, under "bugs", that polling
devices does not work, and indeed, although the current implementation
based on poll(2) does produce output, it does not appear to actually
be polling for this reason; instead the wait is blocking on the `read`
call, causing the macOS user to need to input another character to
exit.

this change introduces a wrapper over macOS's implementation of
`select`, modeled after `std.io.poll` as `select.zig`. it is a compile
error to use `select.zig` when `builtin.os.tag.isDarwin()` is false. a
lightly altered version of `Tty.zig` accompanies this change. it's
certainly possible to incorporate the two into one file; i didn't just
to leave the other one in its original state.

with this change, writing to the pipe correctly exits.

additionally, on macOS, `Thread.setName` must be called from the
thread whose name you wish to set, so I have just commented out that
line.
2024-03-09 06:45:36 -06:00
Tim Culverhouse
ba29a71b3b tty: change logged line to level debug 2024-02-27 07:44:59 -06:00
Tim Culverhouse
f84bad6420 tty: set termios ISIG = false and PARMRK = false
When changing to the new zig termios api, I missed setting two flags.
This left SIGINTs being sent to the terminal and applications not able
to handle ctrl+c.
2024-02-26 18:26:12 -06:00
Tim Culverhouse
6418570819 update for zig-0.12.0-2809
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-02-18 12:20:47 -06:00
Jora Troosh
4a463cfa3a
refactor: make code more idiomatic
- Added standard .gitattributes file for Zig projects.
- Reworked build.zig a little, hopefully it's a bit clearer. Also, now zig build will run all steps.
- outer: while in examples was redundant since there's only one loop to break from. switch expressions don't allow breaking from them, so breaking is only for loops, i.e. while and for.
- When returning a struct instance from a function, the compiler infers the return type from function signature, so instead of return MyType{...}; , it's more idiomatic to write return .{...};.
- Logging adds a new line by default, so you don't usually need to write \n like here: log.debug("event: {}\r\n", .{event});.
2024-02-11 12:59:33 -06:00
Tim Culverhouse
2b8346f691 tty: shadow os.system with our own switch
When linking lib_c, os.system gets overwritten with std.c. The linux
implementation of std.c doesn't contain the constants we need.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-02-02 11:14:25 -06:00
Tim Culverhouse
f3cf7bcfcd mouse: implement mouse parsing and events
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-31 12:50:00 -06:00
Tim Culverhouse
8c8c592722 parser: handle parsing of apc, sos, pm strings
This lets us detect kitty graphics.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-31 06:59:34 -06:00
Tim Culverhouse
9f89ed06f3 vaxis: use vt caps to measure grapheme widths
Implement our own grapheme measuring function which switches on whether
the terminal supports mode 2027

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-24 06:12:39 -06:00
Tim Culverhouse
04f6117cfe vaxis: enable da1 parsing, use futex timeout to return from query
Now that DA1 parsing is done, block the queryTerminal function until the
DA1 response is received, or a 1 second timeout elapses. With this
functionality, move certain events into Vaxis's realm of handling: IE
enabling kitty keyboard, unicode mode, etc

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-23 21:30:09 -06:00
Tim Culverhouse
a2dc97c039 vaxis: add mode 2027 query parsing, wcwidth measurement
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-23 21:06:02 -06:00
Tim Culverhouse
aaa1c17a81 key: enable kitty keyboard
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-23 13:25:31 -06:00
Tim Culverhouse
44ff960cb0 caps: implement first capability response (kitty keyboard)
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-23 08:10:59 -06:00
Tim Culverhouse
f1a9e21a98 tty: use grapheme cache in the tty run method
We only need the grapheme cache when we are parsing input

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-22 10:40:30 -06:00
Tim Culverhouse
64557bf9ab parser: use a ring buffer to store raw text
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-22 10:26:33 -06:00
Tim Culverhouse
40525eb038 parser: handle graphemes
I'm not positive this is the final approach. We fill in the `text` field
if there was multi-codepoint text generated from the key_press.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-21 17:54:44 -06:00
Tim Culverhouse
25d844702f tty: add events to parser handling, update comment
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-21 13:20:34 -06:00
Tim Culverhouse
8caa67d5b3 tty: add todo for incomplete parsing
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-21 13:16:52 -06:00
Tim Culverhouse
4ac15e2195 parser: refactor into testable function
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-21 12:47:34 -06:00
Tim Culverhouse
38b41c4ecf parser: more kitty key parsing
Add some more implementation details to kitty key parsing

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-21 11:53:25 -06:00
Tim Culverhouse
93d9ead99c parser: more progress on CSI parsing
Add additional CSI parsing for keys

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-20 08:05:22 -06:00
Tim Culverhouse
462a303903 examples: add some comments
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 22:02:10 -06:00
Tim Culverhouse
58bc6864cb render: implement double buffered screen for rendering
This lets us efficiently render by only updating cells that have changed
since last render

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 13:13:20 -06:00
Tim Culverhouse
43ea14e263 queue: check for fields before posting events
This allows users of the lib to not worry about having the fields on
their enum

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 12:24:02 -06:00
Tim Culverhouse
bef5276340 vaxis: send winsize at run, initialize screen to default cells
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 11:44:20 -06:00
Tim Culverhouse
8c8caf4769 tty: enable writing to tty and add smcup in example
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 10:58:14 -06:00
Tim Culverhouse
c3964fec43 rename project libvaxis
This is so similar to my vaxis project for go that we'll retain the name
here as well. The two can keep similar APIs and feature sets, but are
used in different languages. Maybe someday libvaxis will export a C api
for even broader use

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-19 10:13:32 -06:00
Tim Culverhouse
266c5ec224 screen: implement initial screen data structure
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-18 23:18:19 -06:00
Tim Culverhouse
a9c97d051b tty: implement winch handling
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-18 22:37:48 -06:00
Tim Culverhouse
3176eb81ef hack: go to ground state in escape state
Only doing this until I finish the parser

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-01-18 20:35:33 -06:00