|
|
@ -338,8 +338,8 @@ const ManPageRunner = struct {
|
|
338
|
338
|
}
|
|
339
|
339
|
|
|
340
|
340
|
fn toArgv(cmd: []const u8) []const []const u8 {
|
|
341
|
|
_ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["man ".len..]}) catch "???";
|
|
342
|
|
return &[_][]const u8{ "man", &cmd_buf };
|
|
|
341
|
_ = std.fmt.bufPrint(&cmd_buf, "MAN_KEEP_FORMATTING=yesplease man {s}\x00", .{cmd["man ".len..]}) catch "???";
|
|
|
342
|
return &[_][]const u8{ "bash", "-c", &cmd_buf };
|
|
343
|
343
|
}
|
|
344
|
344
|
};
|
|
345
|
345
|
|
|
|
@ -355,11 +355,13 @@ const SearchRunner = struct {
|
|
355
|
355
|
fn toArgv(cmd: []const u8) []const []const u8 {
|
|
356
|
356
|
_ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["s ".len..]}) catch "???";
|
|
357
|
357
|
argv_buf[0] = "ag";
|
|
358
|
|
argv_buf[1] = &cmd_buf;
|
|
|
358
|
argv_buf[1] = "--color";
|
|
|
359
|
argv_buf[2] = "--unrestricted";
|
|
|
360
|
argv_buf[3] = &cmd_buf;
|
|
359
|
361
|
for (Config.searchDirectories) |dir, i| {
|
|
360
|
|
argv_buf[2 + i] = dir;
|
|
|
362
|
argv_buf[4 + i] = dir;
|
|
361
|
363
|
}
|
|
362
|
|
return argv_buf[0 .. 2 + Config.searchDirectories.len];
|
|
|
364
|
return argv_buf[0 .. 4 + Config.searchDirectories.len];
|
|
363
|
365
|
}
|
|
364
|
366
|
};
|
|
365
|
367
|
|
|
|
@ -466,6 +468,13 @@ pub fn main() !void {
|
|
466
|
468
|
defer c.TTF_CloseFont(font);
|
|
467
|
469
|
c.SDL_Log("Using font %s", font_file.ptr);
|
|
468
|
470
|
|
|
|
471
|
var bold_font_file = if (args.len > 2) args[2] else "/usr/share/fonts/TTF/FantasqueSansMono-Bold.ttf";
|
|
|
472
|
const bold_font = c.TTF_OpenFont(bold_font_file, 16) orelse {
|
|
|
473
|
c.SDL_Log("Unable to load font: %s", c.TTF_GetError());
|
|
|
474
|
return error.TTFInitializationFailed;
|
|
|
475
|
};
|
|
|
476
|
defer c.TTF_CloseFont(bold_font);
|
|
|
477
|
|
|
469
|
478
|
// assume monospace font
|
|
470
|
479
|
var glyph_width: c_int = 0;
|
|
471
|
480
|
if (c.TTF_GlyphMetrics(font, 'g', null, null, null, null, &glyph_width) != 0) {
|
|
|
@ -702,6 +711,7 @@ pub fn main() !void {
|
|
702
|
711
|
|
|
703
|
712
|
var i: c_int = 1;
|
|
704
|
713
|
var line_buf = [_]u8{0} ** 10000;
|
|
|
714
|
var part_buf = [_]u8{0} ** 10000;
|
|
705
|
715
|
for (commands) |*command| {
|
|
706
|
716
|
if (!command.isActive(cmd)) {
|
|
707
|
717
|
continue;
|
|
|
@ -739,20 +749,76 @@ pub fn main() !void {
|
|
739
|
749
|
_ = std.mem.replace(u8, skipped_line, "\t", " " ** 8, &line_buf);
|
|
740
|
750
|
line_buf[repl_size] = 0;
|
|
741
|
751
|
|
|
|
752
|
var j: c_int = 0;
|
|
|
753
|
|
|
742
|
754
|
// TODO: implement some terminal colors
|
|
743
|
755
|
var parts = std.mem.split(u8, line_buf[0..repl_size], "\x1B[");
|
|
744
|
756
|
var part = parts.next();
|
|
745
|
|
while (part != null and part.?.len != repl_size) : (part = parts.next()) {
|
|
746
|
|
if (part.?.len > 0) {
|
|
747
|
|
std.debug.print("escape char: {d} {s}\n", .{ part.?[0], part.?[0..] });
|
|
|
757
|
while (part != null) : (part = parts.next()) {
|
|
|
758
|
var fnt = font;
|
|
|
759
|
var fg_color = white;
|
|
|
760
|
var bg_color = black;
|
|
|
761
|
|
|
|
762
|
var part_text = part.?;
|
|
|
763
|
if (std.mem.startsWith(u8, part_text, "0m")) {
|
|
|
764
|
part_text = part_text[2..];
|
|
|
765
|
} else if (std.mem.startsWith(u8, part_text, "1;32m")) {
|
|
|
766
|
fnt = bold_font;
|
|
|
767
|
part_text = part_text[5..];
|
|
|
768
|
fg_color = c.SDL_Color{ .r = 0, .g = 205, .b = 0, .a = 255 };
|
|
|
769
|
} else if (std.mem.startsWith(u8, part_text, "1;33m")) {
|
|
|
770
|
fnt = bold_font;
|
|
|
771
|
part_text = part_text[5..];
|
|
|
772
|
fg_color = c.SDL_Color{ .r = 205, .g = 205, .b = 0, .a = 255 };
|
|
|
773
|
} else if (std.mem.startsWith(u8, part_text, "30;43m")) {
|
|
|
774
|
part_text = part_text[6..];
|
|
|
775
|
bg_color = c.SDL_Color{ .r = 205, .g = 205, .b = 0, .a = 255 };
|
|
|
776
|
} else if (std.mem.startsWith(u8, part_text, "K")) {
|
|
|
777
|
// no idea what this is, skipping it
|
|
|
778
|
part_text = part_text[1..];
|
|
|
779
|
} else {
|
|
|
780
|
if (part.?.len > 0) {
|
|
|
781
|
//std.debug.print("unhandled escape char: {d} {s}\n", .{ part.?[0], part.?[0..] });
|
|
|
782
|
}
|
|
748
|
783
|
}
|
|
749
|
|
}
|
|
750
|
784
|
|
|
751
|
|
const result_text = c.TTF_RenderUTF8_Shaded(font, &line_buf, white, black);
|
|
752
|
|
const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
|
|
753
|
|
_ = 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 });
|
|
754
|
|
c.SDL_FreeSurface(result_text);
|
|
755
|
|
c.SDL_DestroyTexture(result_texture);
|
|
|
785
|
var k = j;
|
|
|
786
|
var l: usize = 0;
|
|
|
787
|
var skip_next = false;
|
|
|
788
|
var was_overdraw = false;
|
|
|
789
|
for (part_text) |ch, p| {
|
|
|
790
|
if (skip_next) {
|
|
|
791
|
skip_next = false;
|
|
|
792
|
continue;
|
|
|
793
|
}
|
|
|
794
|
if (ch == 8 and p + 1 < part_text.len) {
|
|
|
795
|
//std.debug.print("overdraw '{c}'\n", .{part_text[p + 1]});
|
|
|
796
|
const result_text = c.TTF_RenderUTF8_Shaded(font, &[_]u8{ part_text[p + 1], 0 }, fg_color, bg_color);
|
|
|
797
|
const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
|
|
|
798
|
_ = c.SDL_RenderCopy(renderer, result_texture, null, &c.SDL_Rect{ .x = (k - 1) * glyph_width, .y = i * glyph_height, .w = @intCast(c_int, 1) * glyph_width, .h = glyph_height });
|
|
|
799
|
c.SDL_FreeSurface(result_text);
|
|
|
800
|
c.SDL_DestroyTexture(result_texture);
|
|
|
801
|
|
|
|
802
|
skip_next = true;
|
|
|
803
|
was_overdraw = true;
|
|
|
804
|
} else {
|
|
|
805
|
part_buf[l] = ch;
|
|
|
806
|
l += 1;
|
|
|
807
|
k += 1;
|
|
|
808
|
}
|
|
|
809
|
}
|
|
|
810
|
part_buf[l] = 0;
|
|
|
811
|
|
|
|
812
|
const result_text = c.TTF_RenderUTF8_Shaded(fnt, &part_buf, fg_color, bg_color);
|
|
|
813
|
const result_texture = c.SDL_CreateTextureFromSurface(renderer, result_text);
|
|
|
814
|
if (was_overdraw and c.SDL_SetTextureBlendMode(result_texture, c.SDL_BLENDMODE_ADD) != 0) {
|
|
|
815
|
c.SDL_Log("Unable set texture blend mode: %s", c.SDL_GetError());
|
|
|
816
|
}
|
|
|
817
|
_ = c.SDL_RenderCopy(renderer, result_texture, null, &c.SDL_Rect{ .x = j * glyph_width, .y = i * glyph_height, .w = @intCast(c_int, l) * glyph_width, .h = glyph_height });
|
|
|
818
|
c.SDL_FreeSurface(result_text);
|
|
|
819
|
c.SDL_DestroyTexture(result_texture);
|
|
|
820
|
j += @intCast(c_int, part_text.len);
|
|
|
821
|
}
|
|
756
|
822
|
|
|
757
|
823
|
i += 1;
|
|
758
|
824
|
line = lines.next();
|