implemented 'no-colour' feature

This commit is contained in:
root committed 2026-10-09 16:29:48 +02:00
1 parent e37f04a1cd
commit 030ca4584a
3 files changed
+76 -53

No files matched your search

+61 -37
View File
@@ -25,10 +25,14 @@ static void size_to_string(
);
// module logic
void display_type( entry_type_t type )
void display_type( entry_type_t type, bool no_colour )
{
format_set_style( type_style, TYPE_STYLE_NUM );
format_set_colour( type_colour );
if ( !no_colour )
{
format_set_style( type_style, TYPE_STYLE_NUM );
format_set_colour( type_colour );
}
switch ( type )
{
case type_block:
@@ -53,53 +57,69 @@ void display_type( entry_type_t type )
fputc( 's', stdout );
break;
}
format_clear();
format_clear();
fputc( ' ', stdout );
}
void display_permissions( const char* const permissions )
void display_permissions( const char* const permissions, bool no_colour )
{
format_set_style( permission_style, PERM_STYLE_NUM );
format_set_colour( permission_colour );
if ( !permissions ) return;
if ( !no_colour )
{
format_set_style( permission_style, PERM_STYLE_NUM );
format_set_colour( permission_colour );
}
fprintf( stdout, "%s", permissions );
format_clear();
fputc( ' ', stdout );
}
void display_size( directory_entry_t *entry )
void display_size( directory_entry_t *entry, bool no_colour )
{
const size_t length = 9;
char size_string[ length ];
if ( !entry ) return;
size_to_string( entry, size_string, length );
format_set_style( size_style, SIZE_STYLE_NUM );
format_set_colour( size_colour );
if ( !no_colour )
{
format_set_style( size_style, SIZE_STYLE_NUM );
format_set_colour( size_colour );
}
fprintf( stdout, "%s", size_string );
format_clear();
fputc( ' ', stdout );
}
void display_user( directory_entry_t* entry )
void display_user( directory_entry_t* entry, bool no_colour )
{
struct passwd* user = getpwuid( entry->stats.st_uid );
const size_t length = 8;
char string[ length ];
if ( !entry ) return;
snprintf( string, length, "%s", user->pw_name );
format_set_style( user_style, USER_STYLE_NUM );
format_set_colour( user_colour );
if ( !no_colour )
{
format_set_style( user_style, USER_STYLE_NUM );
format_set_colour( user_colour );
}
fprintf( stdout, "%-7s", string );
format_clear();
fputc( ' ', stdout );
}
void display_time( time_t time )
void display_time( time_t time, bool no_colour )
{
const size_t length = 17;
char string[ length ];
@@ -107,30 +127,40 @@ void display_time( time_t time )
strftime( string, length, "%Y-%m-%d %H:%M", local );
format_set_style( date_style, DATE_STYLE_NUM );
format_set_colour( date_colour );
if ( !no_colour )
{
format_set_style( date_style, DATE_STYLE_NUM );
format_set_colour( date_colour );
}
fprintf( stdout, "%s", string );
format_clear();
fputc( ' ', stdout );
}
void display_entry( const directory_entry_t* const entry )
void display_entry( const directory_entry_t* const entry, bool no_colour )
{
set_type_style( entry );
if ( !entry ) return;
if ( !no_colour )
{
set_type_style( entry );
}
fprintf( stdout, "%s", entry->name );
format_clear();
fputc( ' ', stdout );
}
void display_link_target(const directory_entry_t* const entry)
void display_link_target(const directory_entry_t* const entry, bool no_colour )
{
char link[ PATH_MAX ];
ssize_t length = 0;
struct stat link_stat;
int link_invalid;
if ( !entry ) return;
length = readlink( entry->name, &link[ 0 ], PATH_MAX );
if ( 0 > length )
@@ -143,29 +173,23 @@ void display_link_target(const directory_entry_t* const entry)
fprintf( stdout, "--> ");
if ( link_invalid )
if ( !no_colour )
{
format_set_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
format_set_colour( brokenlink_colour );
}
else
{
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_set_colour( link_colour );
if ( link_invalid )
{
format_set_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
format_set_colour( brokenlink_colour );
}
else
{
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_set_colour( link_colour );
}
}
fprintf( stdout, "%s", link );
if ( link_invalid )
{
format_reset_style( &brokenlink_style[ 0 ], BLNK_STYLE_NUM );
format_clear_colour();
}
else
{
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
format_clear_colour();
}
format_clear();
}
void set_type_style( const directory_entry_t* const entry )