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
79
80
81
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
* vfetch - neofetch but the ascii part is a video
*
* Copyright (C) 2026 Doan Luu Duc Tai
*
*/
#ifndef SRC__UTILS_H
#define SRC__UTILS_H
#include <glib.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include "error.h"
#include "state.h"
#include "video_defs.h"
struct FTW;
struct stat;
typedef struct Rect {
size_t width;
size_t height;
uint32_t start_x;
uint32_t start_y;
} Rect;
#ifdef __GNUC__
# define ATTR_PRINTF_FORMAT(FMT_POS, ARG_POS) \
__attribute__((format(printf, FMT_POS, ARG_POS)))
#else
# define ATTR_PRINTF_FORMAT(FMT_POS, ARG_POS)
#endif
void log_debug(bool debug_flag, const char *format, ...)
ATTR_PRINTF_FORMAT(2, 3);
void log_verbose(AppState *state,
bool verbose_flag,
bool debug_flag,
const char *format,
...) ATTR_PRINTF_FORMAT(4, 5);
#undef ATTR_PRINTF_FORMAT
void log_vfetch_error(VfetchError err, const char *context_msg);
_Noreturn void die(VfetchError err, const char *context_msg);
void print_progress(AppState *state, size_t current, size_t total);
void *progress_display_thread_func(void *arg);
void restore_terminal(void);
void setup_terminal(AppState *state);
void set_cursor_visible(AppState *state, bool visible);
void append_block_to_buffer(char *buffer,
size_t buffer_size,
size_t *current_len,
uint32_t start_x,
uint32_t start_y,
const char *text_block,
size_t text_block_len);
void clear_rect_in_buffer(char *buffer,
size_t buffer_size,
size_t *current_len,
const Rect *rect);
VfetchError
run_command_fork_output(const gchar *command, gchar **output, bool debug_flag);
int unlink_cb(const char *fpath,
const struct stat *stat_buf,
int typeflag,
struct FTW *ftwbuf);
bool rm_rf(const char *path);
void hash_string_to_bytes(const char *str, uint8_t *out_bytes);
gchar *hash_cache_key(const CacheKey *key);
int compare_strings_wrapper(gconstpointer first_pointer,
gconstpointer second_pointer);
gchar *serialize_map_for_hashing(GHashTable *map);
guint32 parse_hex_color(const char *hex_str);
size_t count_lines(const gchar *str);
void *signal_monitor_thread_func(void *arg);
void app_signal_handler(int signum, siginfo_t *info, void *context);
void app_resize_handler(int signum, siginfo_t *info, void *context);
#endif /* SRC__UTILS_H */
|