From 8ed2407463cae6e43060fdefa4ebc96ea648b7dd Mon Sep 17 00:00:00 2001 From: zegonix Date: Tue, 6 Oct 2026 20:49:15 +0200 Subject: [PATCH] started implementing a configuration --- Makefile | 3 ++- inc/config.h | 17 +++++++++++++++++ inc/format.h | 10 +++++----- src/format.c | 4 ++-- src/main.c | 21 ++++++++++++++++----- 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 inc/config.h diff --git a/Makefile b/Makefile index fda9399..fb6268d 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,8 @@ C_SRC := main.c \ log.c \ arguments.c \ stringing.c \ - sorting.c + sorting.c \ + format.c C_FLAGS := -std=c11 \ $(WG) \ diff --git a/inc/config.h b/inc/config.h new file mode 100644 index 0000000..0498dbb --- /dev/null +++ b/inc/config.h @@ -0,0 +1,17 @@ +/* ------------------------------------------------------------------ + * -- project: SCAN + * -- description: abstraction for terminal control sequences + * ------------------------------------------------------------------ + */ + +#ifndef __CONFIG_H +#define __CONFIG_H + +#include "format.h" + +/* -- colour and style configuration */ +#define DIR_STYLE_NUM ( ( int )1 ) +const style_t directory_style[DIR_STYLE_NUM] = { style_bold }; +const uint32_t directory_colour = 0x6CA05C; + +#endif diff --git a/inc/format.h b/inc/format.h index fbc2a21..2eb104a 100644 --- a/inc/format.h +++ b/inc/format.h @@ -7,12 +7,11 @@ #ifndef __FORMAT_H #define __FORMAT_H -#include "stdint.h" +#include /* -- defines */ #define NUMBER_STYLES ( ( int )8 ) -#define NUMBER_COLOURS ( ( int )9 ) #define ESCAPE "\x1b" #define SEQUENCE_PREFIX ESCAPE"[" #define SEQUENCE_SUFFIX "m" @@ -26,7 +25,8 @@ typedef enum { style_blinking, style_reversed, style_invisible, - style_strikethrough + style_strikethrough, + style_end = NUMBER_STYLES } style_t; @@ -36,8 +36,8 @@ extern const uint8_t STYLE_RESET[ NUMBER_STYLES ]; /* -- function prototypes */ void format_clear( void ); -void format_set_style( style_t* styles, uint8_t number_styles ); -void format_reset_style( style_t* styles, uint8_t number_styles ); +void format_set_style( const style_t* const styles, uint8_t number_styles ); +void format_reset_style( const style_t* const styles, uint8_t number_styles ); void format_set_fg_colour( uint32_t colour ); void format_set_bg_colour( uint32_t colour ); void format_clear_fg_colour( void ); diff --git a/src/format.c b/src/format.c index c2f06c8..ade72e5 100644 --- a/src/format.c +++ b/src/format.c @@ -13,7 +13,7 @@ void format_clear( void ) fprintf( stdout, SEQUENCE_PREFIX"0"SEQUENCE_SUFFIX ); } -void format_set_style( style_t* styles, uint8_t number ) +void format_set_style( const style_t* const styles, uint8_t number ) { if ( NUMBER_STYLES < number ) return; @@ -34,7 +34,7 @@ void format_set_style( style_t* styles, uint8_t number ) fprintf( stdout, SEQUENCE_SUFFIX ); } -void format_reset_style( style_t* styles, uint8_t number ) +void format_reset_style( const style_t* const styles, uint8_t number ) { if ( NUMBER_STYLES < number ) return; diff --git a/src/main.c b/src/main.c index 3a8e5a7..d2c1b23 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,8 @@ #include "arguments.h" #include "type_definitions.h" #include "sorting.h" +#include "format.h" +#include "config.h" // macro definitions #define SUCCESS 0 @@ -378,11 +380,20 @@ int display_directory_contents( tree[ 4 * recursion_level + 2 ] = '-'; tree[ 4 * recursion_level + 3 ] = ' '; - log_info( - "%s%s", - tree, - entry->name - ); + fprintf( stdout, "%s", tree ); + + if ( entry->type == type_directory ) + { + format_set_style( directory_style, DIR_STYLE_NUM ); + format_set_fg_colour( directory_colour ); + } + fprintf( stdout, "%s", entry->name ); + if ( entry->type == type_directory ) + { + format_reset_style( directory_style, DIR_STYLE_NUM ); + format_clear_fg_colour(); + } + fprintf( stdout, "\n" ); if ( recursion_level < args->depth && entry->type == type_directory )