|
1 | | -const STYLES = @import("styles.zig"); |
2 | 1 | const STD = @import("std"); |
3 | 2 |
|
| 3 | +const STYLES = @import("styles.zig"); |
| 4 | + |
4 | 5 | var stdin_buffer: [1024]u8 = undefined; |
5 | 6 | var stdin_reader = STD.fs.File.stdin().reader(&stdin_buffer); |
6 | 7 | const STDIN = &stdin_reader.interface; |
@@ -30,48 +31,10 @@ const CLI = struct { |
30 | 31 | current_exercise_prev_mod_time: i128 = 0, |
31 | 32 | current_chapter: []const u8 = "", |
32 | 33 | list_of_chapter_support_files: STD.ArrayList([]const u8) = .empty, |
| 34 | + list_of_patches: STD.ArrayList([]const u8) = .empty, |
33 | 35 | }; |
34 | 36 |
|
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 |
75 | 38 | fn iterateExerciseDirectory( |
76 | 39 | self: *CLI, |
77 | 40 | exercise_dir: struct { dir_path: []const u8 = "exercises" }, |
@@ -160,6 +123,7 @@ fn iterateNextExercise(self: *CLI) !void { |
160 | 123 | try compileCurrentExercise(self); |
161 | 124 | } |
162 | 125 |
|
| 126 | +// TODO: implement abstract factory/protoype; watch current exercise and support files |
163 | 127 | fn watchFileChanges(self: *CLI, polling_rate_ms: u64) !void { |
164 | 128 | while (true) { |
165 | 129 | 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 |
375 | 339 |
|
376 | 340 | try userInput(self); |
377 | 341 | } |
| 342 | + |
0 commit comments