1 #pragma once
2 
3 #include "modules/meta/base.hpp"
4 #include "utils/command.hpp"
5 #include "utils/io.hpp"
6 
7 POLYBAR_NS
8 
9 namespace modules {
10   class script_module : public module<script_module> {
11    public:
12     explicit script_module(const bar_settings&, string);
~script_module()13     ~script_module() {}
14 
15     void start();
16     void stop();
17 
18     string get_output();
19     bool build(builder* builder, const string& tag) const;
20 
21     static constexpr auto TYPE = "custom/script";
22 
23    protected:
24     chrono::duration<double> process(const mutex_wrapper<function<chrono::duration<double>()>>& handler) const;
25     bool check_condition();
26 
27    private:
28     static constexpr const char* TAG_LABEL{"<label>"};
29 
30     mutex_wrapper<function<chrono::duration<double>()>> m_handler;
31 
32     unique_ptr<command<output_policy::REDIRECTED>> m_command;
33 
34     bool m_tail;
35 
36     string m_exec;
37     string m_exec_if;
38 
39     chrono::duration<double> m_interval{0};
40     map<mousebtn, string> m_actions;
41 
42     label_t m_label;
43     string m_output;
44     string m_prev;
45     int m_counter{0};
46 
47     bool m_stopping{false};
48   };
49 }  // namespace modules
50 
51 POLYBAR_NS_END
52