ソースを参照

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 年 前
コミット
a438b2c10b
共有1 個のファイルを変更した10 個の追加1 個の削除を含む
  1. 10 1
      zig/sdl/hello_sdl.zig

+ 10 - 1
zig/sdl/hello_sdl.zig

338
338
339
    fn toArgv(cmd: []const u8) []const []const u8 {
339
    fn toArgv(cmd: []const u8) []const []const u8 {
340
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["s ".len..]}) catch "???";
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
                _ = std.mem.replace(u8, skipped_line, "\t", " " ** 8, &line_buf);
690
                _ = std.mem.replace(u8, skipped_line, "\t", " " ** 8, &line_buf);
691
                line_buf[repl_size] = 0;
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
                const result_text = c.TTF_RenderUTF8_Shaded(font, &line_buf, white, black);
702
                const result_text = c.TTF_RenderUTF8_Shaded(font, &line_buf, white, black);
694
                const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
703
                const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
695
                _ = 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 });
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 });