… | |
… | |
5 | sub on_init { |
5 | sub on_init { |
6 | my ($self) = @_; |
6 | my ($self) = @_; |
7 | |
7 | |
8 | my $hotkey = $self->{argv}[0] || "M-s"; |
8 | my $hotkey = $self->{argv}[0] || "M-s"; |
9 | |
9 | |
10 | $self->parse_keysym ($hotkey, "perl:searchable-scrollback:enter") |
10 | $self->parse_keysym ($hotkey, "perl:searchable-scrollback:start") |
11 | or warn "unable to register '$hotkey' as scrollback search enter hotkey\n"; |
11 | or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; |
12 | |
12 | |
13 | () |
13 | () |
14 | } |
14 | } |
15 | |
15 | |
16 | sub on_keyboard_command { |
16 | sub on_keyboard_command { |
17 | my ($self, $cmd) = @_; |
17 | my ($self, $cmd) = @_; |
18 | |
18 | |
19 | if ($cmd eq "searchable-scrollback:enter") { |
19 | if ($cmd eq "searchable-scrollback:start") { |
20 | $self->enter; |
20 | $self->enter; |
21 | } |
21 | } |
22 | |
22 | |
23 | () |
23 | () |
24 | } |
24 | } |
… | |
… | |
37 | |
37 | |
38 | $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EVENT_NONE); |
38 | $self->{pty_ev_events} = $self->pty_ev_events (urxvt::EVENT_NONE); |
39 | $self->{view_start} = $self->view_start; |
39 | $self->{view_start} = $self->view_start; |
40 | |
40 | |
41 | $self->enable ( |
41 | $self->enable ( |
|
|
42 | key_press => \&key_press, |
42 | refresh_begin => sub { |
43 | refresh_begin => \&refresh, |
43 | warn "beg(@_)\n"; |
44 | refresh_end => \&refresh, |
44 | }, |
|
|
45 | refresh_end => sub { |
|
|
46 | warn "end(@_)\n"; |
|
|
47 | }, |
|
|
48 | ); |
45 | ); |
49 | |
46 | |
50 | $self->idle; |
47 | $self->idle; |
51 | } |
48 | } |
52 | |
49 | |
53 | sub leave { |
50 | sub leave { |
54 | my ($self) = @_; |
51 | my ($self) = @_; |
55 | |
52 | |
56 | delete $self->{overlay}; |
53 | delete $self->{overlay}; |
57 | |
54 | |
58 | $self->disable ("refresh_begin", "refresh_end"); |
55 | $self->disable ("key_press", "refresh_begin", "refresh_end"); |
59 | |
56 | |
60 | $self->pty_ev_events ($self->{pty_ev_events}); |
57 | $self->pty_ev_events ($self->{pty_ev_events}); |
61 | $self->want_refresh; |
58 | $self->want_refresh; |
62 | } |
59 | } |
63 | |
60 | |
64 | sub idle { |
61 | sub idle { |
65 | my ($self) = @_; |
62 | my ($self) = @_; |
66 | |
63 | |
67 | $self->msg ("scrollback search, escape=exit, enter=accept, /=start search, n=next, p=previous"); |
64 | $self->msg ("scrollback search, escape=exit, enter=accept, /=start search, n=next, p=previous, G=bottom"); |
68 | |
65 | |
69 | delete $self->{in_search}; |
66 | delete $self->{in_search}; |
70 | } |
67 | } |
71 | |
68 | |
72 | sub search { |
69 | sub search { |
… | |
… | |
84 | or last; |
81 | or last; |
85 | |
82 | |
86 | my $text = $line->t; |
83 | my $text = $line->t; |
87 | if ($text =~ /$re/g) { |
84 | if ($text =~ /$re/g) { |
88 | do { |
85 | do { |
89 | push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[1])]; |
86 | push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; |
90 | } while $text =~ /$re/g; |
87 | } while $text =~ /$re/g; |
91 | |
88 | |
92 | $self->view_start (-$row + ($self->nrow >> 1)); |
89 | $self->view_start (-$row + ($self->nrow >> 1)); |
93 | last; |
90 | last; |
94 | } |
91 | } |
95 | |
92 | |
96 | $row = $line->beg - 1; |
93 | $row = $line->beg - 1; |
97 | } |
94 | } |
98 | |
95 | |
99 | $self->msg ("enter/type/backspace: /$self->{search}_" |
96 | $self->msg ("enter/type/backspace: /$self->{search}_" |
100 | . ($self->{found} ? " (not found)" : "")); |
97 | . ($self->{found} ? "" : " (not found)")); |
101 | $self->scr_bell unless $self->{found}; |
98 | $self->scr_bell unless $self->{found}; |
102 | } |
99 | } |
103 | |
100 | |
|
|
101 | sub refresh { |
|
|
102 | my ($self) = @_; |
|
|
103 | |
|
|
104 | return unless $self->{found}; |
|
|
105 | |
|
|
106 | $self->scr_xor_span (@$_) |
|
|
107 | for @{ $self->{found} }; |
|
|
108 | |
|
|
109 | () |
|
|
110 | } |
|
|
111 | |
104 | sub on_key_press { |
112 | sub key_press { |
105 | my ($self, $event, $keysym, $string) = @_; |
113 | my ($self, $event, $keysym, $string) = @_; |
106 | |
|
|
107 | $self->{overlay} |
|
|
108 | or return; |
|
|
109 | |
114 | |
110 | if (exists $self->{in_search}) { |
115 | if (exists $self->{in_search}) { |
111 | if ($keysym == 0xff0d || $keysym == 0xff8d) { |
116 | if ($keysym == 0xff0d || $keysym == 0xff8d) { |
112 | delete $self->{in_search}; |
117 | $self->idle; |
113 | } elsif ($keysym == 0xff1b) { |
118 | } elsif ($keysym == 0xff1b) { |
114 | $self->view_start (delete $self->{in_search}); |
119 | $self->view_start ($self->{in_search}); |
|
|
120 | $self->idle; |
115 | } elsif ($keysym == 0xff08) { |
121 | } elsif ($keysym == 0xff08) { |
116 | substr $self->{search}, -1, 1, ""; |
122 | substr $self->{search}, -1, 1, ""; |
|
|
123 | |
|
|
124 | $self->search; |
117 | } elsif ($string ne "") { |
125 | } elsif ($string ne "") { |
118 | $self->{search} .= $string; |
126 | $self->{search} .= $string; |
|
|
127 | |
|
|
128 | $self->search; |
119 | } |
129 | } |
120 | |
|
|
121 | $self->search; |
|
|
122 | } else { |
130 | } else { |
123 | if ($keysym == 0xff0d || $keysym == 0xff8d) { |
131 | if ($keysym == 0xff0d || $keysym == 0xff8d) { |
124 | # OK |
132 | # OK |
125 | $self->leave; |
133 | $self->leave; |
126 | } elsif ($keysym == 0xff1b) { |
134 | } elsif ($keysym == 0xff1b) { |
… | |
… | |
131 | } elsif ($keysym == 0xff54) { |
139 | } elsif ($keysym == 0xff54) { |
132 | $self->view_start ($self->view_start - 1); |
140 | $self->view_start ($self->view_start - 1); |
133 | } elsif ($string eq "/") { |
141 | } elsif ($string eq "/") { |
134 | $self->{in_search} = $self->view_start; |
142 | $self->{in_search} = $self->view_start; |
135 | $self->search; |
143 | $self->search; |
|
|
144 | } elsif ($string eq "G") { |
|
|
145 | $self->view_start (0); |
136 | } elsif ($string eq "n") { |
146 | } elsif ($string eq "n") { |
|
|
147 | $self->search; |
137 | } elsif ($string eq "p") { |
148 | } elsif ($string eq "p") { |
|
|
149 | # TODO |
138 | } elsif ($string ne "") { |
150 | } elsif ($string ne "") { |
139 | $self->scr_bell; |
151 | $self->scr_bell; |
140 | } |
152 | } |
141 | } |
153 | } |
142 | |
154 | |