Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/zig master #61

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
version: "master"

- run: zig build
lint:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ target/
*.jpg
src/temp-main.zig
lima.yaml
.vscode
vaxis.log
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub fn build(b: *std.Build) void {
exe.root_module.addImport("vaxis", deps.vaxis.module("vaxis"));
exe.root_module.addImport("fzwatch", deps.fzwatch.module("fzwatch"));

exe.root_module.addAnonymousImport("metadata", .{ .root_source_file = b.path("build.zig.zon") });

if (useVendorMupdf) {
exe.step.dependOn(&mupdf_build_step.step);
addMupdfStatic(exe, b, location);
Expand Down
12 changes: 6 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.{
.name = "fancy-cat",
.version = "0.3.0",
.minimum_zig_version = "0.13.0",
.version = "0.4.0",
.minimum_zig_version = "0.14.0",
.dependencies = .{
.vaxis = .{
.url = "https://github.com/freref/libvaxis/archive/b2e2588e69bb227a16ec50bdb3bedabe48b7f58a.tar.gz",
.hash = "122098b207673eb55bf51b9981b7b7f5c852149dac82d49d70f07c7227323f8c0617",
.url = "https://github.com/freref/libvaxis/archive/d409f2f168192374aa7c625f61f6fe64fdb66818.zip",
.hash = "1220ef263fb9e45c2725b3781d342d746313751db9cdb61e7a737dbc72c94c184dc4",
},
.fzwatch = .{
.url = "https://github.com/freref/fzwatch/archive/refs/heads/master.tar.gz",
.hash = "1220a6181ec8374f37e49914204b98ff4cc326bfca1a46594364886fe962f998c9dd",
},
.fastb64z = .{
.url = "git+https://github.com/freref/fastb64z#3bfba44545042f00cc908890a652da00dc3d7670",
.hash = "12206695fbabe2c3f981ea79d97afe8d4fdb7790773a4153543c63ac7e0d11e564c7",
.url = "https://github.com/freref/fastb64z/archive/fa3f34a4528609a8778124641b080e90d93c357a.tar.gz",
.hash = "1220b5a0e9aa8d4c9b0e09c41ec3a58092888e7516c05cb78b74c9be77acaebab303",
},
},
.paths = .{
Expand Down
2 changes: 1 addition & 1 deletion src/Context.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub const Context = struct {
cache: Cache,
check_cache: bool,

pub fn init(allocator: std.mem.Allocator, args: [][]const u8) !Self {
pub fn init(allocator: std.mem.Allocator, args: [][:0]u8) !Self {
const path = args[1];
const initial_page = if (args.len == 3)
try std.fmt.parseInt(u16, args[2], 10)
Expand Down
5 changes: 3 additions & 2 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn init(allocator: std.mem.Allocator) !Self {
const home = try std.process.getEnvVarOwned(allocator, "HOME");
defer if (home.len != 1) allocator.free(home);

var config_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var config_path_buf: [std.fs.max_path_bytes]u8 = undefined;
const config_dir = try std.fmt.bufPrint(&config_path_buf, "{s}/.config/fancy-cat", .{home});

std.fs.makeDirAbsolute(config_dir) catch |err| {
Expand Down Expand Up @@ -150,6 +150,7 @@ fn parseKeyBinding(value: std.json.Value, allocator: std.mem.Allocator) !vaxis.K
}

if (vaxis.Key.name_map.get(key)) |codepoint| {
std.debug.print("key_value: {any}, key: {s}, codepoint: {any}\n", .{ key_value, key, codepoint });
return vaxis.Key{
.codepoint = codepoint,
.mods = modifiers,
Expand Down Expand Up @@ -241,7 +242,7 @@ fn parseStatusBar(value: std.json.Value, allocator: std.mem.Allocator) !StatusBa
const bg_rgb = bg.get("rgb").?.array;
const fg_rgb = fg.get("rgb").?.array;

const style = .{
const style: vaxis.Cell.Style = .{
.bg = .{ .rgb = .{
try std.json.innerParseFromValue(u8, allocator, bg_rgb.items[0], .{}),
try std.json.innerParseFromValue(u8, allocator, bg_rgb.items[1], .{}),
Expand Down
26 changes: 24 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
const std = @import("std");
const Context = @import("Context.zig").Context;

pub const FANCY_CAT_VERSION = "0.3.0";
// Types for build.zig.zon
// For now metadata is only used in main.zig, but can move it to types.zig if needed eleswhere
// This wont be necessary once https://github.com/ziglang/zig/pull/22907 is merged
const DependencyType = struct {
url: []const u8,
hash: []const u8,
};

const DependenciesType = struct {
vaxis: DependencyType,
fzwatch: DependencyType,
fastb64z: DependencyType,
};

const MetadataType = struct {
name: []const u8,
version: []const u8,
minimum_zig_version: []const u8,
dependencies: DependenciesType,
paths: []const []const u8,
};

const metadata: MetadataType = @import("metadata");

pub fn main() !void {
const args = try std.process.argsAlloc(std.heap.page_allocator);
defer std.process.argsFree(std.heap.page_allocator, args);

if (args.len == 2 and (std.mem.eql(u8, args[1], "--version") or std.mem.eql(u8, args[1], "-v"))) {
const stdout = std.io.getStdOut().writer();
try stdout.print("fancy-cat version {s}\n", .{FANCY_CAT_VERSION});
try stdout.print("fancy-cat version {s}\n", .{metadata.version});
return;
}

Expand Down