ソースを参照

Rename RegexRunner to Runner to reflect what it does better

Luna Stadler 4 年 前
コミット
8dc8c2cee1
共有1 個のファイルを変更した21 個の追加21 個の削除を含む
  1. 21 21
      zig/sdl/hello_sdl.zig

+ 21 - 21
zig/sdl/hello_sdl.zig

149
    }
149
    }
150
};
150
};
151
151
152
const RegexRunner = struct {
152
const Runner = struct {
153
    name: []const u8,
153
    name: []const u8,
154
    run_always: bool,
154
    run_always: bool,
155
    process: ?ProcessWithOutput = null,
155
    process: ?ProcessWithOutput = null,
157
    toArgv: fn (cmd: []const u8) []const []const u8,
157
    toArgv: fn (cmd: []const u8) []const []const u8,
158
    isActive: fn (cmd: []const u8) bool,
158
    isActive: fn (cmd: []const u8) bool,
159
159
160
    fn run(self: *RegexRunner, allocator: *std.mem.Allocator, cmd: []const u8, is_confirmed: bool) !bool {
160
    fn run(self: *Runner, allocator: *std.mem.Allocator, cmd: []const u8, is_confirmed: bool) !bool {
161
        if (!self.run_always and !is_confirmed) {
161
        if (!self.run_always and !is_confirmed) {
162
            return false;
162
            return false;
163
        }
163
        }
189
        return true;
189
        return true;
190
    }
190
    }
191
191
192
    fn output(self: *RegexRunner) ![]const u8 {
192
    fn output(self: *Runner) ![]const u8 {
193
        if (self.process) |*process| {
193
        if (self.process) |*process| {
194
            process.poll() catch |err| switch (err) {
194
            process.poll() catch |err| switch (err) {
195
                error.StdoutStreamTooLong => {
195
                error.StdoutStreamTooLong => {
211
        return "<no output>";
211
        return "<no output>";
212
    }
212
    }
213
213
214
    fn deinit(self: *RegexRunner) void {
214
    fn deinit(self: *Runner) void {
215
        if (self.process) |*process| {
215
        if (self.process) |*process| {
216
            process.deinit();
216
            process.deinit();
217
        }
217
        }
221
var cmd_buf: [1000]u8 = undefined;
221
var cmd_buf: [1000]u8 = undefined;
222
222
223
const GoDocRunner = struct {
223
const GoDocRunner = struct {
224
    fn init() RegexRunner {
225
        return RegexRunner{ .name = "go doc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
224
    fn init() Runner {
225
        return Runner{ .name = "go doc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
226
    }
226
    }
227
227
228
    fn isActive(cmd: []const u8) bool {
228
    fn isActive(cmd: []const u8) bool {
237
};
237
};
238
238
239
const PythonHelpRunner = struct {
239
const PythonHelpRunner = struct {
240
    fn init() RegexRunner {
241
        return RegexRunner{ .name = "python help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
240
    fn init() Runner {
241
        return Runner{ .name = "python help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
242
    }
242
    }
243
243
244
    fn isActive(cmd: []const u8) bool {
244
    fn isActive(cmd: []const u8) bool {
252
};
252
};
253
253
254
const PythonRunner = struct {
254
const PythonRunner = struct {
255
    fn init() RegexRunner {
256
        return RegexRunner{ .name = "python run", .run_always = true, .toArgv = toArgv, .isActive = isActive };
255
    fn init() Runner {
256
        return Runner{ .name = "python run", .run_always = true, .toArgv = toArgv, .isActive = isActive };
257
    }
257
    }
258
258
259
    fn isActive(cmd: []const u8) bool {
259
    fn isActive(cmd: []const u8) bool {
267
};
267
};
268
268
269
const HelpRunner = struct {
269
const HelpRunner = struct {
270
    fn init() RegexRunner {
271
        return RegexRunner{ .name = "--help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
270
    fn init() Runner {
271
        return Runner{ .name = "--help", .run_always = true, .toArgv = toArgv, .isActive = isActive };
272
    }
272
    }
273
273
274
    fn isActive(cmd: []const u8) bool {
274
    fn isActive(cmd: []const u8) bool {
282
};
282
};
283
283
284
const ManPageRunner = struct {
284
const ManPageRunner = struct {
285
    fn init() RegexRunner {
286
        return RegexRunner{ .name = "man page", .run_always = true, .toArgv = toArgv, .isActive = isActive };
285
    fn init() Runner {
286
        return Runner{ .name = "man page", .run_always = true, .toArgv = toArgv, .isActive = isActive };
287
    }
287
    }
288
288
289
    fn isActive(cmd: []const u8) bool {
289
    fn isActive(cmd: []const u8) bool {
297
};
297
};
298
298
299
const SearchRunner = struct {
299
const SearchRunner = struct {
300
    fn init() RegexRunner {
301
        return RegexRunner{ .name = "search", .run_always = true, .toArgv = toArgv, .isActive = isActive };
300
    fn init() Runner {
301
        return Runner{ .name = "search", .run_always = true, .toArgv = toArgv, .isActive = isActive };
302
    }
302
    }
303
303
304
    fn isActive(cmd: []const u8) bool {
304
    fn isActive(cmd: []const u8) bool {
312
};
312
};
313
313
314
const LogsRunner = struct {
314
const LogsRunner = struct {
315
    fn init() RegexRunner {
316
        return RegexRunner{ .name = "logs", .run_always = true, .toArgv = toArgv, .isActive = isActive };
315
    fn init() Runner {
316
        return Runner{ .name = "logs", .run_always = true, .toArgv = toArgv, .isActive = isActive };
317
    }
317
    }
318
318
319
    fn isActive(cmd: []const u8) bool {
319
    fn isActive(cmd: []const u8) bool {
332
};
332
};
333
333
334
const QalcRunner = struct {
334
const QalcRunner = struct {
335
    fn init() RegexRunner {
336
        return RegexRunner{ .name = "qalc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
335
    fn init() Runner {
336
        return Runner{ .name = "qalc", .run_always = true, .toArgv = toArgv, .isActive = isActive };
337
    }
337
    }
338
338
339
    fn isActive(cmd: []const u8) bool {
339
    fn isActive(cmd: []const u8) bool {
411
    const keyboardState = c.SDL_GetKeyboardState(null);
411
    const keyboardState = c.SDL_GetKeyboardState(null);
412
412
413
    c.SDL_StartTextInput();
413
    c.SDL_StartTextInput();
414
    var commands = [_]RegexRunner{
414
    var commands = [_]Runner{
415
        GoDocRunner.init(),
415
        GoDocRunner.init(),
416
        PythonHelpRunner.init(),
416
        PythonHelpRunner.init(),
417
        PythonRunner.init(),
417
        PythonRunner.init(),