Commit graph

293 commits

Author SHA1 Message Date
Tim Culverhouse
5e1f9b17a5 window: add child method for cleaner child spawning 2024-03-21 13:54:49 -05:00
Tim Culverhouse
7e23a64aec mouse_shape: set state of last render properly 2024-03-20 10:21:48 -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
Tim Culverhouse
b0944234c6 widgets(textinput): add toOwnedSlice
Add a way to get the contents of the TextInput
2024-03-19 13:25:03 -05:00
Tim Culverhouse
d40fb7cbdb examples: clear textinput on enter 2024-03-19 13:24:17 -05:00
Tim Culverhouse
8a5fe1a8ab gwidth: fix gwidth for no_zwj case 2024-03-19 13:20:00 -05:00
Tim Culverhouse
15c64a0e66 textinput: implement horizontal scrolling
Scroll the textinput widget horizontally when it overflows either side.
2024-03-18 08:26:53 -05:00
Tim Culverhouse
f18f6328bb textinput: fix deleteToEnd
Fix behavior of deleteToEnd to delete the character underneath the
cursor to the end of the line.
2024-03-18 08:06:44 -05:00
Tim Culverhouse
8e76610617 fix: catch error on show_cursor 2024-03-17 19:26:42 -05:00
Tim Culverhouse
449eb170f7 fix: always show cursor on deinit
The render method always hides the cursor, and only shows it if it needs
to be shown. This has the effect that if a caller never shows the
cursor, exits the application, and the shell doesn't re-show the cursor
then we have no visible cursor.

Always show the cursor on deinit to prevent such a curse.

