display link target
This commit is contained in:
1 parent
bb0072a6f6
commit
9c65543633
3 files changed
+186
-35
No files matched your search
+60
-1
@@ -10,12 +10,71 @@
|
|||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
|
||||||
/* -- colour and style configuration */
|
/* -- colour and style configuration */
|
||||||
|
// additional information
|
||||||
|
// #define PERM_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t permission_style[PERM_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t permission_colour = 0xEEEEEE;
|
||||||
|
//
|
||||||
|
// #define DATE_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t date_style[DATE_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t date_colour = 0xEEEEEE;
|
||||||
|
//
|
||||||
|
// #define TYPE_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t type_style[TYPE_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t type_colour = 0xEEEEEE;
|
||||||
|
//
|
||||||
|
// #define SIZE_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t size_style[SIZE_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t size_colour = 0xEEEEEE;
|
||||||
|
|
||||||
|
// files by type
|
||||||
|
#define BLK_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t block_style[BLK_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t block_colour = 0xFFCC13;
|
||||||
|
|
||||||
|
#define CHAR_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t character_style[CHAR_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t character_colour = 0xEEEEEE;
|
||||||
|
|
||||||
#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 FIFO_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t fifo_style[FIFO_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t fifo_colour = 0xEEEEEE;
|
||||||
|
|
||||||
|
#define LINK_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t link_style[LINK_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t link_colour = 0x19D1DE;
|
||||||
|
|
||||||
|
// #define BLNK_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t brokenlink_style[BLNK_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t brokenlink_colour = 0xEEEEEE;
|
||||||
|
|
||||||
|
#define SOCK_STYLE_NUM ( ( int )1 )
|
||||||
|
const style_t socket_style[SOCK_STYLE_NUM] = { style_none };
|
||||||
|
const uint32_t socket_colour = 0xEEEEEE;
|
||||||
|
|
||||||
#define EXEC_STYLE_NUM ( ( int )1 )
|
#define EXEC_STYLE_NUM ( ( int )1 )
|
||||||
const style_t exec_style[EXEC_STYLE_NUM] = { style_none };
|
const style_t exec_style[EXEC_STYLE_NUM] = { style_none };
|
||||||
const uint32_t exec_colour = 0x34AD1F;
|
const uint32_t exec_colour = 0xEEEEEE;
|
||||||
|
|
||||||
|
// // files by extension
|
||||||
|
// #define MAKE_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t makefile_style[MAKE_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t makefile_colour = 0xEAE977;
|
||||||
|
//
|
||||||
|
// #define SRC_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t source_style[SRC_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t source_colour = 0x6FADD8;
|
||||||
|
//
|
||||||
|
// #define MEDIA_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t media_style[MEDIA_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t media_colour = 0x6FADD8;
|
||||||
|
//
|
||||||
|
// #define AR_STYLE_NUM ( ( int )1 )
|
||||||
|
// const style_t archive_style[AR_STYLE_NUM] = { style_none };
|
||||||
|
// const uint32_t archive_colour = 0x6FADD8;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-14
@@ -15,6 +15,7 @@ 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 ( 0 == number ) return;
|
||||||
if ( NUMBER_STYLES < number ) return;
|
if ( NUMBER_STYLES < number ) return;
|
||||||
if ( style_none == styles[ 0 ] ) return;
|
if ( style_none == styles[ 0 ] ) return;
|
||||||
|
|
||||||
@@ -26,20 +27,16 @@ void format_set_style( const style_t* const styles, uint8_t number )
|
|||||||
if ( style_none <= style )
|
if ( style_none <= style )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( n >= number - 1 )
|
|
||||||
{
|
|
||||||
fprintf( stdout, "%d", STYLE_SET[ style ] );
|
fprintf( stdout, "%d", STYLE_SET[ style ] );
|
||||||
}
|
if ( n < number - 1 )
|
||||||
else
|
fputc( ';', stdout );
|
||||||
{
|
|
||||||
fprintf( stdout, "%d;", STYLE_SET[ style ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fprintf( stdout, SEQUENCE_SUFFIX );
|
fprintf( stdout, SEQUENCE_SUFFIX );
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ( 0 == number ) return;
|
||||||
if ( NUMBER_STYLES < number ) return;
|
if ( NUMBER_STYLES < number ) return;
|
||||||
if ( style_none == styles[ 0 ] ) return;
|
if ( style_none == styles[ 0 ] ) return;
|
||||||
|
|
||||||
@@ -47,14 +44,13 @@ void format_reset_style( const style_t* const styles, uint8_t number )
|
|||||||
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 ( n >= number - 1 )
|
|
||||||
{
|
if ( NUMBER_STYLES <= style )
|
||||||
|
continue;
|
||||||
|
|
||||||
fprintf( stdout, "%d", STYLE_RESET[ style ] );
|
fprintf( stdout, "%d", STYLE_RESET[ style ] );
|
||||||
}
|
if ( n < number - 1 )
|
||||||
else
|
fputc( ';', stdout );
|
||||||
{
|
|
||||||
fprintf( stdout, "%d;", STYLE_RESET[ style ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fprintf( stdout, SEQUENCE_SUFFIX );
|
fprintf( stdout, SEQUENCE_SUFFIX );
|
||||||
}
|
}
|
||||||
|
|||||||
+116
-20
@@ -55,6 +55,8 @@ static int display_directory_contents(
|
|||||||
size_t recursion_level,
|
size_t recursion_level,
|
||||||
size_t is_last
|
size_t is_last
|
||||||
);
|
);
|
||||||
|
void set_style( const directory_entry_t* const entry );
|
||||||
|
void reset_style( const directory_entry_t* const entry );
|
||||||
|
|
||||||
// program logic
|
// program logic
|
||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
@@ -374,39 +376,53 @@ int display_directory_contents(
|
|||||||
fprintf( stdout, "%s", tree );
|
fprintf( stdout, "%s", tree );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( entry->type == type_directory )
|
if ( !args->tree_view )
|
||||||
{
|
{
|
||||||
format_set_style( directory_style, DIR_STYLE_NUM );
|
fprintf(
|
||||||
format_set_fg_colour( directory_colour );
|
stdout,
|
||||||
|
"%c%s%s ",
|
||||||
|
file_type,
|
||||||
|
file_permissions,
|
||||||
|
file_size
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_style( entry );
|
||||||
fprintf( stdout, "%s", entry->name );
|
fprintf( stdout, "%s", entry->name );
|
||||||
if ( entry->type == type_directory )
|
reset_style( entry );
|
||||||
|
|
||||||
|
if ( type_link == entry->type )
|
||||||
{
|
{
|
||||||
format_reset_style( directory_style, DIR_STYLE_NUM );
|
char link[ PATH_MAX ];
|
||||||
|
ssize_t length = 0;
|
||||||
|
|
||||||
|
length = readlink( entry->name, &link[ 0 ], PATH_MAX );
|
||||||
|
|
||||||
|
if ( 0 > length )
|
||||||
|
{
|
||||||
|
log_error( "failed to read link '%s'", entry->name );
|
||||||
|
}
|
||||||
|
link[ length ] = '\0';
|
||||||
|
|
||||||
|
fprintf( stdout, " --> ");
|
||||||
|
|
||||||
|
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||||
|
format_set_fg_colour( link_colour );
|
||||||
|
fprintf( stdout, "%s", link );
|
||||||
|
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||||
format_clear_fg_colour();
|
format_clear_fg_colour();
|
||||||
}
|
}
|
||||||
fprintf( stdout, "\n" );
|
|
||||||
|
|
||||||
// if ( !args->tree_view )
|
fputc( '\n', stdout );
|
||||||
// {
|
|
||||||
// log_info(
|
|
||||||
// "%c%s%s %s",
|
|
||||||
// file_type,
|
|
||||||
// file_permissions,
|
|
||||||
// file_size,
|
|
||||||
// entry->name
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
|
|
||||||
if ( recursion_level < args->depth
|
if ( args->tree_view
|
||||||
|
&& recursion_level < args->depth
|
||||||
&& entry->type == type_directory )
|
&& entry->type == type_directory )
|
||||||
{
|
{
|
||||||
DIR* subdirectory = opendir(entry->name);
|
DIR* subdirectory = opendir(entry->name);
|
||||||
if ( !subdirectory )
|
if ( !subdirectory )
|
||||||
{
|
{
|
||||||
log_error( "failed to open directory `%s`", entry->name );
|
log_error( "failed to open directory '%s'", entry->name );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -485,3 +501,83 @@ void size_to_string(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_style( const directory_entry_t* const entry )
|
||||||
|
{
|
||||||
|
switch ( entry->type )
|
||||||
|
{
|
||||||
|
case type_block:
|
||||||
|
format_set_style( &block_style[ 0 ], BLK_STYLE_NUM );
|
||||||
|
format_set_fg_colour( block_colour );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_character:
|
||||||
|
format_set_style( &character_style[ 0 ], CHAR_STYLE_NUM );
|
||||||
|
format_set_fg_colour( character_colour );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_directory:
|
||||||
|
format_set_style( &directory_style[ 0 ], DIR_STYLE_NUM );
|
||||||
|
format_set_fg_colour( directory_colour );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_fifo:
|
||||||
|
format_set_style( &fifo_style[ 0 ], FIFO_STYLE_NUM );
|
||||||
|
format_set_fg_colour( fifo_colour );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_link:
|
||||||
|
format_set_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||||
|
format_set_fg_colour( link_colour );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_regular:
|
||||||
|
// TODO: handle files by extension
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_socket:
|
||||||
|
format_set_style( &socket_style[ 0 ], SOCK_STYLE_NUM );
|
||||||
|
format_set_fg_colour( socket_colour );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_style( const directory_entry_t* const entry )
|
||||||
|
{
|
||||||
|
switch ( entry->type )
|
||||||
|
{
|
||||||
|
case type_block:
|
||||||
|
format_reset_style( &block_style[ 0 ], BLK_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_character:
|
||||||
|
format_reset_style( &character_style[ 0 ], CHAR_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_directory:
|
||||||
|
format_reset_style( &directory_style[ 0 ], DIR_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_fifo:
|
||||||
|
format_reset_style( &fifo_style[ 0 ], FIFO_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_link:
|
||||||
|
format_reset_style( &link_style[ 0 ], LINK_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_regular:
|
||||||
|
// TODO: handle files by extension
|
||||||
|
break;
|
||||||
|
|
||||||
|
case type_socket:
|
||||||
|
format_reset_style( &socket_style[ 0 ], SOCK_STYLE_NUM );
|
||||||
|
format_clear_fg_colour();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user