| skipped 18 lines |
19 | 19 | | "testing" |
20 | 20 | | |
21 | 21 | | "github.com/kylelemons/godebug/pretty" |
| 22 | + | "github.com/mum4k/termdash/align" |
22 | 23 | | "github.com/mum4k/termdash/cell" |
23 | 24 | | "github.com/mum4k/termdash/internal/canvas" |
24 | 25 | | "github.com/mum4k/termdash/internal/canvas/braille/testbraille" |
| skipped 118 lines |
143 | 144 | | update: func(d *Donut) error { |
144 | 145 | | return d.Percent(100) |
145 | 146 | | }, |
146 | | - | canvas: image.Rect(0, 0, 1, 1), |
147 | | - | wantDrawErr: true, |
| 147 | + | canvas: image.Rect(0, 0, 1, 1), |
| 148 | + | want: func(size image.Point) *faketerm.Terminal { |
| 149 | + | ft := faketerm.MustNew(size) |
| 150 | + | cvs := testcanvas.MustNew(ft.Area()) |
| 151 | + | testdraw.MustResizeNeeded(cvs) |
| 152 | + | testcanvas.MustApply(cvs, ft) |
| 153 | + | return ft |
| 154 | + | }, |
148 | 155 | | }, |
149 | 156 | | { |
150 | 157 | | desc: "smallest valid donut, 100% progress", |
| skipped 12 lines |
163 | 170 | | }, |
164 | 171 | | }, |
165 | 172 | | { |
| 173 | + | desc: "adding label to the smallest canvas makes it too small", |
| 174 | + | opts: []Option{ |
| 175 | + | Label("hi"), |
| 176 | + | }, |
| 177 | + | canvas: image.Rect(0, 0, 3, 3), |
| 178 | + | update: func(d *Donut) error { |
| 179 | + | return d.Percent(100) |
| 180 | + | }, |
| 181 | + | want: func(size image.Point) *faketerm.Terminal { |
| 182 | + | ft := faketerm.MustNew(size) |
| 183 | + | cvs := testcanvas.MustNew(ft.Area()) |
| 184 | + | testdraw.MustResizeNeeded(cvs) |
| 185 | + | testcanvas.MustApply(cvs, ft) |
| 186 | + | return ft |
| 187 | + | }, |
| 188 | + | }, |
| 189 | + | { |
166 | 190 | | desc: "New sets donut options", |
167 | 191 | | opts: []Option{ |
168 | 192 | | CellOpts( |
| skipped 132 lines |
301 | 325 | | }, |
302 | 326 | | }, |
303 | 327 | | { |
| 328 | + | desc: "draws hole and label", |
| 329 | + | opts: []Option{ |
| 330 | + | Label("hi"), |
| 331 | + | }, |
| 332 | + | canvas: image.Rect(0, 0, 6, 6), |
| 333 | + | update: func(d *Donut) error { |
| 334 | + | return d.Percent(100, HolePercent(50)) |
| 335 | + | }, |
| 336 | + | want: func(size image.Point) *faketerm.Terminal { |
| 337 | + | ft := faketerm.MustNew(size) |
| 338 | + | c := testcanvas.MustNew(ft.Area()) |
| 339 | + | bc := testbraille.MustNew(ft.Area()) |
| 340 | + | |
| 341 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, draw.BrailleCircleFilled()) |
| 342 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 3, |
| 343 | + | draw.BrailleCircleFilled(), |
| 344 | + | draw.BrailleCircleClearPixels(), |
| 345 | + | ) |
| 346 | + | testbraille.MustCopyTo(bc, c) |
| 347 | + | |
| 348 | + | testdraw.MustText(c, "hi", image.Point{2, 5}) |
| 349 | + | |
| 350 | + | testcanvas.MustApply(c, ft) |
| 351 | + | return ft |
| 352 | + | }, |
| 353 | + | }, |
| 354 | + | { |
304 | 355 | | desc: "hole as large as donut", |
305 | 356 | | canvas: image.Rect(0, 0, 6, 6), |
306 | 357 | | update: func(d *Donut) error { |
| skipped 265 lines |
572 | 623 | | testbraille.MustCopyTo(bc, c) |
573 | 624 | | |
574 | 625 | | testdraw.MustText(c, "1/10", image.Point{2, 4}) |
| 626 | + | |
| 627 | + | testcanvas.MustApply(c, ft) |
| 628 | + | return ft |
| 629 | + | }, |
| 630 | + | }, |
| 631 | + | { |
| 632 | + | desc: "displays text label under the donut", |
| 633 | + | opts: []Option{ |
| 634 | + | Label("hi"), |
| 635 | + | }, |
| 636 | + | canvas: image.Rect(0, 0, 7, 7), |
| 637 | + | update: func(d *Donut) error { |
| 638 | + | return d.Percent(100, HolePercent(80)) |
| 639 | + | }, |
| 640 | + | want: func(size image.Point) *faketerm.Terminal { |
| 641 | + | ft := faketerm.MustNew(size) |
| 642 | + | c := testcanvas.MustNew(ft.Area()) |
| 643 | + | bc := testbraille.MustNew(c.Area()) |
| 644 | + | |
| 645 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 646 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 647 | + | draw.BrailleCircleFilled(), |
| 648 | + | draw.BrailleCircleClearPixels(), |
| 649 | + | ) |
| 650 | + | testbraille.MustCopyTo(bc, c) |
| 651 | + | |
| 652 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 653 | + | |
| 654 | + | testdraw.MustText(c, "hi", image.Point{2, 6}) |
| 655 | + | |
| 656 | + | testcanvas.MustApply(c, ft) |
| 657 | + | return ft |
| 658 | + | }, |
| 659 | + | }, |
| 660 | + | { |
| 661 | + | desc: "aligns text label center with option", |
| 662 | + | opts: []Option{ |
| 663 | + | Label("hi"), |
| 664 | + | LabelAlign(align.HorizontalCenter), |
| 665 | + | }, |
| 666 | + | canvas: image.Rect(0, 0, 7, 7), |
| 667 | + | update: func(d *Donut) error { |
| 668 | + | return d.Percent(100, HolePercent(80)) |
| 669 | + | }, |
| 670 | + | want: func(size image.Point) *faketerm.Terminal { |
| 671 | + | ft := faketerm.MustNew(size) |
| 672 | + | c := testcanvas.MustNew(ft.Area()) |
| 673 | + | bc := testbraille.MustNew(c.Area()) |
| 674 | + | |
| 675 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 676 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 677 | + | draw.BrailleCircleFilled(), |
| 678 | + | draw.BrailleCircleClearPixels(), |
| 679 | + | ) |
| 680 | + | testbraille.MustCopyTo(bc, c) |
| 681 | + | |
| 682 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 683 | + | |
| 684 | + | testdraw.MustText(c, "hi", image.Point{2, 6}) |
| 685 | + | |
| 686 | + | testcanvas.MustApply(c, ft) |
| 687 | + | return ft |
| 688 | + | }, |
| 689 | + | }, |
| 690 | + | { |
| 691 | + | desc: "aligns text label left", |
| 692 | + | opts: []Option{ |
| 693 | + | Label("hi"), |
| 694 | + | LabelAlign(align.HorizontalLeft), |
| 695 | + | }, |
| 696 | + | canvas: image.Rect(0, 0, 7, 7), |
| 697 | + | update: func(d *Donut) error { |
| 698 | + | return d.Percent(100, HolePercent(80)) |
| 699 | + | }, |
| 700 | + | want: func(size image.Point) *faketerm.Terminal { |
| 701 | + | ft := faketerm.MustNew(size) |
| 702 | + | c := testcanvas.MustNew(ft.Area()) |
| 703 | + | bc := testbraille.MustNew(c.Area()) |
| 704 | + | |
| 705 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 706 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 707 | + | draw.BrailleCircleFilled(), |
| 708 | + | draw.BrailleCircleClearPixels(), |
| 709 | + | ) |
| 710 | + | testbraille.MustCopyTo(bc, c) |
| 711 | + | |
| 712 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 713 | + | |
| 714 | + | testdraw.MustText(c, "hi", image.Point{0, 6}) |
| 715 | + | |
| 716 | + | testcanvas.MustApply(c, ft) |
| 717 | + | return ft |
| 718 | + | }, |
| 719 | + | }, |
| 720 | + | { |
| 721 | + | desc: "aligns text label right", |
| 722 | + | opts: []Option{ |
| 723 | + | Label("hi"), |
| 724 | + | LabelAlign(align.HorizontalRight), |
| 725 | + | }, |
| 726 | + | canvas: image.Rect(0, 0, 7, 7), |
| 727 | + | update: func(d *Donut) error { |
| 728 | + | return d.Percent(100, HolePercent(80)) |
| 729 | + | }, |
| 730 | + | want: func(size image.Point) *faketerm.Terminal { |
| 731 | + | ft := faketerm.MustNew(size) |
| 732 | + | c := testcanvas.MustNew(ft.Area()) |
| 733 | + | bc := testbraille.MustNew(c.Area()) |
| 734 | + | |
| 735 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 736 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 737 | + | draw.BrailleCircleFilled(), |
| 738 | + | draw.BrailleCircleClearPixels(), |
| 739 | + | ) |
| 740 | + | testbraille.MustCopyTo(bc, c) |
| 741 | + | |
| 742 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 743 | + | |
| 744 | + | testdraw.MustText(c, "hi", image.Point{5, 6}) |
| 745 | + | |
| 746 | + | testcanvas.MustApply(c, ft) |
| 747 | + | return ft |
| 748 | + | }, |
| 749 | + | }, |
| 750 | + | { |
| 751 | + | desc: "sets cell options on text label", |
| 752 | + | opts: []Option{ |
| 753 | + | Label( |
| 754 | + | "hi", |
| 755 | + | cell.FgColor(cell.ColorRed), |
| 756 | + | cell.BgColor(cell.ColorBlue), |
| 757 | + | ), |
| 758 | + | }, |
| 759 | + | canvas: image.Rect(0, 0, 7, 7), |
| 760 | + | update: func(d *Donut) error { |
| 761 | + | return d.Percent(100, HolePercent(80)) |
| 762 | + | }, |
| 763 | + | want: func(size image.Point) *faketerm.Terminal { |
| 764 | + | ft := faketerm.MustNew(size) |
| 765 | + | c := testcanvas.MustNew(ft.Area()) |
| 766 | + | bc := testbraille.MustNew(c.Area()) |
| 767 | + | |
| 768 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 769 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 770 | + | draw.BrailleCircleFilled(), |
| 771 | + | draw.BrailleCircleClearPixels(), |
| 772 | + | ) |
| 773 | + | testbraille.MustCopyTo(bc, c) |
| 774 | + | |
| 775 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 776 | + | |
| 777 | + | testdraw.MustText( |
| 778 | + | c, |
| 779 | + | "hi", |
| 780 | + | image.Point{2, 6}, |
| 781 | + | draw.TextCellOpts( |
| 782 | + | cell.FgColor(cell.ColorRed), |
| 783 | + | cell.BgColor(cell.ColorBlue), |
| 784 | + | ), |
| 785 | + | ) |
| 786 | + | |
| 787 | + | testcanvas.MustApply(c, ft) |
| 788 | + | return ft |
| 789 | + | }, |
| 790 | + | }, |
| 791 | + | { |
| 792 | + | desc: "text label too long, gets trimmed", |
| 793 | + | opts: []Option{ |
| 794 | + | Label( |
| 795 | + | "hello world", |
| 796 | + | ), |
| 797 | + | }, |
| 798 | + | canvas: image.Rect(0, 0, 7, 7), |
| 799 | + | update: func(d *Donut) error { |
| 800 | + | return d.Percent(100, HolePercent(80)) |
| 801 | + | }, |
| 802 | + | want: func(size image.Point) *faketerm.Terminal { |
| 803 | + | ft := faketerm.MustNew(size) |
| 804 | + | c := testcanvas.MustNew(ft.Area()) |
| 805 | + | bc := testbraille.MustNew(c.Area()) |
| 806 | + | |
| 807 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled()) |
| 808 | + | testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, |
| 809 | + | draw.BrailleCircleFilled(), |
| 810 | + | draw.BrailleCircleClearPixels(), |
| 811 | + | ) |
| 812 | + | testbraille.MustCopyTo(bc, c) |
| 813 | + | |
| 814 | + | testdraw.MustText(c, "100%", image.Point{2, 3}) |
| 815 | + | |
| 816 | + | testdraw.MustText(c, "hello â¦", image.Point{0, 6}) |
575 | 817 | | |
576 | 818 | | testcanvas.MustApply(c, ft) |
577 | 819 | | return ft |
| skipped 100 lines |