aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-06-11 20:24:56 +0000
committerJoursoir <chat@joursoir.net>2021-06-11 20:24:56 +0000
commite41782a1af7c1217589a6c0f3580c8fb955a8c71 (patch)
treedde0eca657843b30ca3b82c3d0d4c42674a217a5
parent7ee736993663501dd0c4754f05fdd32a59977be5 (diff)
downloadlock-password-e41782a1af7c1217589a6c0f3580c8fb955a8c71.tar.gz
lock-password-e41782a1af7c1217589a6c0f3580c8fb955a8c71.tar.bz2
lock-password-e41782a1af7c1217589a6c0f3580c8fb955a8c71.zip
tree: make it possible to control the use of color
-rw-r--r--src/tree.c13
-rw-r--r--src/tree.h2
2 files changed, 9 insertions, 6 deletions
diff --git a/src/tree.c b/src/tree.c
index 9c654d2..63ffd3c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -47,7 +47,7 @@ static void entries_sort(char **entries, const int size)
}
}
-int tree(const char *path, const char *prefix)
+int tree(const char *path, const char *prefix, int use_color)
{
DIR *main_dir;
struct dirent *temp_dirent;
@@ -90,16 +90,19 @@ int tree(const char *path, const char *prefix)
}
full_path = xstrcat(path, entries[i], "/");
+ printf("%s%s", prefix, pointer);
if(file_exist(full_path) == F_ISDIR) {
- printf("%s%s%s%s%s\n", prefix, pointer, ANSIC_BBLU,
- entries[i], ANSIC_RST);
+ printf("%s%s%s\n",
+ (use_color) ? ANSIC_BBLU : "",
+ entries[i],
+ (use_color) ? ANSIC_RST : "");
prefix_depth = xstrcat(prefix, prefix_depth, NULL);
- tree(full_path, prefix_depth);
+ tree(full_path, prefix_depth, use_color);
free(prefix_depth);
}
else
- printf("%s%s%s\n", prefix, pointer, entries[i]);
+ printf("%s\n", entries[i]);
free(entries[i]);
free(full_path);
diff --git a/src/tree.h b/src/tree.h
index 39fbf22..ee9d201 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -19,6 +19,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
***/
-int tree(const char *path, const char *prefix);
+int tree(const char *path, const char *prefix, int use_color);
#endif /* LPASS_TREE_H */ \ No newline at end of file