Skip to content

Commit 6e3d13e

Browse files
feat(code): add ncdu v2.3 source code
https://dev.yorhel.nl/ncdu/changes2
1 parent fd4c884 commit 6e3d13e

File tree

16 files changed

+5917
-1
lines changed

16 files changed

+5917
-1
lines changed

ChangeLog

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
2+
# SPDX-License-Identifier: MIT
3+
4+
2.3 - 2023-08-04
5+
- Now requires Zig 0.11
6+
- Add --(enable|disable)-natsort options
7+
- Add indicator to apparent size/disk usage selection in the footer
8+
- Fix build on armv7l (hopefully)
9+
- Minor build system additions
10+
11+
2.2.2 - 2023-01-19
12+
- Now requires Zig 0.10 or 0.10.1
13+
- That's it, pretty much.
14+
15+
2.2.1 - 2022-10-25
16+
- Still requires Zig 0.9.0 or 0.9.1
17+
- Fix bug with 'dark' and 'off' color themes on FreeBSD and MacOS
18+
19+
2.2 - 2022-10-17
20+
- Still requires Zig 0.9.0 or 0.9.1
21+
- (breaking) Wildcards in exclude patterns don't cross directory boundary anymore
22+
- Improve exclude pattern matching performance
23+
- Set full background in default dark-bg color scheme
24+
- Fix broken JSON export when a filename contains control characters below 0x10
25+
26+
2.1.2 - 2022-04-28
27+
- Still requires Zig 0.9.0 or 0.9.1
28+
- Fix possible crash on shortening file names with unicode variation
29+
selectors or combining marks
30+
31+
2.1.1 - 2022-03-25
32+
- Still requires Zig 0.9.0 or 0.9.1
33+
- Fix potential crash when refreshing
34+
- Fix typo in --graph-style=eighth-block
35+
- Revert default --graph-style to hash characters
36+
37+
2.1 - 2022-02-07
38+
- Still requires Zig 0.9.0
39+
- Use natural sort order when sorting by file name
40+
- Use Unicode box drawing characters for the file size bar
41+
- Add --graph-style option to change drawing style for the file size bar
42+
- Fix early exit if a configuration directory does not exist
43+
- Fix display glitch for long file names
44+
- Fix display glitch with drawing unique/shared size column
45+
46+
2.0.1 - 2022-01-01
47+
- Still requires Zig 0.9.0
48+
- Fix build failure to find 'wcwidth' on some systems
49+
- Add ZIG_FLAGS option to Makefile
50+
51+
2.0 - 2021-12-21
52+
- Requires Zig 0.9.0
53+
- That's the only change.
54+
55+
2.0-beta3 - 2021-11-09
56+
- Requires Zig 0.8 or 0.8.1
57+
- Add lots of new CLI flags to configure ncdu
58+
- Add configuration file support
59+
- Add 'dark-bg' color scheme and use that by default
60+
- Fix not enabling -x by default
61+
- Fix export feature
62+
- Fix import of "special" dirs and files
63+
- Fix double-slash display in file browser
64+
65+
2.0-beta2 - 2021-07-31
66+
- Requires Zig 0.8
67+
- Significantly reduce memory usage for hard links
68+
- Slightly increase memory usage for directory entries
69+
- Fix reporting of fatal errors in the -0 and -1 scanning UIs
70+
71+
2.0-beta1 - 2021-07-22
72+
- Full release announcement: https://dev.yorhel.nl/doc/ncdu2
73+
- Requires Zig 0.8
74+
- Features and UI based on ncdu 1.16
75+
- Lower memory use in most scenarios (except with many hard links)
76+
- Improved performance of hard link counting
77+
- Extra column for shared/unique directory sizes

