1Curses::UI::Searchable(U3s)er Contributed Perl DocumentatCiuornses::UI::Searchable(3)
2
3
4

NAME

6       Curses::UI::Searchable - Add 'less'-like search abilities to a widget
7

CLASS HIERARCHY

9        Curses::UI::Searchable - base class
10

SYNOPSIS

12           package MyWidget;
13
14           use Curses::UI::Searchable;
15           use vars qw(@ISA);
16           @ISA = qw(Curses::UI::Searchable);
17
18           ....
19
20           sub new () {
21               # Create class instance $this.
22               ....
23
24               $this->set_routine('search-forward', \&search_forward);
25               $this->set_binding('search-forward', '/');
26               $this->set_routine('search-backward', \&search_backward);
27               $this->set_binding('search-backward', '?');
28           }
29
30           sub layout_content() {
31               my $this = shift;
32
33               # Layout your widget's content.
34               ....
35
36               return $this;
37           }
38
39           sub number_of_lines() {
40               my $this = shift;
41
42               # Return the number of lines in
43               # the widget's content.
44               return ....
45           }
46
47           sub getline_at_ypos($;) {
48               my $this = shift;
49               my $ypos = shift;
50
51               # Return the content on the line
52               # where ypos = $ypos
53               return ....
54           }
55

DESCRIPTION

57       Using Curses::UI::Searchable, you can add 'less'-like search
58       capabilities to your widget.
59
60       To make your widget searchable using this class, your widget should
61       meet the following requirements:
62
63       ·   make it a descendant of Curses::UI::Searchable
64
65           All methods for searching are in Curses::UI::Searchable.  By making
66           your class a descendant of this class, these methods are
67           automatically inherited.
68
69       ·   -ypos data member
70
71           The current vertical position in the widget should be identified by
72           $this->{-ypos}. This y-position is the index of the line of
73           content. Here's an example for a Listbox widget.
74
75            -ypos
76              |
77              v
78                  +------+
79              0   |One   |
80              1   |Two   |
81              2   |Three |
82                  +------+
83
84       ·   method: number_of_lines ( )
85
86           Your widget class should have a method number_of_lines, which
87           returns the total number of lines in the widget's content. So in
88           the example above, this method would return the value 3.
89
90       ·   method: getline_at_ypos ( YPOS )
91
92           Your widget class should have a method getline_at_ypos, which
93           returns the line of content at -ypos YPOS.  So in the example
94           above, this method would return the value "Two" for YPOS = 1.
95
96       ·   method: layout_content ( )
97
98           The search routines will set the -ypos of your widget if a match is
99           found for the given search string. Your layout_content routine
100           should make sure that the line of content at -ypos will be made
101           visible if the draw method is called.
102
103       ·   method: draw ( )
104
105           If the search routines find a match, $this->{-search_highlight}
106           will be set to the -ypos for the line on which the match was found.
107           If no match was found $this->{-search_highlight} will be undefined.
108           If you want a matching line to be highlighted, in your widget, you
109           can use this data member to do so (an example of a widget that uses
110           this option is the Curses::UI::TextViewer widget).
111
112       ·   bindings for searchroutines
113
114           There are two search routines. These are search_forward and
115           search_backward. These have to be called in order to display the
116           search prompt. The best way to do this is by creating bindings for
117           them. Here's an example which will make '/' a forward search and
118           '?' a backward search:
119
120               $this->set_routine('search-forward'  , \&search_forward);
121               $this->set_binding('search-forward'  , '/');
122               $this->set_routine('search-backward' , \&search_backward);
123               $this->set_binding('search-backward' , '?');
124

SEE ALSO

126       Curses::UI,
127

AUTHOR

129       Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
130
131       Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
132
133       This package is free software and is provided "as is" without express
134       or implied warranty. It may be used, redistributed and/or modified
135       under the same terms as perl itself.
136
137
138
139perl v5.30.0                      2019-07-26         Curses::UI::Searchable(3)
Impressum