Skip to content

Commit ff856c7

Browse files
refactor: move source code into ./src
1 parent 68e2a86 commit ff856c7

10 files changed

Lines changed: 697 additions & 466 deletions

File tree

src/cli/cli.zig renamed to src/cli.zig

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const STYLES = @import("styles.zig");
21
const STD = @import("std");
32

3+
const STYLES = @import("styles.zig");
4+
45
var stdin_buffer: [1024]u8 = undefined;
56
var stdin_reader = STD.fs.File.stdin().reader(&stdin_buffer);
67
const STDIN = &stdin_reader.interface;
@@ -30,48 +31,10 @@ const CLI = struct {
3031
current_exercise_prev_mod_time: i128 = 0,
3132
current_chapter: []const u8 = "",
3233
list_of_chapter_support_files: STD.ArrayList([]const u8) = .empty,
34+
list_of_patches: STD.ArrayList([]const u8) = .empty,
3335
};
3436

35-
pub fn iterateDirectory(
36-
allocator: STD.mem.Allocator,
37-
extra_options: struct {
38-
dir_path: []const u8 = "exercises",
39-
},
40-
) !STD.ArrayList([]const u8) {
41-
var list_of_contents: STD.ArrayList([]const u8) = .empty;
42-
43-
const TOP_LEVEL_DIR = try STD.fs.cwd().openDir(extra_options.dir_path, .{ .iterate = true });
44-
var chapters = TOP_LEVEL_DIR.iterate();
45-
46-
while (try chapters.next()) |chapter| {
47-
const CHAPTER_DIR_PATH = try STD.fs.path.join(allocator, &.{ extra_options.dir_path, chapter.name });
48-
49-
const CHAPTER_DIR = try STD.fs.cwd().openDir(CHAPTER_DIR_PATH, .{ .iterate = true });
50-
var contents = CHAPTER_DIR.iterate();
51-
52-
while (try contents.next()) |content| {
53-
const CONTENT_FILE_PATH = try STD.fs.path.join(allocator, &.{ extra_options.dir_path, chapter.name, content.name });
54-
55-
if (STD.mem.containsAtLeast(u8, content.name, 1, ".cpp")) {
56-
try list_of_contents.append(allocator, CONTENT_FILE_PATH);
57-
}
58-
}
59-
}
60-
61-
STD.sort.insertion(
62-
[]const u8,
63-
list_of_contents.items,
64-
{},
65-
struct {
66-
fn lessThan(_: void, a: []const u8, b: []const u8) bool {
67-
return STD.mem.lessThan(u8, a, b);
68-
}
69-
}.lessThan,
70-
);
71-
72-
return list_of_contents;
73-
}
74-
37+
// TODO: strategy + observer pattern; iterate exercises, iterate patches
7538
fn iterateExerciseDirectory(
7639
self: *CLI,
7740
exercise_dir: struct { dir_path: []const u8 = "exercises" },
@@ -160,6 +123,7 @@ fn iterateNextExercise(self: *CLI) !void {
160123
try compileCurrentExercise(self);
161124
}
162125

126+
// TODO: implement abstract factory/protoype; watch current exercise and support files
163127
fn watchFileChanges(self: *CLI, polling_rate_ms: u64) !void {
164128
while (true) {
165129
const CURRENT_EXERCISE_METADATA = try STD.fs.cwd().statFile(self.current_exercise);
@@ -375,3 +339,4 @@ pub fn run(allocator: STD.mem.Allocator, extra_options: struct { exercises_dir_p
375339

376340
try userInput(self);
377341
}
342+

src/cli/patch.zig

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/cli/test_patch.zig

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/cli/test_util.zig

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)