LICENSES/MIT.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) <year> <copyright holders>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
2+
# SPDX-License-Identifier: MIT
3+
4+
# Optional semi-standard Makefile with some handy tools.
5+
# Ncdu itself can be built with just the zig build system.
6+
7+
ZIG ?= zig
8+
9+
PREFIX ?= /usr/local
10+
BINDIR ?= ${PREFIX}/bin
11+
MANDIR ?= ${PREFIX}/share/man/man1
12+
ZIG_FLAGS ?= -Doptimize=ReleaseFast
13+
14+
NCDU_VERSION=$(shell grep 'program_version = "' src/main.zig | sed -e 's/^.*"\(.\+\)".*$$/\1/')
15+
16+
.PHONY: build
17+
build: release doc
18+
19+
release:
20+
$(ZIG) build ${ZIG_FLAGS}
21+
22+
debug:
23+
$(ZIG) build
24+
25+
clean:
26+
rm -rf zig-cache zig-out
27+
28+
distclean: clean
29+
rm -f ncdu.1
30+
31+
doc: ncdu.1
32+
33+
ncdu.1: ncdu.pod src/main.zig
34+
pod2man --center "ncdu manual" --release "ncdu-${NCDU_VERSION}" ncdu.pod >ncdu.1
35+
36+
install: install-bin install-doc
37+
38+
install-bin: release
39+
mkdir -p ${BINDIR}
40+
install -m0755 zig-out/bin/ncdu ${BINDIR}/
41+
42+
install-doc: doc
43+
mkdir -p ${MANDIR}
44+
install -m0644 ncdu.1 ${MANDIR}/
45+
46+
uninstall: uninstall-bin uninstall-doc
47+
48+
# XXX: Ideally, these would also remove the directories created by 'install' if they are empty.
49+
uninstall-bin:
50+
rm -f ${BINDIR}/ncdu
51+
52+
uninstall-doc:
53+
rm -f ${MANDIR}/ncdu.1
54+
55+
dist: doc
56+
rm -f ncdu-${NCDU_VERSION}.tar.gz
57+
mkdir ncdu-${NCDU_VERSION}
58+
for f in ncdu.1 `git ls-files | grep -v ^\.gitignore`; do mkdir -p ncdu-${NCDU_VERSION}/`dirname $$f`; ln -s "`pwd`/$$f" ncdu-${NCDU_VERSION}/$$f; done
59+
tar -cophzf ncdu-${NCDU_VERSION}.tar.gz --sort=name ncdu-${NCDU_VERSION}
60+
rm -rf ncdu-${NCDU_VERSION}
61+
62+
63+
# ASSUMPTION: the ncurses source tree has been extracted into ncurses/
64+
static-%.tar.gz:
65+
mkdir -p static-$*/nc static-$*/inst/pkg
66+
cd static-$*/nc && ../../ncurses/configure --prefix="`pwd`/../inst"\
67+
--with-pkg-config-libdir="`pwd`/../inst/pkg"\
68+
--without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs\
69+
--without-tests --enable-pc-files --without-pkg-config --without-shared --without-debug\
70+
--without-gpm --without-sysmouse --enable-widec --with-default-terminfo-dir=/usr/share/terminfo\
71+
--with-terminfo-dirs=/usr/share/terminfo:/lib/terminfo:/usr/local/share/terminfo\
72+
--with-fallbacks="screen linux vt100 xterm xterm-256color" --host=$*\
73+
CC="${ZIG} cc --target=$*"\
74+
LD="${ZIG} cc --target=$*"\
75+
AR="${ZIG} ar" RANLIB="${ZIG} ranlib"\
76+
CPPFLAGS=-D_GNU_SOURCE && make && make install.libs
77+
@# zig-build - cleaner approach but doesn't work, results in a dynamically linked binary.
78+
@#cd static-$* && PKG_CONFIG_LIBDIR="`pwd`/inst/pkg" zig build -Dtarget=$*
79+
@# --build-file ../build.zig --search-prefix inst/ --cache-dir zig -Drelease-fast=true
80+
@# Alternative approach, bypassing zig-build
81+
cd static-$* && ${ZIG} build-exe -target $*\
82+
-Iinst/include -Iinst/include/ncursesw -lc inst/lib/libncursesw.a\
83+
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig ../src/ncurses_refs.c
84+
cd static-$* && mv main ncdu && tar -czf ../static-$*.tar.gz ncdu
85+
rm -rf static-$*
86+
87+
static-linux-x86_64: static-x86_64-linux-musl.tar.gz
88+
mv $< ncdu-${NCDU_VERSION}-linux-x86_64.tar.gz
89+
90+
static-linux-x86: static-x86-linux-musl.tar.gz
91+
mv $< ncdu-${NCDU_VERSION}-linux-x86.tar.gz
92+
93+
static-linux-aarch64: static-aarch64-linux-musl.tar.gz
94+
mv $< ncdu-${NCDU_VERSION}-linux-aarch64.tar.gz
95+
96+
static-linux-arm: static-arm-linux-musleabi.tar.gz
97+
mv $< ncdu-${NCDU_VERSION}-linux-arm.tar.gz
98+
99+
static:\
100+
static-linux-x86_64 \
101+
static-linux-x86 \
102+
static-linux-aarch64 \
103+
static-linux-arm

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# ncdu-zig
1+
<!--
2+
SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
6+
# ncdu-zig
7+
8+
## Description
9+
10+
Ncdu is a disk usage analyzer with an ncurses interface. It is designed to find
11+
space hogs on a remote server where you don't have an entire graphical setup
12+
available, but it is a useful tool even on regular desktop systems. Ncdu aims
13+
to be fast, simple and easy to use, and should be able to run in any minimal
14+
POSIX-like environment with ncurses installed.
15+
16+
See the [ncdu 2 release announcement](https://dev.yorhel.nl/doc/ncdu2) for
17+
information about the differences between this Zig implementation (2.x) and the
18+
C version (1.x).
19+
20+
## Requirements
21+
22+
- Zig 0.11.0
23+
- Some sort of POSIX-like OS
24+
- ncurses libraries and header files
25+
26+
## Install
27+
28+
You can use the Zig build system if you're familiar with that.
29+
30+
There's also a handy Makefile that supports the typical targets, e.g.:
31+
32+
```
33+
make
34+
sudo make install PREFIX=/usr
35+
```

build.zig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-FileCopyrightText: 2021-2023 Yoran Heling <[email protected]>
2+
// SPDX-License-Identifier: MIT
3+
4+
const std = @import("std");
5+
6+
pub fn build(b: *std.Build) void {
7+
const target = b.standardTargetOptions(.{});
8+
const optimize = b.standardOptimizeOption(.{});
9+
10+
const pie = b.option(bool, "pie", "Build with PIE support (by default false)") orelse false;
11+
12+
const exe = b.addExecutable(.{
13+
.name = "ncdu",
14+
.root_source_file = .{ .path = "src/main.zig" },
15+
.target = target,
16+
.optimize = optimize,
17+
});
18+
19+
// https://github.com/ziglang/zig/blob/b52be973dfb7d1408218b8e75800a2da3dc69108/build.zig#L551-L554
20+
if (exe.target.isDarwin()) {
21+
// useful for package maintainers
22+
exe.headerpad_max_install_names = true;
23+
}
24+
linkNcurses(exe);
25+
exe.pie = pie;
26+
b.installArtifact(exe);
27+
28+
const run_cmd = b.addRunArtifact(exe);
29+
run_cmd.step.dependOn(b.getInstallStep());
30+
if (b.args) |args| {
31+
run_cmd.addArgs(args);
32+
}
33+
34+
const run_step = b.step("run", "Run the app");
35+
run_step.dependOn(&run_cmd.step);
36+
37+
const unit_tests = b.addTest(.{
38+
.root_source_file = .{ .path = "src/main.zig" },
39+
.target = target,
40+
.optimize = optimize,
41+
});
42+
linkNcurses(unit_tests);
43+
unit_tests.pie = pie;
44+
45+
const run_unit_tests = b.addRunArtifact(unit_tests);
46+
47+
const test_step = b.step("test", "Run unit tests");
48+
test_step.dependOn(&run_unit_tests.step);
49+
}
50+
51+
pub fn linkNcurses(compile_step: *std.Build.CompileStep) void {
52+
compile_step.linkSystemLibrary("ncursesw");
53+
compile_step.linkLibC();
54+
compile_step.addCSourceFile(.{ .file = .{ .path = "src/ncurses_refs.c" }, .flags = &.{} });
55+
}

0 commit comments

Comments
 (0)