Created
December 31, 2024 16:50
-
-
Save HalanoSiblee/4edf2f46bea7e5ebcaef2bed5156deb2 to your computer and use it in GitHub Desktop.
FLTK partition usage chart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FL/Fl.H> | |
#include <FL/Fl_Window.H> | |
#include <FL/Fl_Chart.H> | |
#include <FL/Fl_Box.H> | |
#include <charconv> | |
#include <ostream> | |
#include <sstream> | |
#include <iostream> | |
#include <string.h> | |
#include <sys/statvfs.h> | |
using namespace std; | |
int main(int argc, char* argv[]) { | |
Fl_Window* window = new Fl_Window(Fl::w()/2, Fl::h()-50, "Fast Light Disk Usage Analysis"); | |
struct statvfs stat; | |
if (statvfs("/", &stat) != 0) { | |
fprintf(stderr, "Error: Could not get disk space information.\n"); | |
return 1; | |
} | |
// Fl_Color darga = fl_rgb_color(41, 41, 41); | |
window->resizable(window);window->color(fl_rgb_color(41, 41, 41));window->position(Fl::w() / 2 - window->w() / 2, Fl::h() / 2 - window->h() / 2); | |
unsigned long long total_space = stat.f_blocks * stat.f_frsize; | |
unsigned long long free_space = stat.f_bfree * stat.f_frsize; | |
unsigned long long used_space = total_space - free_space; | |
// Create a line chart | |
cout<<Fl::h()/2; | |
Fl_Chart* chart = new Fl_Chart(0, 0,window->w(),window->h()/2); | |
chart->type(FL_PIE_CHART);chart->autosize(1);chart->color(0);chart->box(FL_NO_BOX);chart->textcolor(FL_WHITE); | |
double free_percentage = (double)free_space / total_space * 100; | |
double used_percentage = 100 - free_percentage; | |
std::stringstream ss; | |
ss << free_percentage<<"%"<<" Free"; | |
std::string str = ss.str(); | |
ss.str(""); | |
ss << used_percentage<<"%"<<" Used"; | |
std::string str2 = ss.str(); | |
chart->add(free_percentage,str.c_str(),0);chart->add(used_percentage, str2.c_str(),FL_WHITE); | |
double total_gb = static_cast<double>(total_space) / (1024 * 1024 * 1024); | |
char disk_space_str[32]; | |
// snprintf(disk_space_str, sizeof(disk_space_str), "%.2f GB", total_gb); | |
Fl_Box* pstatics = new Fl_Box(0, window->h()/2, window->w(), 20,". . ."); | |
// pstatics->labelcolor(); | |
window->end(); | |
window->show(); | |
return Fl::run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment