Commit graph

49 commits

Author SHA1 Message Date
Yorhel
5129de737e Zig 0.15: Fix support for new IO interface
I've managed to get a single codebase to build with both 0.14 and 0.15
now, but compiling with Zig's native x86_64 backend seems buggy. Need to
investigate what's going on there.

This is a lazy "just get it to work" migration and avoids the use of
0.15-exclusive APIs. We can probably clean up some code when dropping
support for 0.14.
2025-08-19 14:02:41 +02:00
Yorhel
68671a1af1 Zig 0.15: Migrate all ArrayLists to the Unmanaged API
Managed ArrayLists are deprecated in 0.15. "ArrayList" in 0.15 is the
same as "ArrayListUnmanaged" in 0.14. The latter alias is still
available in 0.15, so let's stick with that for now. When dropping
support for 0.14, we can do s/ArrayListUnmanaged/ArrayList/.
2025-08-19 13:05:20 +02:00
Yorhel
66b875eb00 Add --delete-command option
Fixes #215.

delete.zig's item replacement/refresh code is pretty awful and may be
buggy in some edge cases. Existing refresh infrastructure wasn't
designed to update an individual file.
2025-07-15 18:27:10 +02:00
Eric Joldasov
ce9921846c
update to new names in std.builtin.Type
See https://github.com/ziglang/zig/pull/21225 .

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-03-03 22:46:49 +05:00
Eric Joldasov
e0ab5d40c7
change deprecated @setCold(true) to @branchHint(.cold)
New `@branchHint` builtin is more expressive than `@setCold`, therefore
latter was removed.
See https://github.com/ziglang/zig/pull/21214 .

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-03-03 22:46:49 +05:00
Henrik Bengtsson
db96bc698c SI units: The unit is kB, not KB 2024-12-22 11:21:36 -08:00
Yorhel
bd442673d2 Consolidate @cImports into a single c.zig
Which is, AFAIK, a recommended practice. Reduces the number of times
translate-c is being run and (most likely) simplifies a possible future
transition if/when @cImport is thrown out of the language.

Also uses zstd.h instead of my own definitions, mainly because I plan to
use the streaming API as well and those need more definitions.
2024-10-26 14:35:05 +02:00
Yorhel
90b43755b8 Use integer formatting instead of floating points
This avoids embedding Zig's floating point formatting tables and
ancillary code, shaving 17k off the final static binary for x86_64.

Also adjusted the cut-off points for the units to be more precise.
2024-08-03 15:37:54 +02:00
Yorhel
025e5ee99e Add import function for the new binary format
This isn't the low-memory browsing experience I was hoping to implement,
yet, but it serves as a good way to test the new format and such a
sink-based import is useful to have anyway.

Performance is much better than I had expected, and I haven't even
profiled anything yet.
2024-08-02 14:03:30 +02:00
Yorhel
e5508ba9b4 Fix OOM handling to be thread-safe 2024-07-17 11:48:58 +02:00
Yorhel
f2541d42ba Rewrite scan/import code, experiment with multithreaded scanning (again)
Benchmarks are looking very promising this time. This commit breaks a
lot, though:
- Hard link counting
- Refreshing
- JSON import
- JSON export
- Progress UI
- OOM handling is not thread-safe

All of which needs to be reimplemented and fixed again. Also haven't
really tested this code very well yet so there's likely to be bugs.

There's also a behavioral change: --exclude-kernfs is not checked on the
given root directory anymore, meaning that the filesystem the user asked
to scan is being scanned even if that's a 'kernfs'. I suspect that's
more sensible behavior.

The old scan.zig was quite messy and hard for me to reason about and
extend, this new sink API is looking to be less confusing. I hope it
stays that way as more features are added.
2024-07-14 20:17:18 +02:00
Yorhel
d60bcb2113 Copyright: remove year & use alias
Tired of bumping files every year and slowly moving stuff to my alias.
2024-04-20 15:49:51 +02:00
Eric Joldasov
946d2a0316
src: update to standard library changes in Zig 0.12.0-dev.3385+3a836b480
* rearrangment of entries in `std.os` and `std.c`, `std.posix`
 finally extracted in https://github.com/ziglang/zig/pull/19354 .

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-03-20 23:06:20 +05:00
Eric Joldasov
8ce5bae872
src/ui.zig: update to language changes in Zig 0.12.0-dev.2150+63de8a598
* `name` field of std.builtin.Type struct changed type from `[]const u8` to `[:0]const u8`:
 https://github.com/ziglang/zig/pull/18470 .

 * New `'comptime var' is redundant in comptime scope` error
 introduced in https://github.com/ziglang/zig/pull/18242 .

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-03-20 23:06:14 +05:00
Eric Joldasov
1fa40ae498
src/ui.zig: update to language changes in Zig 0.12.0-dev.1808+69195d0cd
* New `redundant inline keyword in comptime scope` error
 introduced in https://github.com/ziglang/zig/pull/18227 .

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-03-20 23:02:42 +05:00
Eric Joldasov
c83159f076
fix new "var never mutated" error on Zig 0.12.0-dev.1663+6b1a823b2
Fixes these errors (introduced in https://github.com/ziglang/zig/pull/18017
and 6b1a823b2b ):

