mirror of
https://github.com/polybar/polybar.git
synced 2026-02-20 21:35:43 +00:00
feat(fs): New filesystem module
Module that displays details about mounted filesystems, #84 Closes #153
This commit is contained in:
@ -157,12 +157,48 @@ namespace string_util {
|
||||
return find_nth(haystack, found_pos + 1, needle, nth - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a float value string
|
||||
*/
|
||||
string floatval(float value, int decimals, bool fixed, string locale) {
|
||||
stringstream ss;
|
||||
ss.precision(decimals);
|
||||
if (!locale.empty())
|
||||
ss.imbue(std::locale(locale.c_str()));
|
||||
if (fixed)
|
||||
ss << std::fixed;
|
||||
ss << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a filesize string
|
||||
*/
|
||||
string filesize(unsigned long long bytes, int decimals, bool fixed, string locale) {
|
||||
vector<string> suffixes{"TB", "GB", "MB"};
|
||||
string suffix{"KB"};
|
||||
|
||||
while ((bytes /= 1000) > 999) {
|
||||
suffix = suffixes.back();
|
||||
suffixes.pop_back();
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss.precision(decimals);
|
||||
if (!locale.empty())
|
||||
ss.imbue(std::locale(locale.c_str()));
|
||||
if (fixed)
|
||||
ss << std::fixed;
|
||||
ss << bytes << " " << suffix;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resulting string from a ostream/
|
||||
*
|
||||
* Example usage:
|
||||
* @code cpp
|
||||
* string_util::from_stream(std::stringstream() << ...);
|
||||
* string_util::from_stream(stringstream() << ...);
|
||||
* @endcode
|
||||
*/
|
||||
string from_stream(const std::basic_ostream<char>& os) {
|
||||
|
||||
Reference in New Issue
Block a user