config config config
This commit is contained in:
1 parent
8ed2407463
commit
bb0072a6f6
4 files changed
+62
-50
No files matched your search
+5
-1
@@ -10,8 +10,12 @@
|
|||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
/* -- colour and style configuration */
|
/* -- colour and style configuration */
|
||||||
#define DIR_STYLE_NUM ( ( int )1 )
|
#define DIR_STYLE_NUM ( ( int )1 )
|
||||||
const style_t directory_style[DIR_STYLE_NUM] = { style_bold };
|
const style_t directory_style[DIR_STYLE_NUM] = { style_bold };
|
||||||
const uint32_t directory_colour = 0x6CA05C;
|
const uint32_t directory_colour = 0x6CA05C;
|
||||||
|
|
||||||
|
#define EXEC_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t exec_style[EXEC_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t exec_colour = 0x34AD1F;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+2
-2
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
/* -- type definitions */
|
/* -- type definitions */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
style_bold = 0u,
|
style_bold = 0u,
|
||||||
style_dim,
|
style_dim,
|
||||||
style_italic,
|
style_italic,
|
||||||
style_underlined,
|
style_underlined,
|
||||||
@@ -26,7 +26,7 @@ typedef enum {
|
|||||||
style_reversed,
|
style_reversed,
|
||||||
style_invisible,
|
style_invisible,
|
||||||
style_strikethrough,
|
style_strikethrough,
|
||||||
style_end = NUMBER_STYLES
|
style_none = NUMBER_STYLES
|
||||||
} style_t;
|
} style_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -15,13 +15,17 @@ void format_clear( void )
|
|||||||
|
|
||||||
void format_set_style( const style_t* const styles, uint8_t number )
|
void format_set_style( const style_t* const styles, uint8_t number )
|
||||||
{
|
{
|
||||||
if ( NUMBER_STYLES < number )
|
if ( NUMBER_STYLES < number ) return;
|
||||||
return;
|
if ( style_none == styles[ 0 ] ) return;
|
||||||
|
|
||||||
fprintf( stdout, SEQUENCE_PREFIX );
|
fprintf( stdout, SEQUENCE_PREFIX );
|
||||||
for ( int n = 0; n < number; n++ )
|
for ( int n = 0; n < number; n++ )
|
||||||
{
|
{
|
||||||
style_t style = styles[ n ];
|
style_t style = styles[ n ];
|
||||||
|
|
||||||
|
if ( style_none <= style )
|
||||||
|
continue;
|
||||||
|
|
||||||
if ( n >= number - 1 )
|
if ( n >= number - 1 )
|
||||||
{
|
{
|
||||||
fprintf( stdout, "%d", STYLE_SET[ style ] );
|
fprintf( stdout, "%d", STYLE_SET[ style ] );
|
||||||
@@ -36,8 +40,8 @@ void format_set_style( const style_t* const styles, uint8_t number )
|
|||||||
|
|
||||||
void format_reset_style( const style_t* const styles, uint8_t number )
|
void format_reset_style( const style_t* const styles, uint8_t number )
|
||||||
{
|
{
|
||||||
if ( NUMBER_STYLES < number )
|
if ( NUMBER_STYLES < number ) return;
|
||||||
return;
|
if ( style_none == styles[ 0 ] ) return;
|
||||||
|
|
||||||
fprintf( stdout, SEQUENCE_PREFIX );
|
fprintf( stdout, SEQUENCE_PREFIX );
|
||||||
for ( int n = 0; n < number; n++ )
|
for ( int n = 0; n < number; n++ )
|
||||||
|
|||||||
+47
-43
@@ -335,25 +335,16 @@ int display_directory_contents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
( void )permissions_to_string(
|
( void )permissions_to_string(
|
||||||
args,
|
args,
|
||||||
entry->stats.st_mode,
|
entry->stats.st_mode,
|
||||||
file_permissions
|
file_permissions
|
||||||
);
|
);
|
||||||
size_to_string( entry, &file_size[ 0 ], LENGTH_SIZE );
|
size_to_string( entry, &file_size[ 0 ], LENGTH_SIZE );
|
||||||
|
|
||||||
if ( !args->tree_view )
|
if ( args->tree_view )
|
||||||
{
|
|
||||||
log_info(
|
|
||||||
"%c%s%s %s",
|
|
||||||
file_type,
|
|
||||||
file_permissions,
|
|
||||||
file_size,
|
|
||||||
entry->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
char tree[ NAME_MAX ] = "";
|
char tree[ NAME_MAX ] = "";
|
||||||
|
|
||||||
for ( size_t k = 0; k < recursion_level; k++ )
|
for ( size_t k = 0; k < recursion_level; k++ )
|
||||||
{
|
{
|
||||||
if ( !( is_last & 1 << k ) )
|
if ( !( is_last & 1 << k ) )
|
||||||
@@ -381,41 +372,54 @@ int display_directory_contents(
|
|||||||
tree[ 4 * recursion_level + 3 ] = ' ';
|
tree[ 4 * recursion_level + 3 ] = ' ';
|
||||||
|
|
||||||
fprintf( stdout, "%s", tree );
|
fprintf( stdout, "%s", tree );
|
||||||
|
}
|
||||||
|
|
||||||
if ( entry->type == type_directory )
|
if ( entry->type == type_directory )
|
||||||
{
|
{
|
||||||
format_set_style( directory_style, DIR_STYLE_NUM );
|
format_set_style( directory_style, DIR_STYLE_NUM );
|
||||||
format_set_fg_colour( directory_colour );
|
format_set_fg_colour( directory_colour );
|
||||||
}
|
}
|
||||||
fprintf( stdout, "%s", entry->name );
|
fprintf( stdout, "%s", entry->name );
|
||||||
if ( entry->type == type_directory )
|
if ( entry->type == type_directory )
|
||||||
{
|
{
|
||||||
format_reset_style( directory_style, DIR_STYLE_NUM );
|
format_reset_style( directory_style, DIR_STYLE_NUM );
|
||||||
format_clear_fg_colour();
|
format_clear_fg_colour();
|
||||||
}
|
}
|
||||||
fprintf( stdout, "\n" );
|
fprintf( stdout, "\n" );
|
||||||
|
|
||||||
if ( recursion_level < args->depth
|
// if ( !args->tree_view )
|
||||||
&& entry->type == type_directory )
|
// {
|
||||||
|
// log_info(
|
||||||
|
// "%c%s%s %s",
|
||||||
|
// file_type,
|
||||||
|
// file_permissions,
|
||||||
|
// file_size,
|
||||||
|
// entry->name
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
|
||||||
|
if ( recursion_level < args->depth
|
||||||
|
&& entry->type == type_directory )
|
||||||
|
{
|
||||||
|
DIR* subdirectory = opendir(entry->name);
|
||||||
|
if ( !subdirectory )
|
||||||
{
|
{
|
||||||
DIR* subdirectory = opendir(entry->name);
|
log_error( "failed to open directory `%s`", entry->name );
|
||||||
if ( !subdirectory )
|
}
|
||||||
{
|
else
|
||||||
log_error( "failed to open directory `%s`", entry->name );
|
{
|
||||||
}
|
chdir( entry->name );
|
||||||
else
|
// TODO: handle return code
|
||||||
{
|
display_directory_contents(
|
||||||
chdir( entry->name );
|
|
||||||
// TODO: handle return code
|
|
||||||
display_directory_contents(
|
|
||||||
args,
|
args,
|
||||||
subdirectory,
|
subdirectory,
|
||||||
recursion_level + 1,
|
recursion_level + 1,
|
||||||
is_last | (size_t)( num_entries == n + 1 ) << recursion_level
|
is_last | (size_t)( num_entries == n + 1 ) << recursion_level
|
||||||
);
|
);
|
||||||
closedir( subdirectory );
|
closedir( subdirectory );
|
||||||
chdir( ".." );
|
chdir( ".." );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user