```
src/main.zig:290:13: error: local variable is never mutated
        var line_ = line_fbs.getWritten();
            ^~~~~
src/main.zig:290:13: note: consider using 'const'
src/main.zig:450:17: error: local variable is never mutated
            var path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable;
                ^~~~
src/main.zig:450:17: note: consider using 'const'

...
```

Will be included in future Zig 0.12, this fix is backward compatible:
ncdu still builds and runs fine on Zig 0.11.0.

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-11-20 14:45:02 +06:00
Eric Joldasov
115de253a8
replace ncurses_refs.c workaround with pure Zig workaround
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-11-19 14:37:52 +06:00
Eric Joldasov
ab6dc5be75
Update to Zig 0.11.0
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-08-04 14:41:49 +06:00
Yorhel
ec233ff33a Version 2.2.2 + copyright year bump 2023-01-19 08:00:27 +01:00
Yorhel
1452b91032 Some fixes for building with Zig stage2
Building is currently broken on packed struct alignment issues. :/
2022-10-26 13:34:27 +02:00
Yorhel
f7e774ee6e Fixes for stdlib changes 2022-10-26 13:34:06 +02:00
Yorhel
0d16b9f33e Fix colors on FreeBSD (and MacOS?) again
Broken in 1548f9276f because I'm an idiot.

