Compare commits

..
25 Commits
Author SHA1 Message Date
Nathan McRae aa766b44fe Add TODOs to readme 2023-06-21 21:18:55 -07:00
nathanmcrae 27673079fa Clean up 2023-06-21 20:39:12 -07:00
nathanmcrae 0d4d3e9212 Add buffer between columns 2023-06-21 20:38:35 -07:00
nathanmcrae b0698395c0 Update readme 2023-06-21 20:38:13 -07:00
nathanmcrae 38ae10f9c6 Only display filename, not full path 2023-06-21 20:18:10 -07:00
nathanmcrae d3951dbc1d Add zig-out to .gitignore 2023-06-21 20:03:18 -07:00
nathanmcrae 32c0b9bb5c Open directories of files
You can pass files / dirs as arguments an they will be opened. The
directories will be searched for text files (as identified by libmagic)
and those text files will be displayed too.
2023-06-20 22:32:04 -07:00
nathanmcrae 0da13751d5 Display multiple files 2023-06-19 23:09:23 -07:00
nathanmcrae aade06e600 Add docmap struct
We want to have an array of docmaps, one for each file and be able to
iterate through them. That way the layout can be done in a single
function.
2023-06-19 22:42:26 -07:00
nathanmcrae d3e47ee184 Write file name inline 2023-06-18 00:23:56 -07:00
nathanmcrae 8a16eff9ba Finish text render test 2023-06-16 21:01:59 -07:00
nathanmcrae deb02fa359 Add SDL TTF for text rendering 2023-06-10 23:11:44 -07:00
nathanmcrae 80de6db167 Added red mark at end of long line 2023-06-10 22:13:40 -07:00
nathanmcrae 757a401eee Rename bin to docmap 2023-06-10 21:34:49 -07:00
nathanmcrae 727eeb8710 zig fmt 2023-06-10 21:34:42 -07:00
nathanmcrae b61717cf21 Added columns 2023-06-04 15:19:51 -07:00
nathanmcrae b695ee0bf7 First pass at a document map viewer 2023-06-04 14:46:48 -07:00
Andrew Kelley 0e9e56a8f1 update to latest zig 2022-10-25 15:26:34 -07:00
Andrew Kelley 09ef4b6106 update to latest zig 2021-03-29 12:18:07 -07:00
Andrew Kelley ccb18ace37 update to latest zig 2018-07-04 12:06:20 -04:00
Andrew Kelley a4c4a42e0a update to latest zig 2018-06-09 23:13:57 -04:00
Andrew Kelley 2dd7e5b51e zig has extern unions now 2018-03-27 18:03:03 -04:00
Andrew Kelley a2a3fc57d1 update to latest zig 2018-03-27 17:57:07 -04:00
Andrew Kelley 7e4872a02c don't free the rwop twice 2017-10-25 23:42:16 -04:00
Andrew Kelley 4ab4e4f58b initial version 2017-10-25 23:30:19 -04:00
3 changed files with 43 additions and 32 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
/.zig-cache/ /zig-cache/
/zig-out/ /zig-out/
+12 -14
View File
@@ -1,21 +1,19 @@
const std = @import("std"); const Builder = @import("std").build.Builder;
pub fn build(b: *std.Build) void { pub fn build(b: *Builder) void {
const exe = b.addExecutable(.{ const mode = b.standardReleaseOptions();
.name = "docmap", const exe = b.addExecutable("docmap", "src/main.zig");
.root_source_file = b.path("src/main.zig"),
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
});
exe.addIncludePath(.{ .cwd_relative = "C:/Users/nathanm/Downloads/SDL2-devel-2.26.5-mingw/SDL2-2.26.5/x86_64-w64-mingw32/include/SDL2" });
exe.addIncludePath(.{ .cwd_relative = "C:/Users/nathanm/Downloads/SDL2_ttf-devel-2.24.0-mingw/SDL2_ttf-2.24.0/x86_64-w64-mingw32/include/SDL2" });
exe.addObjectFile(.{ .cwd_relative = "C:/Users/nathanm/Downloads/SDL2-devel-2.30.11-mingw/SDL2-2.30.11/x86_64-w64-mingw32/bin/SDL2.dll" });
exe.addObjectFile(.{ .cwd_relative = "C:/Users/nathanm/Downloads/SDL2_ttf-devel-2.24.0-mingw/SDL2_ttf-2.24.0/x86_64-w64-mingw32/bin/SDL2_ttf.dll" });
exe.setBuildMode(mode);
exe.linkSystemLibrary("SDL2");
exe.linkSystemLibrary("SDL2_TTF");
exe.linkSystemLibrary("magic");
exe.linkSystemLibrary("c"); exe.linkSystemLibrary("c");
b.default_step.dependOn(&exe.step); b.default_step.dependOn(&exe.step);
b.installArtifact(exe); b.installArtifact(exe);
const run = b.step("run", "Run the demo");
const run_cmd = exe.run();
run.dependOn(&run_cmd.step);
} }
+28 -15
View File
@@ -25,12 +25,18 @@ const FileDocMap = struct {
pub fn main() !void { pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer { defer {
const deinit_status = gpa.deinit(); if (gpa.deinit()) {
if (deinit_status == .leak) {
std.debug.print("Allocator leak\n", .{}); std.debug.print("Allocator leak\n", .{});
} }
} }
var magic = m.magic_open(m.MAGIC_MIME | m.MAGIC_CHECK);
const load_result = m.magic_load(magic, null);
if (load_result != 0) {
std.debug.print("Unable to initialize magic: {d}", .{load_result});
return error.MagicInitializationFailed;
}
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const args = try std.process.argsAlloc(allocator); const args = try std.process.argsAlloc(allocator);
@@ -46,7 +52,7 @@ pub fn main() !void {
} }
defer c.SDL_Quit(); defer c.SDL_Quit();
const screen = c.SDL_CreateWindow("Document Map Viewer", c.SDL_WINDOWPOS_UNDEFINED, c.SDL_WINDOWPOS_UNDEFINED, window_width, window_height, c.SDL_WINDOW_OPENGL | c.SDL_WINDOW_RESIZABLE) orelse const screen = c.SDL_CreateWindow("Document Map Viewer", c.SDL_WINDOWPOS_UNDEFINED, c.SDL_WINDOWPOS_UNDEFINED, window_width, window_height, c.SDL_WINDOW_OPENGL) orelse
{ {
c.SDL_Log("Unable to create window: %s", c.SDL_GetError()); c.SDL_Log("Unable to create window: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
@@ -75,7 +81,12 @@ pub fn main() !void {
} }
defer c.TTF_Quit(); defer c.TTF_Quit();
const text_color: c.SDL_Color = c.SDL_Color{ .r = 0, .g = 0, .b = 0, .a = 255 }; const text_color: c.SDL_Color = c.SDL_Color{
.r = 0,
.g = 0,
.b = 0,
.a = 255
};
// TODO: can we embed this file? // TODO: can we embed this file?
const font: ?*c.TTF_Font = c.TTF_OpenFont("FreeSans.ttf", 12); const font: ?*c.TTF_Font = c.TTF_OpenFont("FreeSans.ttf", 12);
@@ -96,19 +107,21 @@ pub fn main() !void {
var args_i: usize = 1; var args_i: usize = 1;
while (args_i < args.len) : (args_i += 1) { while (args_i < args.len) : (args_i += 1) {
const arg = args[args_i]; const arg = args[args_i];
if (std.fs.cwd().openDir(arg, .{ .iterate = true })) |iter_dir| { if (std.fs.cwd().openIterableDir(arg, .{})) |iter_dir| {
std.debug.print("searching dir for files: '{s}'\n", .{arg}); std.debug.print("searching dir for files: '{s}'\n", .{arg});
var iter = iter_dir.iterate(); var iter = iter_dir.iterate();
while (try iter.next()) |entry| { while (try iter.next()) |entry| {
if (entry.kind == .file) { if (entry.kind == .File) {
const entry_path = try std.fmt.allocPrint(allocator, "{s}{c}{s}\x00", .{ const entry_path = try std.fmt.allocPrint(allocator, "{s}{c}{s}\x00", .{
arg, arg,
std.fs.path.sep, std.fs.path.sep,
entry.name, entry.name,
}); });
if (std.mem.eql(u8, entry.name[(entry.name.len - 4)..(entry.name.len)], ".org")) { const magic_result = m.magic_file(magic, @ptrCast([*c]const u8, entry_path));
try file_paths.append(entry_path[0..(entry_path.len)]); std.debug.print("'{s}': {s}\n", .{ entry.name, magic_result });
if (std.mem.eql(u8, magic_result[0..5], "text/")) {
try file_paths.append(entry_path[0..(entry_path.len - 1)]);
} else { } else {
allocator.free(entry_path); allocator.free(entry_path);
} }
@@ -118,8 +131,8 @@ pub fn main() !void {
if (std.fs.cwd().openFile(arg, .{})) |file| { if (std.fs.cwd().openFile(arg, .{})) |file| {
file.close(); file.close();
std.debug.print("Will do docmap for: '{s}'\n", .{arg}); std.debug.print("Will do docmap for: '{s}'\n", .{arg});
const path = try allocator.alloc(u8, arg.len); var path = try allocator.alloc(u8, arg.len);
@memcpy(path, arg); std.mem.copy(u8, path, arg);
try file_paths.append(path); try file_paths.append(path);
} else |_| { } else |_| {
std.debug.print("Arg not file: '{s}'\n", .{arg}); std.debug.print("Arg not file: '{s}'\n", .{arg});
@@ -137,7 +150,7 @@ pub fn main() !void {
file_name = token; file_name = token;
} }
const surface: [*c]c.SDL_Surface = c.TTF_RenderText_Solid(font, @ptrCast(file_name), text_color); const surface: [*c]c.SDL_Surface = c.TTF_RenderText_Solid(font, @ptrCast([*c]const u8, file_name), text_color);
if (surface == null) { if (surface == null) {
c.SDL_Log("Unable to render text"); c.SDL_Log("Unable to render text");
return error.RenderTextFailed; return error.RenderTextFailed;
@@ -149,7 +162,7 @@ pub fn main() !void {
return error.CreateTextureFailed; return error.CreateTextureFailed;
} }
const rect = c.SDL_Rect{ var rect = c.SDL_Rect{
.x = 0, .x = 0,
.y = 0, .y = 0,
.w = surface.*.w, .w = surface.*.w,
@@ -161,7 +174,7 @@ pub fn main() !void {
defer file.close(); defer file.close();
const stat = try file.stat(); const stat = try file.stat();
const buffer = try allocator.alloc(u8, stat.size); var buffer = try allocator.alloc(u8, stat.size);
const bytes_read = try file.readAll(buffer); const bytes_read = try file.readAll(buffer);
if (bytes_read != stat.size) { if (bytes_read != stat.size) {
@@ -172,7 +185,7 @@ pub fn main() !void {
return error.FileReadError; return error.FileReadError;
} }
const docmap = FileDocMap{ var docmap = FileDocMap{
.title_text = DrawnText{ .title_text = DrawnText{
.surface = surface, .surface = surface,
.texture = texture, .texture = texture,
@@ -201,7 +214,7 @@ pub fn main() !void {
while (!quit) { while (!quit) {
var event: c.SDL_Event = undefined; var event: c.SDL_Event = undefined;
while (c.SDL_PollEvent(&event) != 0) { while (c.SDL_PollEvent(&event) != 0) {
switch (event.type) { switch (event.@"type") {
c.SDL_QUIT => { c.SDL_QUIT => {
quit = true; quit = true;
}, },