1 /**
2  * Copyright (c) 2007-2012, 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 lnav_bottom_status_source_hh
31 #define lnav_bottom_status_source_hh
32 
33 #include <string>
34 
35 #include "grep_proc.hh"
36 #include "textview_curses.hh"
37 #include "logfile_sub_source.hh"
38 #include "statusview_curses.hh"
39 
40 class bottom_status_source
41     : public status_data_source,
42       public grep_proc_control {
43 public:
44     typedef enum {
45         BSF_LINE_NUMBER,
46         BSF_PERCENT,
47         BSF_HITS,
48         BSF_SEARCH_TERM,
49         BSF_LOADING,
50         BSF_HELP,
51 
52         BSF__MAX
53     } field_t;
54 
55     bottom_status_source();
56 
get_field(field_t id)57     status_field &get_field(field_t id) { return this->bss_fields[id]; };
58 
set_prompt(const std::string & prompt)59     void set_prompt(const std::string &prompt)
60     {
61         this->bss_prompt.set_value(prompt);
62     };
63 
grep_error(const std::string & msg)64     void grep_error(const std::string& msg) override
65     {
66         this->bss_error.set_value(msg);
67     };
68 
69     size_t statusview_fields() override;
70 
71     status_field &statusview_value_for_field(int field) override;
72 
73     void update_line_number(listview_curses *lc);
74 
75     void update_search_term(textview_curses &tc);
76 
77     void update_percent(listview_curses *lc);
78 
79     void update_marks(listview_curses *lc);
80 
81     void update_hits(textview_curses *tc);
82 
83     void update_loading(file_off_t off, file_size_t total);
84 
85 private:
86     status_field bss_prompt{1024, view_colors::VCR_STATUS};
87     status_field bss_error{1024, view_colors::VCR_ALERT_STATUS};
88     status_field bss_line_error{1024, view_colors::VCR_ALERT_STATUS};
89     status_field bss_fields[BSF__MAX];
90     int          bss_hit_spinner{0};
91     int          bss_load_percent{0};
92     bool         bss_paused{false};
93 };
94 
95 #endif
96