1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/usr/bin/perl
use v5.26;
use warnings;
use Test2::V0;
use Tickit::Test 0.12;
use Tickit::Widget::Scroller;
use Tickit::Widget::Scroller::Item::Text;
# TODO: mk_window once Tickit::Test can take a size there too
my ( $term, $rootwin ) = mk_term_and_window cols => 20, lines => 8;
my $win = $rootwin->make_sub( 0, 0, 6, 20 );
$rootwin->focus( 7, 0 );
my $scroller = Tickit::Widget::Scroller->new(
gravity => "bottom",
);
$scroller->set_window( $win );
$scroller->unshift(
Tickit::Widget::Scroller::Item::Text->new( "Existing line $_" ),
) for 1 .. 20;
flush_tickit;
is_termlog( [ ( map { SETBG(undef),
SCROLLRECT(0,0,6,20, -1,0) } 1 .. 5, ),
( map { GOTO(6-$_,0),
SETPEN,
PRINT("Existing line $_"),
SETBG(undef),
ERASECH(5) } reverse 1 .. 6 ),
GOTO(7,0) ],
'Termlog initially' );
is_display( [ [TEXT("Existing line 6")],
[TEXT("Existing line 5")],
[TEXT("Existing line 4")],
[TEXT("Existing line 3")],
[TEXT("Existing line 2")],
[TEXT("Existing line 1")] ],
'Display initially' );
is_cursorpos( 7, 0, 'Cursor position intially' );
my ( $item ) = $scroller->pop;
isa_ok( $item, "Tickit::Widget::Scroller::Item::Text" );
flush_tickit;
is_termlog( [ SETBG(undef),
SCROLLRECT(0,0,6,20, -1,0),
GOTO(0,0),
SETPEN,
PRINT("Existing line 7"),
SETBG(undef),
ERASECH(5),
GOTO(7,0) ],
'Termlog after pop' );
is_display( [ [TEXT("Existing line 7")],
[TEXT("Existing line 6")],
[TEXT("Existing line 5")],
[TEXT("Existing line 4")],
[TEXT("Existing line 3")],
[TEXT("Existing line 2")] ],
'Display after pop' );
is_cursorpos( 7, 0, 'Cursor position after pop' );
$scroller->pop( 3 );
flush_tickit;
is_termlog( [ SETBG(undef),
SCROLLRECT(0,0,6,20, -3,0),
GOTO(0,0),
SETPEN,
PRINT("Existing line 10"),
SETBG(undef),
ERASECH(4),
GOTO(1,0),
SETPEN,
PRINT("Existing line 9"),
SETBG(undef),
ERASECH(5),
GOTO(2,0),
SETPEN,
PRINT("Existing line 8"),
SETBG(undef),
ERASECH(5),
GOTO(7,0) ],
'Termlog after pop 3' );
is_display( [ [TEXT("Existing line 10")],
[TEXT("Existing line 9")],
[TEXT("Existing line 8")],
[TEXT("Existing line 7")],
[TEXT("Existing line 6")],
[TEXT("Existing line 5")] ],
'Display after pop 3' );
is_cursorpos( 7, 0, 'Cursor position after pop 3' );
$scroller->scroll_to_top;
flush_tickit;
drain_termlog;
is_display( [ [TEXT("Existing line 20")],
[TEXT("Existing line 19")],
[TEXT("Existing line 18")],
[TEXT("Existing line 17")],
[TEXT("Existing line 16")],
[TEXT("Existing line 15")] ],
'Display after scroll_to_top' );
$scroller->pop;
flush_tickit;
is_termlog( [],
'Termlog empty after pop at top' );
is_display( [ [TEXT("Existing line 20")],
[TEXT("Existing line 19")],
[TEXT("Existing line 18")],
[TEXT("Existing line 17")],
[TEXT("Existing line 16")],
[TEXT("Existing line 15")] ],
'Display unchanged after pop at top' );
$scroller->scroll_to_bottom;
flush_tickit;
drain_termlog;
is_display( [ [TEXT("Existing line 11")],
[TEXT("Existing line 10")],
[TEXT("Existing line 9")],
[TEXT("Existing line 8")],
[TEXT("Existing line 7")],
[TEXT("Existing line 6")] ],
'Display after scroll_to_bottom' );
$scroller->pop( 6 );
flush_tickit;
is_termlog( [ ( map { GOTO(17-$_,0),
SETPEN,
PRINT("Existing line $_"),
SETBG(undef),
ERASECH(4) } reverse 12 .. 17 ),
GOTO(7,0) ],
'Termlog after pop 6 at bottom' );
is_display( [ [TEXT("Existing line 17")],
[TEXT("Existing line 16")],
[TEXT("Existing line 15")],
[TEXT("Existing line 14")],
[TEXT("Existing line 13")],
[TEXT("Existing line 12")] ],
'Display after pop 6 at bottom' );
done_testing;
|