aboutsummaryrefslogtreecommitdiffstats
path: root/stat.h
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-21 19:04:31 +0800
committerverdant <im@verdant.ee>2026-07-21 19:04:31 +0800
commitb921e3b0d305f494d37b928ca52995b52b8657f9 (patch)
tree86c1d4e261b1c7f5114a6db1f5d699aeac675d3f /stat.h
parentf77177e2f3ae27c48151a297dd0a4b36101038a2 (diff)
downloadsf-b921e3b0d305f494d37b928ca52995b52b8657f9.tar.gz
sf-b921e3b0d305f494d37b928ca52995b52b8657f9.zip
Add status information manager
Diffstat (limited to 'stat.h')
-rw-r--r--stat.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/stat.h b/stat.h
new file mode 100644
index 0000000..81d84cc
--- /dev/null
+++ b/stat.h
@@ -0,0 +1,57 @@
+#ifndef SF_STAT_H
+#define SF_STAT_H
+
+#include <ncurses.h>
+
+#define PROC_PATH_VERSION "/proc/version"
+#define PROC_PATH_MEMINFO "/proc/meminfo"
+#define PROC_PATH_STAT "/proc/stat"
+
+#define STAT_INFO_WIDTH 15
+#define BAR_LABEL_WIDTH 7
+#define STAT_BAR_HEIGHT 1
+
+typedef struct {
+ char name[16];
+ unsigned int user; /* User mode */
+ unsigned int nice; /* Low-priority user mode */
+ unsigned int system; /* Kernel mode */
+ unsigned int idle; /* Free time of CPU */
+} cpu_occupy;
+
+typedef struct {
+ char sysver[30];
+ struct {
+ unsigned long mem_total;
+ unsigned long mem_available;
+ } meminfo;
+ struct {
+ unsigned long long disk_total;
+ unsigned long long disk_available;
+ } diskinfo;
+ struct {
+ char name[16];
+ unsigned long long user; /* User mode */
+ unsigned long long nice; /* Low-priority user mode */
+ unsigned long long system; /* Kernel mode */
+ unsigned long long idle; /* Free time of CPU */
+ double cpu;
+ } cpu_occupy;
+} stat;
+
+void stat_get_sysver(stat* s);
+stat* stat_init();
+void stat_print_info(WINDOW* w, int y, int maxx, const char* label,
+ unsigned long total, unsigned long ava);
+void stat_print_cpu_info(WINDOW* w, int y, int maxx, stat* s);
+void stat_draw_bar(WINDOW* w, const char* label, int maxx, int y, int x,
+ unsigned long total, unsigned long ava);
+void stat_draw_cpu_bar(WINDOW* w, int maxx, int y, int x, stat* s);
+void stat_get_meminfo(stat* s);
+void stat_get_diskinfo(stat* s);
+void stat_get_cpuinfo(stat* s);
+void stat_calc_cpuocc(stat* s);
+int stat_get_bar_ticks(int maxx, unsigned long long total,
+ unsigned long long ava);
+
+#endif /* SF_STAT_H */