╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Title.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
368 ".####.", 369 "#...##", 370 "#..#.#", 371 "#..#.#", 372 "#.#..#", 373 "#.#..#", 374 "##...#", 375 "#....#", 376 ".####.", 377 }, 378 '1' => .{ 379 "..##..", 380 ".###..", 381 "..##..", 382 "..##..", 383 "..##..", 384 "..##..", 385 "..##..", 386 "..##..", 387 "######", 388 }, 389 '2' => .{ 390 ".####.", 391 "#....#", 392 ".....#", 393 "....#.", 394 "...#..", 395 "..#...", 396 ".#....", 397 "#.....", 398 "######", 399 }, 400 '3' => .{ 401 ".####.", 402 "#....#", 403 ".....#", 404 ".....#", 405 ".####.", 406 ".....#", 407 ".....#", 408 "#....#", 409 ".####.", 410 }, 411 '4' => .{ 412 "....#.", 413 "...##.", 414 "..#.#.", 415 ".#..#.", 416 "#...#.", 417 "######", 418 "....#.", 419 "....#.", 420 "....#.", 421 }, 422 '5' => .{ 423 "######", 424 "#.....", 425 "#.....", 426 "#.....", 427 "#####.", 428 ".....#", 429 ".....#", 430 "#....#", 431 ".####.", 432 }, 433 '6' => .{ 434 ".####.", 435 "#....#", 436 "#.....", 437 "#.....", 438 "#####.", 439 "#....#", 440 "#....#", 441 "#....#", 442 ".####.", 443 }, 444 '7' => .{ 445 "######", 446 ".....#", 447 "....#.", 448 "....#.", 449 "...#..", 450 "...#..", 451 "..#...", 452 "..#...", 453 ".#....", 454 }, 455 '8' => .{ 456 ".####.", 457 "#....#", 458 "#....#", 459 "#....#", 460 ".####.", 461 "#....#", 462 "#....#", 463 "#....#", 464 ".####.", 465 }, 466 '9' => .{ 467 ".####.", 468 "#....#", 469 "#....#", 470 "#....#", 471 ".#####", 472 ".....#", 473 ".....#", 474 "#....#", 475 ".####.", 476 }, 477 '-' => .{ 478 "......", 479 "......", 480 "......", 481 "......", 482 ".####.", 483 "......", 484 "......", 485 "......", 486 "......", 487 }, 488 '.' => .{ 489 "......", 490 "......", 491 "......", 492 "......", 493 "......", 494 "......", 495 "......", 496 "..##..", 497 "..##..", 498 }, 499 else => null, 500 }; 501 } 502 503 // map a 2x3 sub-pixel pattern to its corresponding sextant codepoint 504 fn sextantCodepoint(pattern: u6) u21 { 505 return switch (pattern) { 506 0b000000 => ' ', 507 0b010101 => 0x258C, // ▌ left half block 508 0b101010 => 0x2590, // ▐ right half block 509 0b111111 => 0x2588, // █ full block 510 else => blk: { 511 var offset: u21 = @as(u21, pattern) - 1; 512 if (pattern > 0b010101) offset -= 1; 513 if (pattern > 0b101010) offset -= 1; 514 break :blk 0x1FB00 + offset; 515 }, 516 }; 517 } 518 519 fn renderTitle(allocator: std.mem.Allocator, input: []const u8) ![]const u8 { 520 var rows: [3]std.ArrayList(u8) = .{ .empty, .empty, .empty }; 521 defer for (&rows) |*r| r.deinit(allocator); 522 523 var first = true; 524 for (input) |c| { 525 const glyph = glyphFor(c) orelse continue; 526 527 // row-aligned dither: keep on-pixels only at even bitmap rows. 528 var kept: [9][6]bool = std.mem.zeroes([9][6]bool); 529 for (0..9) |r| { 530 if (r % 2 != 0) continue; 531 for (0..6) |col| { 532 kept[r][col] = glyph[r][col] == '#'; 533 } 534 } 535 536 if (!first) { 537 for (&rows) |*r| try r.append(allocator, ' '); 538 } 539 first = false; 540 541 for (0..3) |text_row| { 542 for (0..3) |text_col| { 543 var pattern: u6 = 0; 544 for (0..3) |sub_row| { 545 for (0..2) |sub_col| { 546 const row_idx = text_row * 3 + sub_row; 547 const col_idx = text_col * 2 + sub_col; 548 if (kept[row_idx][col_idx]) { 549 pattern |= @as(u6, 1) << @intCast(sub_row * 2 + sub_col); 550 } 551 } 552 } 553 const cp = sextantCodepoint(pattern); 554 var utf8_buf: [4]u8 = undefined; 555 const len = try std.unicode.utf8Encode(cp, &utf8_buf); 556 try rows[text_row].appendSlice(allocator, utf8_buf[0..len]); 557 } 558 } 559 } 560 561 var out: std.ArrayList(u8) = .empty; 562 errdefer out.deinit(allocator); 563 try out.appendSlice(allocator, rows[0].items); 564 try out.append(allocator, '\n'); 565 try out.appendSlice(allocator, rows[1].items); 566 try out.append(allocator, '\n'); 567 try out.appendSlice(allocator, rows[2].items); 568 return out.toOwnedSlice(allocator); 569 } 570