Skip to content

Commit ecdd567

Browse files
committed
fix: changed TYPE names; some code refactored
1 parent 64a75ee commit ecdd567

4 files changed

Lines changed: 36 additions & 42 deletions

File tree

src/ds.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Manpage for Directory diSplay.
22
.\" by ElCapitan, https://github.com/at-elcapitan
33

4-
.TH "ds" 1 "30 July 2024" "GNU" "Directory diSplay"
4+
.TH "ds" 1 "27 Feb 2026" "GNU" "Directory diSplay"
55
.SH NAME
66
Directory diSplay (DS) - display current directory
77

src/file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn get_file_type(file: &DirEntry) -> ObjectType {
3838

3939
if filetype.is_dir() {
4040
ObjectType {
41-
type_name: String::from(" DIR"),
41+
type_name: String::from("DIR"),
4242
display_color: String::from("\x1b[34;1m")
4343
}
4444
} else if filetype.is_file()
@@ -56,7 +56,7 @@ fn get_file_type(file: &DirEntry) -> ObjectType {
5656
}
5757
} else if filetype.is_symlink() {
5858
ObjectType {
59-
type_name: String::from("SYMLINK"),
59+
type_name: String::from("SYML"),
6060
display_color: String::from("\x1b[31;1m"),
6161
}
6262
} else if filetype.is_block_device() {
@@ -71,7 +71,7 @@ fn get_file_type(file: &DirEntry) -> ObjectType {
7171
}
7272
} else {
7373
ObjectType {
74-
type_name: String::from("UNKNOWN"),
74+
type_name: String::from("UNDEF"),
7575
display_color: String::from(""),
7676
}
7777
}

src/main.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,30 @@ fn main() -> std::io::Result<()> {
5050
&parsed_args.full_name
5151
);
5252

53-
// Displaying the top line and setting the final size
54-
if let Some(dir_name) = current_dir.file_name() {
55-
let current_dir_name: Cow<str> = dir_name.to_string_lossy();
56-
57-
let current_dir_name_len: usize = current_dir_name.chars()
58-
.count();
53+
let current_dir_name: Cow<str>;
54+
let current_dir_name_len: usize;
5955

60-
files.max_name_length = files.max_name_length.max(current_dir_name_len);
61-
utils::display_top_line(
62-
&files.max_name_length,
63-
current_dir_name,
64-
current_dir_name_len,
65-
&parsed_args.access,
66-
&parsed_args.size
67-
);
56+
// Setting final max_length value
57+
if let Some(dir_name) = current_dir.file_name() {
58+
current_dir_name = dir_name.to_string_lossy();
59+
current_dir_name_len =
60+
current_dir_name.chars()
61+
.count();
62+
files.max_name_length =
63+
files.max_name_length.max(current_dir_name_len);
6864
} else {
69-
utils::display_top_line(
70-
&files.max_name_length,
71-
Cow::Borrowed(""),
72-
0,
73-
&parsed_args.access,
74-
&parsed_args.size
75-
);
65+
current_dir_name = Cow::Borrowed("");
66+
current_dir_name_len = 0;
7667
}
68+
69+
// Displaying the top line
70+
utils::display_top_line(
71+
&files.max_name_length,
72+
current_dir_name,
73+
current_dir_name_len,
74+
&parsed_args.access,
75+
&parsed_args.size
76+
);
7777

7878
// Printing empty line
7979
println!(" │");

src/utils.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn display_help() {
5252
}
5353

5454
pub fn display_version() {
55-
println!("ds (Directory diSplay) 2.1.0");
55+
println!("ds (Directory diSplay) 2.1.1");
5656
println!();
5757
println!(
5858
"This is free software; see the source for copying conditions. There is NO"
@@ -79,28 +79,22 @@ pub fn display_top_line(max_length: &usize,
7979
additional.push_str("PUSER\tGROUP\tOTHER")
8080
}
8181

82-
if current_dir_name_len > 0 {
83-
let spaces = max_length + 7 - current_dir_name_len;
82+
let spaces = max_length + 7 - current_dir_name_len;
8483

85-
println!(
86-
"{}/{}\tTYPE\t\t{}",
87-
current_dir_name,
88-
" ".repeat(spaces),
89-
additional
90-
);
91-
92-
return;
93-
}
94-
95-
println!("./{} \tTYPE\t\t{}", " ".repeat(max_length + 6), additional);
84+
println!(
85+
"{}/{}\tTYPE\t\t{}",
86+
current_dir_name,
87+
" ".repeat(spaces),
88+
additional
89+
);
9690
}
9791

9892
pub fn display_objects(
9993
objects: Vec<DisplayableObject>,
10094
max_length: &usize,
10195
flag_access: &bool,
10296
flag_size: &bool,
103-
ending: bool
97+
final_objects: bool
10498
) {
10599
for (i, obj) in objects.iter().enumerate() {
106100
let mut flags_data = String::new();
@@ -130,12 +124,12 @@ pub fn display_objects(
130124

131125
let symbol;
132126

133-
if ending && i == objects.len() - 1 {
127+
if final_objects && i == objects.len() - 1 {
134128
symbol = String::from("└");
135129
} else {
136130
symbol = String::from("├");
137131
}
138-
132+
139133
println!(
140134
" {} {}{:<width$}\x1b[0m\t{}\t\t{flags_data}",
141135
symbol,

0 commit comments

Comments
 (0)