Skip to content

Commit

Permalink
separated wrappers into a separate file, added swap
Browse files Browse the repository at this point in the history
  • Loading branch information
alba4k committed Jan 2, 2025
1 parent 175b0fe commit f6dd4ed
Show file tree
Hide file tree
Showing 34 changed files with 391 additions and 291 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
## New Features

### Modules
* Added a `swap` module that prints the used and total swap on linux

### Config syntax
* Custom ascii arts will now print in the specified color by default
* Added `swap_label`, the label for the new swa module
* Added `swap_perc`, whether the used swap percentage should be printed

### Command line arguments
* Added `--version` (`-v` for short), prints version and build commit
Expand All @@ -19,12 +22,13 @@
### Noticeable fixes
* Packages should be counted faster for dpkg and especially snap
* Alacritty will now be properly recognized even with `general.ipc_socket = false`
* `gpu` should now print all gpus even when libpci doesn't work

### Technical fixes
* Reduced the size of default logos
* Moved some functions from `src/utils.c` to `src/config/config.c` and `src/config/config.c`.
Planning on rewriting config parsing and reducing `src/utils.c` even more.
* Memory safety improvements in packages
* Moved some functions from `src/utils/utils.c` to `src/config/config.c` and `src/config/config.c`.
Planning on rewriting config parsing and reducing `src/utils/utils.c` even more.
* Minor memory safety improvements

## Dependencies
* sqlite3 is now needed to build the project
Expand Down
11 changes: 8 additions & 3 deletions albafetch.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Check https://github.com/alba4k/albafetch/blob/master/MANUAL.md for additional info.

# My (the authors) personal configuration can be found here:
# https://github.com/alba4k/.dotfiles/blob/master/.config/albafetch.conf

# https://github.com/alba4k/.dotfiles/blob/master/.config/albafetch/albafetch.conf

# CONFIGURATION OPTIONS:

Expand Down Expand Up @@ -68,9 +67,9 @@ modules = {
; "pwd", # current working directory
; "date", # date and time
; "battery", # battery percentage and status (Linux only)
; "swap", # swap usage and percentage (Linux only)
}


# MODULE-SPECIFIC OPTIONS:

# Separators
Expand Down Expand Up @@ -193,6 +192,12 @@ mem_prefix = "Memory" ; str [64]
# whether the percentage of used memory should be printed
mem_perc = "true" ; bool

# Swap
# the prefix printed before the swap
swap_prefix = "Swap" ; str [64]
# whether the percentage of used swap should be printed
swap_perc = "true" ; bool

# IPs
# the prefix printed before the public IP
pub_prefix = "Public IP" ; str [64]
Expand Down
14 changes: 8 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ project(
)

