Luna Stadler лет назад: 4
Родитель
Сommit
f94cf0785b
1 измененных файлов с 32 добавлено и 0 удалено
  1. 32 0
      zig/sdl/hello_sdl.zig

+ 32 - 0
zig/sdl/hello_sdl.zig

@ -252,6 +252,21 @@ const PythonHelpRunner = struct {
252 252
    }
253 253
};
254 254
255
const PythonRunner = struct {
256
    fn init() RegexRunner {
257
        return RegexRunner{ .run_always = true, .toArgv = toArgv, .isActive = isActive };
258
    }
259
260
    fn isActive(cmd: []const u8) bool {
261
        return cmd.len > 3 and std.mem.startsWith(u8, cmd, "py! ");
262
    }
263
264
    fn toArgv(cmd: []const u8) []const []const u8 {
265
        _ = std.fmt.bufPrint(&cmd_buf, "print({s})", .{cmd["py! ".len..]}) catch "???";
266
        return &[_][]const u8{ "python", "-c", &cmd_buf };
267
    }
268
};
269
255 270
const SearchRunner = struct {
256 271
    fn init() RegexRunner {
257 272
        return RegexRunner{ .run_always = true, .toArgv = toArgv, .isActive = isActive };
@ -267,6 +282,21 @@ const SearchRunner = struct {
267 282
    }
268 283
};
269 284
285
const QalcRunner = struct {
286
    fn init() RegexRunner {
287
        return RegexRunner{ .run_always = true, .toArgv = toArgv, .isActive = isActive };
288
    }
289
290
    fn isActive(cmd: []const u8) bool {
291
        return cmd.len > 0 and std.ascii.isDigit(cmd[0]);
292
    }
293
294
    fn toArgv(cmd: []const u8) []const []const u8 {
295
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd}) catch "???";
296
        return &[_][]const u8{ "qalc", "-terse", &cmd_buf };
297
    }
298
};
299
270 300
pub fn main() !void {
271 301
    var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
272 302
    defer {
@ -335,7 +365,9 @@ pub fn main() !void {
335 365
    var commands = [_]RegexRunner{
336 366
        GoDocRunner.init(),
337 367
        PythonHelpRunner.init(),
368
        PythonRunner.init(),
338 369
        SearchRunner.init(),
370
        QalcRunner.init(),
339 371
    };
340 372
341 373
    var quit = false;