File: fs.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (78 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once

#include "components/config.hpp"
#include "modules/meta/timer_module.hpp"
#include "modules/meta/types.hpp"
#include "settings.hpp"

POLYBAR_NS

namespace modules {
  /**
   * Filesystem structure
   */
  struct fs_mount {
    string mountpoint;
    bool mounted = false;

    string type;
    string fsname;

    uint64_t bytes_free{0ULL};
    uint64_t bytes_used{0ULL};
    uint64_t bytes_avail{0ULL};
    uint64_t bytes_total{0ULL};

    int percentage_free{0};
    int percentage_used{0};

    explicit fs_mount(string mountpoint, bool mounted = false) : mountpoint(move(mountpoint)), mounted(mounted) {}
  };

  using fs_mount_t = unique_ptr<fs_mount>;

  /**
   * Module used to display filesystem stats.
   */
  class fs_module : public timer_module<fs_module> {
   public:
    explicit fs_module(const bar_settings&, string, const config&);

    bool update();
    string get_format() const;
    string get_output();
    bool build(builder* builder, const string& tag) const;

    static constexpr auto TYPE = FS_TYPE;

   private:
    static constexpr auto FORMAT_MOUNTED = "format-mounted";
    static constexpr auto FORMAT_WARN = "format-warn";
    static constexpr auto FORMAT_UNMOUNTED = "format-unmounted";
    static constexpr auto TAG_LABEL_MOUNTED = "<label-mounted>";
    static constexpr auto TAG_LABEL_UNMOUNTED = "<label-unmounted>";
    static constexpr auto TAG_LABEL_WARN = "<label-warn>";
    static constexpr auto TAG_BAR_USED = "<bar-used>";
    static constexpr auto TAG_BAR_FREE = "<bar-free>";
    static constexpr auto TAG_RAMP_CAPACITY = "<ramp-capacity>";

    label_t m_labelmounted;
    label_t m_labelunmounted;
    label_t m_labelwarn;
    progressbar_t m_barused;
    progressbar_t m_barfree;
    ramp_t m_rampcapacity;

    vector<string> m_mountpoints;
    vector<fs_mount_t> m_mounts;
    bool m_fixed{false};
    bool m_remove_unmounted{false};
    spacing_val m_spacing{spacing_type::SPACE, 2U};
    int m_perc_used_warn{90};

    // used while formatting output
    size_t m_index{0_z};
  };
} // namespace modules

POLYBAR_NS_END