Skip to content

Instantly share code, notes, and snippets.

@Dubhead
Created November 29, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dubhead/97af0640b0562b357bc747c835b0c074 to your computer and use it in GitHub Desktop.
Save Dubhead/97af0640b0562b357bc747c835b0c074 to your computer and use it in GitHub Desktop.
Hello world with Zig and notcurses
// Hello world with Zig and notcurses
//
// Fedora 35 Worstation
// Zig 0.9.0-dev.1798+0f63f3eeb
// notcurses 2.4.9
// (1) Install notcurses dev library.
//
// $ sudo dnf install notcurses-devel
//
// (2) $ zig init-exe
//
// (3) Add these lines to build.zig after `exe.install();`:
//
// exe.addIncludeDir("/usr/include");
// exe.linkLibC();
// exe.linkSystemLibrary("notcurses-core");
//
// (4) Edit main.zig like this file.
//
// (5) $ zig build run
const nc = @cImport({
@cInclude("notcurses/notcurses.h");
});
pub fn main() anyerror!void {
var ncopt: nc.notcurses_options = undefined;
ncopt.termtype = @intToPtr([*c]const u8, 0); // 0 == Use envvar TERM
ncopt.loglevel = nc.NCLOGLEVEL_SILENT;
ncopt.margin_t = 0;
ncopt.margin_r = 0;
ncopt.margin_b = 0;
ncopt.margin_l = 0;
ncopt.flags = 0; // `nc.NCOPTION_SUPPRESS_BANNERS` to suppress stats
const notcurses = nc.notcurses_core_init(&ncopt, nc.stdout);
const plane = nc.notcurses_stdplane(notcurses);
_ = nc.ncplane_cursor_move_yx(plane, 2, 2);
_ = nc.ncplane_putstr(plane, "Hello world");
_ = nc.ncplane_cursor_move_yx(plane, 4, 2);
_ = nc.ncplane_putstr(plane, "Hit any key to quit.");
_ = nc.notcurses_render(notcurses);
_ = nc.notcurses_getc_blocking(notcurses, @intToPtr([*c]nc.ncinput, 0));
_ = nc.notcurses_stop(notcurses);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment