1 /**
2  * Copyright (c) 2018, Timothy Stack
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of Timothy Stack nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef filter_sub_source_hh
31 #define filter_sub_source_hh
32 
33 #include "readline_curses.hh"
34 #include "textview_curses.hh"
35 #include "plain_text_source.hh"
36 
37 class filter_sub_source
38     : public text_sub_source, public list_input_delegate {
39 public:
40     filter_sub_source();
41 
42     bool list_input_handle_key(listview_curses &lv, int ch) override;
43 
44     void list_input_handle_scroll_out(listview_curses &lv) override;
45 
46     size_t text_line_count() override;
47 
48     size_t text_line_width(textview_curses &curses) override;
49 
50     void
51     text_value_for_line(textview_curses &tc, int line, std::string &value_out,
52                         line_flags_t flags) override;
53 
54     void text_attrs_for_line(textview_curses &tc, int line,
55                              string_attrs_t &value_out) override;
56 
57     size_t
58     text_size_for_line(textview_curses &tc, int line, line_flags_t raw) override;
59 
60     void rl_change(readline_curses *rc);
61 
62     void rl_perform(readline_curses *rc);
63 
64     void rl_abort(readline_curses *rc);
65 
66     void rl_display_matches(readline_curses *rc);
67 
68     void rl_display_next(readline_curses *rc);
69 
70     readline_context fss_regex_context{"filter-regex", nullptr, false};
71     readline_context fss_sql_context{"filter-sql", nullptr, false};
72     readline_curses fss_editor;
73     plain_text_source fss_match_source;
74     textview_curses fss_match_view;
75 
76     bool fss_editing{false};
77     bool fss_filter_state{false};
78 };
79 
80 #endif
81