Fixes: #10
2024-03-17 09:17:42 -05:00
Rylee Lyman
9496270ecd fix: don't rely on std.time.microTimestamp() for accurate statistics
I don't know the extent to which you care about accuracy for rendering
statistics. I found when working on seamstress that the `timestamp`
calls in `std.time` were so unreliable as to be unusable, sometimes
reporting negative time deltas within a single
function. `std.time.Timer`, on the other hand, has been rock-solid in
my experience.
2024-03-14 07:52:19 -05:00
Tim Culverhouse
1e5560cc09 textinput: add clear methods
Add clear methods to reset the underlying GapBuffer and reset cursor
positions

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-12 07:35:35 -05:00
Rylee Alanza Lyman
0798182012
feat: adds gap_buffer.zig for TextInput (#6)
Use a gap buffer for the `TextInput` widget instead of an `ArrayList`.
2024-03-12 06:38:23 -05:00
Tim Culverhouse
5e940fd295 print: continue on 0 width graphemes or words
Don't print 0 width graphemes or words. Usually these will be
overwritten since we advance by 0 columns, however if one is at the end
of text it can mess up rendering.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-11 19:01:43 -05:00
Tim Culverhouse
c5891399f1 api: export Screen and gwidth
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-11 09:38:52 -05:00
Tim Culverhouse
cecf774ed2 event: implement pollEvent and tryEvent
Implement a way for an application to poll the event loop in a blocking
way without popping an event. Implement a non-blocking pop. These
together enable an application to poll the event loop and then drain it.
This is useful when lots of events are delivered in a short amount of
time so an application can batch process the events and then render.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-11 09:24:42 -05:00
Tim Culverhouse
22af4908a1 window: fix wrap method
The wrap method was returning a bool from the call to print. Fix this.
2024-03-10 07:48: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
0192860c85 render: reposition cursor when moving to new row
Explicitly reposition the cursor when moving to a new row to enable
terminals that support text selection to _not_ select the entire screen,
since the entire screen is wrapped.
2024-03-07 20:39:37 -06:00
Tim Culverhouse
6dafeb7820 render: check bounds when setting skipped
A double-wide character in the last cell can force this to go OOB.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-06 19:23:47 -06:00
Tim Culverhouse
378984bd87 print: fix bounds for word wrap
Let words go all the way to the end

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-05 15:46:44 -06:00
Tim Culverhouse
7db582b4f3 border: add bottom border
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-05 15:46:30 -06:00
Tim Culverhouse
778346feea render: fix handling of zero-width cells
The render loop could get stuck in an infinite loop when it encounters a
zero width cell. Always set the width to at least 1, and assert this.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-05 15:45:32 -06:00
Tim Culverhouse
5560545b54 update ziglyph
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-05 15:45:07 -06:00
Tim Culverhouse
fa39f0a067 window: saturate size, export Color
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-01 21:29:16 -06:00
Tim Culverhouse
c662de4df0 lib: export Segment, PrintOptions, and ziglyph
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-01 12:28:48 -06:00
Tim Culverhouse
e281a67a43 window: add print method
Add a print method with multiple print options

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-01 12:28:29 -06:00
Tim Culverhouse
2fab89f2cb screen: allow reading of cells
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-01 12:28:03 -06:00
Tim Culverhouse
9dae256960 border: add right border
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-03-01 12:27:49 -06:00
Tim Culverhouse
cf71bb4e7c queue: fix thread safety
Fix thread safety with changes by leeward on IRC. leeward put this code
on sourcehut here: https://hg.sr.ht/~nmichaels/threadsafeq
2024-03-01 12:25:15 -06:00
Tim Culverhouse
dff38f84d1 border: fix all border limits 2024-02-28 16:14:55 -06:00
Tim Culverhouse
ba29a71b3b tty: change logged line to level debug 2024-02-27 07:44:59 -06:00
00JCIV00
e87d64a2b3 Added the table.zig example
- Created a basic user management example for the Table widget.
2024-02-26 19:27:56 -06:00
00JCIV00
923c81d7d2 widgets: added table widget
- Added `Table.zig` under the `src/widgets` directory and `widgets.zig` module.
- Created the `drawTable()` function to draw a Table to the provided parent Window based on the provided ArrayList.
- Created the `TableContext` struct to manage state and attributes for the `drawTable()` function.
2024-02-26 19:21:12 -06:00
00JCIV00
b57aab7040 Added the "matchesAny()" method to Keys 2024-02-26 19:21:12 -06:00
00JCIV00
70f1e3495c Changed log.info calls to log.debug for better release builds 2024-02-26 19:21:12 -06:00
00JCIV00
4a87c5f408 Added public Window declaration to main.zig 2024-02-26 19:21:12 -06:00
00JCIV00
b7d7ba6b36 example: s/start/startReadThread s/stop/stopReadThread 2024-02-26 19:06:05 -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
00JCIV00
4069c83092 docs: add build step for autodoc
Add build step to generate autodocs and add github workflow for
publishing
2024-02-26 17:09:29 -06:00
Tim Culverhouse
9d87579076 key: remove duplicate match rule 2024-02-24 19:42:35 -06:00
Tim Culverhouse
d51530cb73 parser: don't encode tab and enter as ctrl+I and ctrl+m 2024-02-24 19:25:45 -06:00
Tim Culverhouse
9968735795 zigimg: use fork until PR merged
Use my fork of zigimg with the updated zlib api. Revert back to
zigimg/zigimg once that PR is merged.
2024-02-24 08:14:44 -06:00
Tim Culverhouse
981932debd queue: make public 2024-02-24 08:14:12 -06:00
Tim Culverhouse
0d730aba80 queue: update comments, add tryPop
Update comments on queue, and add a tryPop function which is nonblocking

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-02-19 10:11:18 -06:00
drust
6461e6719c Fixed the .len 2024-02-18 21:39:52 -06:00
Tim Culverhouse
8d0f73e951 gwidth: add no_zwj measurement method
Add the no_zwj measurement method which measures the same as unicode,
but strips all ZWJs from the input string. This mimics how Kitty
measures graphemes

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2024-02-18 12:26:23 -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