src = [
'src/utils/queue.c',
'src/utils/utils.c',
'src/optdeps/libpci.c',
'src/optdeps/glib.c',
'src/config/config.c',
'src/config/parsing.c',
'src/info/battery.c',
'src/info/bios.c',
'src/info/colors.c',
'src/info/cpu.c',
'src/info/cursor_theme.c',
'src/info/date.c',
'src/info/desktop.c',
'src/info/gpu.c',
'src/info/gtk_theme.c',
'src/info/icon_theme.c',
'src/info/cursor_theme.c',
'src/info/host.c',
'src/info/hostname.c',
'src/info/icon_theme.c',
'src/info/info.h',
'src/info/kernel.c',
'src/info/light_colors.c',
Expand All @@ -37,9 +33,15 @@ src = [
'src/info/public_ip.c',
'src/info/pwd.c',
'src/info/shell.c',
'src/info/swap.c',
'src/info/term.c',
'src/info/uptime.c',
'src/info/user.c',
'src/optdeps/glib.c',
'src/optdeps/libpci.c',
'src/utils/queue.c',
'src/utils/utils.c',
'src/utils/wrappers.c',
]

build_args = [
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void parse_config(const char *file, struct Module *modules, void **ascii_ptr, bo
"kernel_type",
"col_background",
"bat_status"
"swap_perc"
};

bool buffer;
Expand Down Expand Up @@ -278,6 +279,7 @@ void parse_config(const char *file, struct Module *modules, void **ascii_ptr, bo
{config.cpu_prefix, "cpu_prefix"},
{config.gpu_prefix, "gpu_prefix"},
{config.mem_prefix, "mem_prefix"},
{config.swap_prefix, "swap_prefix"},
{config.pub_prefix, "pub_prefix"},
{config.loc_prefix, "loc_prefix"},
{config.pwd_prefix, "pwd_prefix"},
Expand Down
47 changes: 25 additions & 22 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@ struct Config {
* 2. _title_color
* 3. _os_arch
* 4. _kernel_short
* 5. de_type
* 6. shell_path
* 7. term_ssh
* 8. pkg_mgr
* 9. pkg_pacman
* 10. pkg_dpkg
* 11. pkg_rpm
* 12. pkg_flatpak
* 13. pkg_snap
* 14. pkg_brew
* 15. pkg_pip
* 16. cpu_brand
* 17. cpu_freq
* 18. cpu_count
* 19. gpu_brand
* 20. mem_perc
* 21. loc_localhost
* 22. loc_docker
* 23. pwd_path
* 24. col_background
* 25. bat_status
* 26. [...]
* 5. _de_type
* 6. _shell_path
* 7. _term_ssh
* 8. _pkg_mgr
* 9. _pkg_pacman
* 10. _pkg_dpkg
* 11. _pkg_rpm
* 12. _pkg_flatpak
* 13. _pkg_snap
* 14. _pkg_brew
* 15. _pkg_pip
* 16. _cpu_brand
* 17. _cpu_freq
* 18. _cpu_count
* 19. _gpu_brand
* 20. _mem_perc
* 21. _loc_localhost
* 22. _loc_docker
* 23. _pwd_path
* 24. _col_background
* 25. _bat_status
* 26. _swap_perc
* [...]
*/
uint64_t boolean_options;

Expand Down Expand Up @@ -68,6 +69,7 @@ struct Config {
char cpu_prefix[64];
char gpu_prefix[64];
char mem_prefix[64];
char swap_prefix[64];
char pub_prefix[64];
char loc_prefix[64];
char pwd_prefix[64];
Expand Down Expand Up @@ -105,5 +107,6 @@ extern struct Config config;
#define _kernel_type config.boolean_options & 0x1000000
#define _col_background config.boolean_options & 0x2000000
#define _bat_status config.boolean_options & 0x4000000
#define _swap_perc config.boolean_options & 0x8000000

void parse_config(const char *file, struct Module *modules, void **ascii_ptr, bool *default_bold, char *default_color, char *default_logo);
1 change: 1 addition & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int main(int argc, char **argv) {
{cpu, "cpu"},
{gpu, "gpu"},
{memory, "memory"},
{swap, "swap"},
{public_ip, "public_ip"},
{local_ip, "local_ip"},
{pwd, "pwd"},
Expand Down
13 changes: 7 additions & 6 deletions src/info/battery.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include "info.h"
#include "../config/config.h"

#include <stdbool.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -9,6 +6,10 @@
#include <ctype.h>
#endif // __ANDROID__

#include "info.h"
#include "../config/config.h"
#include "../utils/wrappers.h"

// get the battery percentage and status (Linux only!)
int battery(char *dest) {
char capacity[5] = "";
Expand All @@ -28,7 +29,7 @@ int battery(char *dest) {
end = strchr(ptr, ',');
if(end != NULL) {
*end = 0;
strncpy(capacity, ptr, 5);
safe_strncpy(capacity, ptr, 5);
}
}

Expand All @@ -44,7 +45,7 @@ int battery(char *dest) {

if(end != NULL) {
*end = 0;
strncpy(status, ptr2, 20);
safe_strncpy(status, ptr2, 20);
}
}
#else
Expand All @@ -71,7 +72,7 @@ int battery(char *dest) {
else if(capacity[0] != 0)
snprintf(dest, 256, "%s%%", capacity);
else if(status[0] != 0 && (_bat_status))
strncpy(dest, status, 256);
safe_strncpy(dest, status, 256);
else
return 1;

Expand Down
9 changes: 5 additions & 4 deletions src/info/bios.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "info.h"

#include <string.h>

#include <stdio.h>
#include <stdlib.h>

#include "info.h"
#include "../utils/wrappers.h"

// get the current BIOS vendor and version (Linux only!)
int bios(char *dest) {
char *vendor = NULL, *version = NULL;
Expand Down Expand Up @@ -36,9 +37,9 @@ int bios(char *dest) {
if(vendor != NULL && version != NULL)
snprintf(dest, 256, "%s %s", vendor, version);
else if(vendor != NULL)
strncpy(dest, vendor, 256);
safe_strncpy(dest, vendor, 256);
else if(version != NULL)
strncpy(dest, version, 256);
safe_strncpy(dest, version, 256);
else
return 1;

Expand Down
9 changes: 5 additions & 4 deletions src/info/cpu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include "info.h"
#include "../config/config.h"

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -9,6 +6,10 @@
#include <sys/sysctl.h>
#endif // __APPLE__

#include "info.h"
#include "../config/config.h"
#include "../utils/wrappers.h"

// get the cpu name and frequency
int cpu(char *dest) {
char *cpu_info;
Expand Down Expand Up @@ -126,7 +127,7 @@ int cpu(char *dest) {
memmove(end, end+4, strlen(end+1));
}

strncpy(dest, cpu_info, 256);
safe_strncpy(dest, cpu_info, 256);
#ifdef __linux__
free(buf);
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/info/cursor_theme.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <string.h>

#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

#include "info.h"
#include "../optdeps/optdeps.h"
#include "../utils/utils.h"
#include "../utils/wrappers.h"

// get the current Cursor Theme
int cursor_theme(char *dest){
Expand All @@ -27,7 +26,7 @@ int cursor_theme(char *dest){
*ptr = 0;
}

strncpy(dest, buf, 256);
safe_strncpy(dest, buf, 256);
return 0;
}
}
Expand Down
Loading

0 comments on commit f6dd4ed

Please sign in to comment.