this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

window: make print infallible

Print and PrintSegment are now infallible due to gwidth also being
infallible. The previous error was only error.OutOfMemory if a temporary
buffer was too small to encode text in gwidth. This has been removed in
favor or a for loop

+36 -36
+1 -1
examples/cli.zig
··· 92 92 .text = opt, 93 93 .style = if (j == i) .{ .reverse = true } else .{}, 94 94 }}; 95 - _ = try win.print(&seg, .{ .row_offset = j + 1 }); 95 + _ = win.print(&seg, .{ .row_offset = j + 1 }); 96 96 } 97 97 } 98 98 try vx.render(tty.anyWriter());
+2 -2
examples/table.zig
··· 239 239 .style = .{ .bg = ctx.bg }, 240 240 }, 241 241 }; 242 - _ = try see_win.print(content_segs, .{}); 242 + _ = see_win.print(content_segs, .{}); 243 243 return see_win.height; 244 244 } 245 245 }.see; ··· 269 269 44, 270 270 top_bar.height - (top_bar.height / 3), 271 271 ); 272 - _ = try logo_bar.print(title_segs[0..], .{ .wrap = .word }); 272 + _ = logo_bar.print(title_segs[0..], .{ .wrap = .word }); 273 273 274 274 // - Middle 275 275 const middle_bar = win.child(.{
+1 -1
examples/vaxis.zig
··· 78 78 .style = style, 79 79 }; 80 80 const center = vaxis.widgets.alignment.center(win, 28, 4); 81 - _ = try center.printSegment(segment, .{ .wrap = .grapheme }); 81 + _ = center.printSegment(segment, .{ .wrap = .grapheme }); 82 82 try vx.render(tty.anyWriter()); 83 83 std.time.sleep(16 * std.time.ns_per_ms); 84 84 switch (dir) {
+4 -4
examples/view.zig
··· 74 74 //h = lg_map_view.screen.height; 75 75 var lg_map_buf: [lg_map_width * lg_map_height]u8 = undefined; 76 76 _ = mem.replace(u8, lg_world_map, "\n", "", lg_map_buf[0..]); 77 - _ = try lg_map_view.printSegment(.{ .text = lg_map_buf[0..] }, .{ .wrap = .grapheme }); 77 + _ = lg_map_view.printSegment(.{ .text = lg_map_buf[0..] }, .{ .wrap = .grapheme }); 78 78 // - Small Map 79 79 var sm_map_view = try View.init(alloc, &vx.unicode, .{ .width = sm_map_width, .height = sm_map_height }); 80 80 defer sm_map_view.deinit(); ··· 82 82 h = sm_map_view.screen.height; 83 83 var sm_map_buf: [sm_map_width * sm_map_height]u8 = undefined; 84 84 _ = mem.replace(u8, sm_world_map, "\n", "", sm_map_buf[0..]); 85 - _ = try sm_map_view.printSegment(.{ .text = sm_map_buf[0..] }, .{ .wrap = .grapheme }); 85 + _ = sm_map_view.printSegment(.{ .text = sm_map_buf[0..] }, .{ .wrap = .grapheme }); 86 86 // - Active Map 87 87 var map_view = lg_map_view; 88 88 ··· 137 137 const controls_win = win.child(.{ 138 138 .height = .{ .limit = 1 }, 139 139 }); 140 - _ = try controls_win.print( 140 + _ = controls_win.print( 141 141 if (win.width >= 112) &.{ 142 142 .{ .text = "Controls:", .style = .{ .bold = true, .ul_style = .single } }, 143 143 .{ .text = " Exit: ctrl + c | Scroll: dpad | Quick Scroll: ctrl + dpad | Goto Side: shift + dpad | Zoom: z | Mini: m" }, ··· 173 173 .y_off = y, 174 174 }); 175 175 if (use_mini_view) { 176 - _ = try win.printSegment( 176 + _ = win.printSegment( 177 177 .{ .text = "This is a mini portion of the View." }, 178 178 .{ .row_offset = 16, .col_offset = 5, .wrap = .word }, 179 179 );
+24 -24
src/Window.zig
··· 280 280 281 281 /// prints segments to the window. returns true if the text overflowed with the 282 282 /// given wrap strategy and size. 283 - pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) !PrintResult { 283 + pub fn print(self: Window, segments: []const Segment, opts: PrintOptions) PrintResult { 284 284 var row = opts.row_offset; 285 285 switch (opts.wrap) { 286 286 .grapheme => { ··· 437 437 } 438 438 439 439 /// print a single segment. This is just a shortcut for print(&.{segment}, opts) 440 - pub fn printSegment(self: Window, segment: Segment, opts: PrintOptions) !PrintResult { 440 + pub fn printSegment(self: Window, segment: Segment, opts: PrintOptions) PrintResult { 441 441 return self.print(&.{segment}, opts); 442 442 } 443 443 ··· 547 547 var segments = [_]Segment{ 548 548 .{ .text = "a" }, 549 549 }; 550 - const result = try win.print(&segments, opts); 550 + const result = win.print(&segments, opts); 551 551 try std.testing.expectEqual(1, result.col); 552 552 try std.testing.expectEqual(0, result.row); 553 553 try std.testing.expectEqual(false, result.overflow); ··· 556 556 var segments = [_]Segment{ 557 557 .{ .text = "abcd" }, 558 558 }; 559 - const result = try win.print(&segments, opts); 559 + const result = win.print(&segments, opts); 560 560 try std.testing.expectEqual(0, result.col); 561 561 try std.testing.expectEqual(1, result.row); 562 562 try std.testing.expectEqual(false, result.overflow); ··· 565 565 var segments = [_]Segment{ 566 566 .{ .text = "abcde" }, 567 567 }; 568 - const result = try win.print(&segments, opts); 568 + const result = win.print(&segments, opts); 569 569 try std.testing.expectEqual(1, result.col); 570 570 try std.testing.expectEqual(1, result.row); 571 571 try std.testing.expectEqual(false, result.overflow); ··· 574 574 var segments = [_]Segment{ 575 575 .{ .text = "abcdefgh" }, 576 576 }; 577 - const result = try win.print(&segments, opts); 577 + const result = win.print(&segments, opts); 578 578 try std.testing.expectEqual(0, result.col); 579 579 try std.testing.expectEqual(2, result.row); 580 580 try std.testing.expectEqual(false, result.overflow); ··· 583 583 var segments = [_]Segment{ 584 584 .{ .text = "abcdefghi" }, 585 585 }; 586 - const result = try win.print(&segments, opts); 586 + const result = win.print(&segments, opts); 587 587 try std.testing.expectEqual(0, result.col); 588 588 try std.testing.expectEqual(2, result.row); 589 589 try std.testing.expectEqual(true, result.overflow); ··· 614 614 var segments = [_]Segment{ 615 615 .{ .text = "a" }, 616 616 }; 617 - const result = try win.print(&segments, opts); 617 + const result = win.print(&segments, opts); 618 618 try std.testing.expectEqual(1, result.col); 619 619 try std.testing.expectEqual(0, result.row); 620 620 try std.testing.expectEqual(false, result.overflow); ··· 623 623 var segments = [_]Segment{ 624 624 .{ .text = " " }, 625 625 }; 626 - const result = try win.print(&segments, opts); 626 + const result = win.print(&segments, opts); 627 627 try std.testing.expectEqual(1, result.col); 628 628 try std.testing.expectEqual(0, result.row); 629 629 try std.testing.expectEqual(false, result.overflow); ··· 632 632 var segments = [_]Segment{ 633 633 .{ .text = " a" }, 634 634 }; 635 - const result = try win.print(&segments, opts); 635 + const result = win.print(&segments, opts); 636 636 try std.testing.expectEqual(2, result.col); 637 637 try std.testing.expectEqual(0, result.row); 638 638 try std.testing.expectEqual(false, result.overflow); ··· 641 641 var segments = [_]Segment{ 642 642 .{ .text = "a b" }, 643 643 }; 644 - const result = try win.print(&segments, opts); 644 + const result = win.print(&segments, opts); 645 645 try std.testing.expectEqual(3, result.col); 646 646 try std.testing.expectEqual(0, result.row); 647 647 try std.testing.expectEqual(false, result.overflow); ··· 650 650 var segments = [_]Segment{ 651 651 .{ .text = "a b c" }, 652 652 }; 653 - const result = try win.print(&segments, opts); 653 + const result = win.print(&segments, opts); 654 654 try std.testing.expectEqual(1, result.col); 655 655 try std.testing.expectEqual(1, result.row); 656 656 try std.testing.expectEqual(false, result.overflow); ··· 659 659 var segments = [_]Segment{ 660 660 .{ .text = "hello" }, 661 661 }; 662 - const result = try win.print(&segments, opts); 662 + const result = win.print(&segments, opts); 663 663 try std.testing.expectEqual(1, result.col); 664 664 try std.testing.expectEqual(1, result.row); 665 665 try std.testing.expectEqual(false, result.overflow); ··· 668 668 var segments = [_]Segment{ 669 669 .{ .text = "hi tim" }, 670 670 }; 671 - const result = try win.print(&segments, opts); 671 + const result = win.print(&segments, opts); 672 672 try std.testing.expectEqual(3, result.col); 673 673 try std.testing.expectEqual(1, result.row); 674 674 try std.testing.expectEqual(false, result.overflow); ··· 677 677 var segments = [_]Segment{ 678 678 .{ .text = "hello tim" }, 679 679 }; 680 - const result = try win.print(&segments, opts); 680 + const result = win.print(&segments, opts); 681 681 try std.testing.expectEqual(0, result.col); 682 682 try std.testing.expectEqual(2, result.row); 683 683 try std.testing.expectEqual(true, result.overflow); ··· 686 686 var segments = [_]Segment{ 687 687 .{ .text = "hello ti" }, 688 688 }; 689 - const result = try win.print(&segments, opts); 689 + const result = win.print(&segments, opts); 690 690 try std.testing.expectEqual(0, result.col); 691 691 try std.testing.expectEqual(2, result.row); 692 692 try std.testing.expectEqual(false, result.overflow); ··· 696 696 .{ .text = "h" }, 697 697 .{ .text = "e" }, 698 698 }; 699 - const result = try win.print(&segments, opts); 699 + const result = win.print(&segments, opts); 700 700 try std.testing.expectEqual(2, result.col); 701 701 try std.testing.expectEqual(0, result.row); 702 702 try std.testing.expectEqual(false, result.overflow); ··· 709 709 .{ .text = "l" }, 710 710 .{ .text = "o" }, 711 711 }; 712 - const result = try win.print(&segments, opts); 712 + const result = win.print(&segments, opts); 713 713 try std.testing.expectEqual(1, result.col); 714 714 try std.testing.expectEqual(1, result.row); 715 715 try std.testing.expectEqual(false, result.overflow); ··· 718 718 var segments = [_]Segment{ 719 719 .{ .text = "he\n" }, 720 720 }; 721 - const result = try win.print(&segments, opts); 721 + const result = win.print(&segments, opts); 722 722 try std.testing.expectEqual(0, result.col); 723 723 try std.testing.expectEqual(1, result.row); 724 724 try std.testing.expectEqual(false, result.overflow); ··· 727 727 var segments = [_]Segment{ 728 728 .{ .text = "he\n\n" }, 729 729 }; 730 - const result = try win.print(&segments, opts); 730 + const result = win.print(&segments, opts); 731 731 try std.testing.expectEqual(0, result.col); 732 732 try std.testing.expectEqual(2, result.row); 733 733 try std.testing.expectEqual(false, result.overflow); ··· 736 736 var segments = [_]Segment{ 737 737 .{ .text = "not now" }, 738 738 }; 739 - const result = try win.print(&segments, opts); 739 + const result = win.print(&segments, opts); 740 740 try std.testing.expectEqual(3, result.col); 741 741 try std.testing.expectEqual(1, result.row); 742 742 try std.testing.expectEqual(false, result.overflow); ··· 745 745 var segments = [_]Segment{ 746 746 .{ .text = "note now" }, 747 747 }; 748 - const result = try win.print(&segments, opts); 748 + const result = win.print(&segments, opts); 749 749 try std.testing.expectEqual(3, result.col); 750 750 try std.testing.expectEqual(1, result.row); 751 751 try std.testing.expectEqual(false, result.overflow); ··· 755 755 .{ .text = "note" }, 756 756 .{ .text = " now" }, 757 757 }; 758 - const result = try win.print(&segments, opts); 758 + const result = win.print(&segments, opts); 759 759 try std.testing.expectEqual(3, result.col); 760 760 try std.testing.expectEqual(1, result.row); 761 761 try std.testing.expectEqual(false, result.overflow); ··· 765 765 .{ .text = "note " }, 766 766 .{ .text = "now" }, 767 767 }; 768 - const result = try win.print(&segments, opts); 768 + const result = win.print(&segments, opts); 769 769 try std.testing.expectEqual(3, result.col); 770 770 try std.testing.expectEqual(1, result.row); 771 771 try std.testing.expectEqual(false, result.overflow);
+2 -2
src/widgets/Table.zig
··· 255 255 .ul_style = if (idx == table_ctx.col) .single else .dotted, 256 256 }, 257 257 }}; 258 - _ = try hdr.print(seg[0..], .{ .wrap = .word }); 258 + _ = hdr.print(seg[0..], .{ .wrap = .word }); 259 259 } 260 260 261 261 // Rows ··· 378 378 .text = if (item_txt.len > col_width and alloc != null) try fmt.allocPrint(alloc.?, "{s}...", .{item_txt[0..(col_width -| 4)]}) else item_txt, 379 379 .style = .{ .fg = row_fg, .bg = row_bg }, 380 380 }}; 381 - _ = try item_align_win.print(seg[0..], .{ .wrap = .word, .col_offset = table_ctx.cell_x_off }); 381 + _ = item_align_win.print(seg[0..], .{ .wrap = .word, .col_offset = table_ctx.cell_x_off }); 382 382 } 383 383 } 384 384 }
+2 -2
src/widgets/View.zig
··· 149 149 150 150 /// Prints segments to the View. Returns true if the text overflowed with the 151 151 /// given wrap strategy and size. 152 - pub fn print(self: *View, segments: []const Cell.Segment, opts: Window.PrintOptions) !Window.PrintResult { 152 + pub fn print(self: *View, segments: []const Cell.Segment, opts: Window.PrintOptions) Window.PrintResult { 153 153 return self.window().print(segments, opts); 154 154 } 155 155 156 156 /// Print a single segment. This is just a shortcut for print(&.{segment}, opts) 157 - pub fn printSegment(self: *View, segment: Cell.Segment, opts: Window.PrintOptions) !Window.PrintResult { 157 + pub fn printSegment(self: *View, segment: Cell.Segment, opts: Window.PrintOptions) Window.PrintResult { 158 158 return self.print(&.{segment}, opts); 159 159 }