Parcourir la Source

Start with terminal escape code decoding

This is... starting to become a terminal, only a very fiddly one.  It
might actually be more feasible to implement this as something running
_in_ a terminal.  But that would be much less fun.
Luna Stadler 4 ans auparavant
Parent
commit
a438b2c10b
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 10 1
      zig/sdl/hello_sdl.zig

+ 10 - 1
zig/sdl/hello_sdl.zig

@ -338,7 +338,7 @@ const SearchRunner = struct {
338 338
339 339
    fn toArgv(cmd: []const u8) []const []const u8 {
340 340
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["s ".len..]}) catch "???";
341
        return &[_][]const u8{ "ag", &cmd_buf, "/home/luna/k/the-thing" };
341
        return &[_][]const u8{ "ag", "--color", &cmd_buf, "/home/luna/k/the-thing", "/home/luna/t/zig" };
342 342
    }
343 343
};
344 344
@ -690,6 +690,15 @@ pub fn main() !void {
690 690
                _ = std.mem.replace(u8, skipped_line, "\t", " " ** 8, &line_buf);
691 691
                line_buf[repl_size] = 0;
692 692
693
                // TODO: implement some terminal colors
694
                var parts = std.mem.split(u8, line_buf[0..repl_size], "\x1B[");
695
                var part = parts.next();
696
                while (part != null and part.?.len != repl_size) : (part = parts.next()) {
697
                    if (part.?.len > 0) {
698
                        std.debug.print("escape char: {d} {s}\n", .{ part.?[0], part.?[1..] });
699
                    }
700
                }
701
693 702
                const result_text = c.TTF_RenderUTF8_Shaded(font, &line_buf, white, black);
694 703
                const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
695 704
                _ = c.SDL_RenderCopy(renderer, result_texture, null, &c.SDL_Rect{ .x = 0, .y = i * glyph_height, .w = @intCast(c_int, repl_size) * glyph_width, .h = glyph_height });