Probably also fixes #210, but I don't have a Mac to test.
2022-10-23 09:16:05 +02:00
Yorhel
058b26bf9a Set default attributes to the whole window during curses init
Based on #204.
2022-06-15 06:17:38 +02:00
Yorhel
0fc14173f2 Fix panic when shortening strings with unicode variation selectors
Fixes #199.
That's not to say it handles variation selectors or combining marks
well, though. This is kind of messy. :(
2022-04-16 20:05:43 +02:00
Yorhel
01f1e9188a Version 2.0.1 + copyright year bump 2022-01-01 16:01:47 +01:00
Yorhel
2b23951e4f ui.zig: Really fix import of wcwidth() this time
Fixes #183
2021-12-26 11:02:42 +01:00
Yorhel
a6f5678088 ui.zig: Fix typo in setting _XOPEN_SOURCE feature test macro 2021-12-21 15:20:07 +01:00
Yorhel
6a68cd9b89 Fixes and updates for Zig 0.9.0 2021-12-21 10:34:44 +01:00
Yorhel
f448e8ea67 Add dark-bg color scheme + enable colors by default if !NO_COLOR
Same thing as commit 376aad0d35 in the C
version.
2021-08-16 16:33:23 +02:00
Yorhel
c8636b8982 Add REUSE-compliant copyright headers 2021-07-18 11:50:50 +02:00
Yorhel
5a196125dc Use @errorName() fallback in ui.errorString()
Sticking to "compiletime-known" error types will essentially just bring
in *every* possible error anyway, so might as well take advantage of
@errorName.
2021-07-16 18:35:21 +02:00
Yorhel
3a21dea2cd Implement file deletion + a bunch of bug fixes 2021-07-16 16:18:13 +02:00
Yorhel
448fa9e7a6 Implement shell spawning 2021-07-14 11:24:19 +02:00
Yorhel
6c2ab5001c Implement directory refresh
This complicated the scan code more than I had anticipated and has a
few inherent bugs with respect to calculating shared hardlink sizes.

Still, the merge approach avoids creating a full copy of the subtree, so
that's another memory usage related win compared to the C version.
On the other hand, it does leak memory if nodes can't be reused.

Not quite as well tested as I should have, so I'm sure there's bugs.
2021-07-13 13:45:08 +02:00
Yorhel
ff3e3bccc6 Add link path listing to information window
Two differences compared to the C version:
- You can now select individual paths in the listing, pressing enter
  will open the selected path in the browser window.
- Creating this listing is much slower and requires, in the worst case,
  a full traversal through the in-memory tree. I've tested this without
  the same-dev and shared-parent optimizations (i.e. worst case) on an
  import with 30M files and performance was still quite acceptable - the
  listing completed in a second - so I didn't bother adding a loading
  indicator. On slower systems and even larger trees this may be a
  little annoying, though.

(also, calling nonl() apparently breaks detection of the return key,
neither \n nor KEY_ENTER are emitted for some reason)
2021-07-06 18:33:31 +02:00
Yorhel
618972b82b Add item info window
Doesn't display the item's path anymore (seems rather redundant) but
adds a few more other fields.
2021-06-11 13:12:00 +02:00
Yorhel
d910ed8b9f Add workaround for Zig bug on FreeBSD
The good news is: apart from this little thing, everything seems to just
work(tm) on FreeBSD. Think I had more trouble with C because of minor
header file differences.
2021-06-07 11:21:55 +02:00
Yorhel
59ef5fd27b Improved error reporting + minor cleanup 2021-05-29 19:22:00 +02:00
Yorhel
2390308883 Handle allocation failures
In a similar way to the C version of ncdu: by wrapping malloc(). It's
simpler to handle allocation failures at the source to allow for easy
retries, pushing the retries up the stack will complicate code somewhat
more. Likewise, this is a best-effort approach to handling OOM,
allocation failures in ncurses aren't handled and display glitches may
occur when we get an OOM inside a drawing function.

This is a somewhat un-Zig-like way of handling errors and adds
scary-looking 'catch unreachable's all over the code, but that's okay.
2021-05-29 13:18:23 +02:00
Yorhel
c077c5bed5 Implement JSON file import
Performance is looking great, but the code is rather ugly and
potentially buggy. Also doesn't handle hard links without an "nlink"
field yet.

Error handling of the import code is different from what I've been doing
until now. That's intentional, I'll change error handling of other
pieces to call ui.die() directly rather than propagating error enums.
The approach is less testable but conceptually simpler, it's perfectly
fine for a tiny application like ncdu.
2021-05-29 10:54:45 +02:00
Yorhel
9474aa4329 Only keep total_items + Zig test update + pointless churn 2021-05-24 11:02:26 +02:00
Yorhel
7b3ebf9241 Implement all existing browsing display options + some fixes
I plan to add more display options, but ran out of keys to bind.
Probably going for a quick-select menu thingy so that we can keep the
old key bindings for people accustomed to it.

The graph width algorithm is slightly different, but I think this one's
a minor improvement.
2021-05-23 17:34:40 +02:00
Yorhel
231ab1037d Implement export to file
The exported file format is fully compatible with ncdu 1.x, but has a
few minor differences. I've backported these changes in
ca51d4ed1a
2021-05-12 11:32:52 +02:00
Yorhel
b0e81ea4e9 Implement scanning UI (-0,-1,-2) 2021-05-09 20:59:09 +02:00
Yorhel
d1eb7ba007 Initial keyboard input handling + item&sort selection 2021-05-07 12:01:00 +02:00
Yorhel
27cb599e22 More UI stuff + shave off 16 bytes from model.Dir
I initially wanted to keep a directory's block count and size as a
separate field so that exporting an in-memory tree to a JSON dump would
be easier to do, but that doesn't seem like a common operation to
optimize for. We'll probably need the algorithms to subtract sub-items
from directory counts anyway, so such an export can still be
implemented, albeit slower.
2021-05-06 19:20:55 +02:00
Yorhel
a54c10bffb More UI stuff: nice string handling/shortening + Zig bug workaround
libc locale-dependent APIs are pure madness, but I can't avoid them as
long as I use ncurses. libtickit seems like a much saner alternative (at
first glance), but no popular application seems to use it. :(
2021-05-05 08:03:27 +02:00
Yorhel
a28a0788c3 Implement --exclude-kernfs and --exclude-pattern
Eaiser to implement now that we're linking against libc.

But exclude pattern matching is extremely slow, so that should really be
rewritten with a custom fnmatch implementation. It's exactly as slow as
in ncdu 1.x as well, I'm surprised nobody's complained about it yet.
And while I'm at it, supporting .gitignore-style patterns would be
pretty neat, too.
2021-05-03 14:41:50 +02:00
Yorhel
826c2fc067 Link to ncurses + some rudimentary TUI frameworky stuff
I tried playing with zbox (pure Zig termbox-like lib) for a bit, but I
don't think I want to have to deal with the terminal support issues that
will inevitably come with it. I already stumbled upon one myself: it
doesn't properly put the terminal in a sensible state after cleanup in
tmux. As much as I dislike ncurses, it /is/ ubiquitous and tends to kind
of work.
2021-05-03 08:01:18 +02:00