mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
replace ncurses_refs.c workaround with pure Zig workaround
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This commit is contained in:
parent
a71bc6eca5
commit
115de253a8
4 changed files with 11 additions and 46 deletions
2
Makefile
2
Makefile
|
|
@ -80,7 +80,7 @@ static-%.tar.gz:
|
||||||
@# Alternative approach, bypassing zig-build
|
@# Alternative approach, bypassing zig-build
|
||||||
cd static-$* && ${ZIG} build-exe -target $*\
|
cd static-$* && ${ZIG} build-exe -target $*\
|
||||||
-Iinst/include -Iinst/include/ncursesw -lc inst/lib/libncursesw.a\
|
-Iinst/include -Iinst/include/ncursesw -lc inst/lib/libncursesw.a\
|
||||||
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig ../src/ncurses_refs.c
|
--cache-dir zig-cache -static -fstrip -O ReleaseFast ../src/main.zig
|
||||||
cd static-$* && mv main ncdu && tar -czf ../static-$*.tar.gz ncdu
|
cd static-$* && mv main ncdu && tar -czf ../static-$*.tar.gz ncdu
|
||||||
rm -rf static-$*
|
rm -rf static-$*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,4 @@ pub fn build(b: *std.Build) void {
|
||||||
pub fn linkNcurses(compile_step: *std.Build.CompileStep) void {
|
pub fn linkNcurses(compile_step: *std.Build.CompileStep) void {
|
||||||
compile_step.linkSystemLibrary("ncursesw");
|
compile_step.linkSystemLibrary("ncursesw");
|
||||||
compile_step.linkLibC();
|
compile_step.linkLibC();
|
||||||
compile_step.addCSourceFile(.{ .file = .{ .path = "src/ncurses_refs.c" }, .flags = &.{} });
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* SPDX-FileCopyrightText: 2021-2023 Yoran Heling <projects@yorhel.nl>
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <curses.h>
|
|
||||||
|
|
||||||
/* Zig @cImport() has problems with the ACS_* macros. Two, in fact:
|
|
||||||
*
|
|
||||||
* 1. Naively using the ACS_* macros results in:
|
|
||||||
*
|
|
||||||
* error: cannot store runtime value in compile time variable
|
|
||||||
* return acs_map[NCURSES_CAST(u8, c)];
|
|
||||||
* ^
|
|
||||||
* That error doesn't make much sense to me, but it might be
|
|
||||||
* related to https://github.com/ziglang/zig/issues/5344?
|
|
||||||
*
|
|
||||||
* 2. The 'acs_map' extern variable isn't being linked correctly?
|
|
||||||
* Haven't investigated this one deeply enough yet, but attempting
|
|
||||||
* to dereference acs_map from within Zig leads to a segfault;
|
|
||||||
* its pointer value doesn't make any sense.
|
|
||||||
*/
|
|
||||||
chtype ncdu_acs_ulcorner() { return ACS_ULCORNER; }
|
|
||||||
chtype ncdu_acs_llcorner() { return ACS_LLCORNER; }
|
|
||||||
chtype ncdu_acs_urcorner() { return ACS_URCORNER; }
|
|
||||||
chtype ncdu_acs_lrcorner() { return ACS_LRCORNER; }
|
|
||||||
chtype ncdu_acs_hline() { return ACS_VLINE ; }
|
|
||||||
chtype ncdu_acs_vline() { return ACS_HLINE ; }
|
|
||||||
27
src/ui.zig
27
src/ui.zig
|
|
@ -192,14 +192,6 @@ test "shorten" {
|
||||||
try t("ą́ą́ą́ą́ą́ą́", 5, "ą́...̨́ą́"); // Combining marks, similarly bad.
|
try t("ą́ą́ą́ą́ą́ą́", 5, "ą́...̨́ą́"); // Combining marks, similarly bad.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ncurses_refs.c
|
|
||||||
extern fn ncdu_acs_ulcorner() c.chtype;
|
|
||||||
extern fn ncdu_acs_llcorner() c.chtype;
|
|
||||||
extern fn ncdu_acs_urcorner() c.chtype;
|
|
||||||
extern fn ncdu_acs_lrcorner() c.chtype;
|
|
||||||
extern fn ncdu_acs_hline() c.chtype;
|
|
||||||
extern fn ncdu_acs_vline() c.chtype;
|
|
||||||
|
|
||||||
const StyleAttr = struct { fg: i16, bg: i16, attr: u32 };
|
const StyleAttr = struct { fg: i16, bg: i16, attr: u32 };
|
||||||
const StyleDef = struct {
|
const StyleDef = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
|
|
@ -535,20 +527,21 @@ pub const Box = struct {
|
||||||
style(.default);
|
style(.default);
|
||||||
if (width < 6 or height < 3) return s;
|
if (width < 6 or height < 3) return s;
|
||||||
|
|
||||||
const ulcorner = ncdu_acs_ulcorner();
|
const acs_map = @extern(*[128]c.chtype, .{ .name = "acs_map" });
|
||||||
const llcorner = ncdu_acs_llcorner();
|
const ulcorner = acs_map['l'];
|
||||||
const urcorner = ncdu_acs_urcorner();
|
const llcorner = acs_map['m'];
|
||||||
const lrcorner = ncdu_acs_lrcorner();
|
const urcorner = acs_map['k'];
|
||||||
const acs_hline = ncdu_acs_hline();
|
const lrcorner = acs_map['j'];
|
||||||
const acs_vline = ncdu_acs_vline();
|
const acs_hline = acs_map['q'];
|
||||||
|
const acs_vline = acs_map['x'];
|
||||||
|
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < height) : (i += 1) {
|
while (i < height) : (i += 1) {
|
||||||
s.move(i, 0);
|
s.move(i, 0);
|
||||||
addch(if (i == 0) ulcorner else if (i == height-1) llcorner else acs_hline);
|
addch(if (i == 0) ulcorner else if (i == height-1) llcorner else acs_vline);
|
||||||
hline(if (i == 0 or i == height-1) acs_vline else ' ', width-2);
|
hline(if (i == 0 or i == height-1) acs_hline else ' ', width-2);
|
||||||
s.move(i, width-1);
|
s.move(i, width-1);
|
||||||
addch(if (i == 0) urcorner else if (i == height-1) lrcorner else acs_hline);
|
addch(if (i == 0) urcorner else if (i == height-1) lrcorner else acs_vline);
|
||||||
}
|
}
|
||||||
|
|
||||||
s.move(0, 3);
|
s.move(0, 3);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue