directory_paradise 1.4.4 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -22
- data/lib/directory_paradise/base/base.rb +33 -0
- data/lib/directory_paradise/base/colours.rb +12 -12
- data/lib/directory_paradise/project/project.rb +0 -0
- data/lib/directory_paradise/report/report.rb +1460 -113
- data/lib/directory_paradise/version/version.rb +2 -2
- metadata +4 -9
- data/lib/directory_paradise/report/constants.rb +0 -39
- data/lib/directory_paradise/report/initialize.rb +0 -75
- data/lib/directory_paradise/report/misc.rb +0 -675
- data/lib/directory_paradise/report/obtain.rb +0 -357
- data/lib/directory_paradise/report/reset.rb +0 -174
@@ -50,141 +50,1340 @@ class Report < Base # === DirectoryParadise::Report
|
|
50
50
|
require 'colours'
|
51
51
|
require 'directory_paradise/project/project.rb'
|
52
52
|
require 'directory_paradise/content/content.rb'
|
53
|
-
require 'directory_paradise/report/constants.rb'
|
54
|
-
require 'directory_paradise/report/initialize.rb'
|
55
53
|
require 'directory_paradise/report/menu.rb'
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === COLOURIZE_KB_AND_MB
|
57
|
+
#
|
58
|
+
# If true then we colourize KB and MB. This also includes B.
|
59
|
+
# ========================================================================= #
|
60
|
+
COLOURIZE_KB_AND_MB = true
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === FILE_SIZE_THRESHOLD
|
64
|
+
#
|
65
|
+
# When an inode entry has more than this amount of chars, we will
|
66
|
+
# truncate.
|
67
|
+
# ========================================================================= #
|
68
|
+
FILE_SIZE_THRESHOLD = 50
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === FILE_COLOURS_FOR_BYTES_VALUES
|
72
|
+
# ========================================================================= #
|
73
|
+
FILE_COLOURS_FOR_BYTES_VALUES = ::DirectoryParadise.project_base_directory?+
|
74
|
+
'yaml/colours_for_bytes_values.yml'
|
59
75
|
|
60
76
|
# ========================================================================= #
|
61
77
|
# === HASH_COLOURS_FOR_BYTES_VALUE
|
62
78
|
# ========================================================================= #
|
63
|
-
if File.exist? FILE_COLOURS_FOR_BYTES_VALUES
|
64
|
-
HASH_COLOURS_FOR_BYTES_VALUE =
|
65
|
-
YAML.load_file(
|
66
|
-
FILE_COLOURS_FOR_BYTES_VALUES
|
67
|
-
)
|
79
|
+
if File.exist? FILE_COLOURS_FOR_BYTES_VALUES
|
80
|
+
HASH_COLOURS_FOR_BYTES_VALUE =
|
81
|
+
YAML.load_file(
|
82
|
+
FILE_COLOURS_FOR_BYTES_VALUES
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
# ========================================================================= #
|
87
|
+
# === initialize
|
88
|
+
#
|
89
|
+
# The first argument is the target directory that should be displayed.
|
90
|
+
# ========================================================================= #
|
91
|
+
def initialize(
|
92
|
+
work_on_this_directory = return_pwd,
|
93
|
+
run_already = true
|
94
|
+
)
|
95
|
+
register_sigint
|
96
|
+
reset
|
97
|
+
# ======================================================================= #
|
98
|
+
# === Handle the run_already variable next
|
99
|
+
# ======================================================================= #
|
100
|
+
case run_already
|
101
|
+
# ======================================================================= #
|
102
|
+
# === :do_not_run_yet
|
103
|
+
# ======================================================================= #
|
104
|
+
when :do_not_run_yet,
|
105
|
+
:dont_run_yet,
|
106
|
+
:dont_run_as_of_yet,
|
107
|
+
:dontrunyet
|
108
|
+
run_already = false
|
109
|
+
# ======================================================================= #
|
110
|
+
# === :display
|
111
|
+
# ======================================================================= #
|
112
|
+
when :display,
|
113
|
+
:do_show,
|
114
|
+
:do_show_it
|
115
|
+
do_show_the_content
|
116
|
+
run_already = true
|
117
|
+
# ======================================================================= #
|
118
|
+
# === :run
|
119
|
+
# ======================================================================= #
|
120
|
+
when :run
|
121
|
+
run_already = true
|
122
|
+
end
|
123
|
+
# ======================================================================= #
|
124
|
+
# Assign to an instance variable next. This must come after
|
125
|
+
# reset().
|
126
|
+
# ======================================================================= #
|
127
|
+
@internal_hash[:run_already] = run_already
|
128
|
+
set_commandline_arguments(
|
129
|
+
work_on_this_directory
|
130
|
+
)
|
131
|
+
set_work_on_this_directory( # This method call can alter @run_already.
|
132
|
+
work_on_this_directory
|
133
|
+
)
|
134
|
+
run if @internal_hash[:run_already]
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === reset (reset tag)
|
139
|
+
# ========================================================================= #
|
140
|
+
def reset
|
141
|
+
infer_the_namespace
|
142
|
+
# ======================================================================= #
|
143
|
+
# === @internal_hash
|
144
|
+
# ======================================================================= #
|
145
|
+
@internal_hash = {}
|
146
|
+
# ======================================================================= #
|
147
|
+
# === :work_on_this_directory
|
148
|
+
# ======================================================================= #
|
149
|
+
@internal_hash[:work_on_this_directory] = return_pwd
|
150
|
+
# ======================================================================= #
|
151
|
+
# === :collapse
|
152
|
+
#
|
153
|
+
# Whether to collapse or not.
|
154
|
+
# ======================================================================= #
|
155
|
+
@internal_hash[:collapse] = false
|
156
|
+
# ======================================================================= #
|
157
|
+
# === :total_filesize
|
158
|
+
# ======================================================================= #
|
159
|
+
@internal_hash[:total_filesize] = 0 # Keep the total file size.
|
160
|
+
# ======================================================================= #
|
161
|
+
# === :report_filesize
|
162
|
+
#
|
163
|
+
# Tell the user the total filesize of the listing.
|
164
|
+
# ======================================================================= #
|
165
|
+
@internal_hash[:report_filesize] = true
|
166
|
+
# ======================================================================= #
|
167
|
+
# === :default_colour
|
168
|
+
# ======================================================================= #
|
169
|
+
@internal_hash[:default_colour] = :steelblue
|
170
|
+
# ======================================================================= #
|
171
|
+
# === :colourize_kb_and_mb
|
172
|
+
# ======================================================================= #
|
173
|
+
@internal_hash[:colourize_kb_and_mb] = COLOURIZE_KB_AND_MB
|
174
|
+
# ======================================================================= #
|
175
|
+
# === :threshold_for_file_size
|
176
|
+
#
|
177
|
+
# Only honoured if @truncate_long_file_names is true.
|
178
|
+
# ======================================================================= #
|
179
|
+
@internal_hash[:threshold_for_file_size] = FILE_SIZE_THRESHOLD
|
180
|
+
# ======================================================================= #
|
181
|
+
# === :show_group_information
|
182
|
+
# ======================================================================= #
|
183
|
+
@internal_hash[:show_group_information] = true
|
184
|
+
# ======================================================================= #
|
185
|
+
# === :show_modification_time
|
186
|
+
#
|
187
|
+
# if true then we show the modification time of the inode in question.
|
188
|
+
# ======================================================================= #
|
189
|
+
@internal_hash[:show_modification_time] = true
|
190
|
+
# ======================================================================= #
|
191
|
+
# === :use_colours
|
192
|
+
# ======================================================================= #
|
193
|
+
@internal_hash[:use_colours] = true
|
194
|
+
# ======================================================================= #
|
195
|
+
# === :show_leading_slash
|
196
|
+
#
|
197
|
+
# Show the leading slash in / directory.
|
198
|
+
# ======================================================================= #
|
199
|
+
@internal_hash[:show_leading_slash] = false
|
200
|
+
# ======================================================================= #
|
201
|
+
# === :sort_by
|
202
|
+
#
|
203
|
+
# This value must be nil initially, so that we will not do any
|
204
|
+
# sorting at all whatsoever.
|
205
|
+
# ======================================================================= #
|
206
|
+
@internal_hash[:sort_by] = nil
|
207
|
+
# ======================================================================= #
|
208
|
+
# === :show_only_symlinks
|
209
|
+
# ======================================================================= #
|
210
|
+
@internal_hash[:show_only_symlinks] = false
|
211
|
+
# ======================================================================= #
|
212
|
+
# === truncate_long_file_names
|
213
|
+
#
|
214
|
+
# If true, we truncate too-long file names.
|
215
|
+
# ======================================================================= #
|
216
|
+
@internal_hash[:truncate_long_file_names] = false
|
217
|
+
# ======================================================================= #
|
218
|
+
# === :colour_for_symlinks
|
219
|
+
# ======================================================================= #
|
220
|
+
@internal_hash[:colour_for_symlinks] = Colours.colour_for_symlinks
|
221
|
+
# ======================================================================= #
|
222
|
+
# === :show_size
|
223
|
+
#
|
224
|
+
# Whether to show the size of the entry at hand.
|
225
|
+
# ======================================================================= #
|
226
|
+
@internal_hash[:show_size] = true
|
227
|
+
# ======================================================================= #
|
228
|
+
# === :show_header
|
229
|
+
# ======================================================================= #
|
230
|
+
@internal_hash[:show_header] = true
|
231
|
+
# ======================================================================= #
|
232
|
+
# === :show_index
|
233
|
+
#
|
234
|
+
# Whether to show a leading index or not. I like this, so it is on
|
235
|
+
# by default.
|
236
|
+
# ======================================================================= #
|
237
|
+
@internal_hash[:show_index] = true
|
238
|
+
# ======================================================================= #
|
239
|
+
# === :colourize_path
|
240
|
+
#
|
241
|
+
# If the next variable is set to true then the path, such as
|
242
|
+
# /foo/bar.md will be colourized when .report() is called.
|
243
|
+
# ======================================================================= #
|
244
|
+
@internal_hash[:colourize_path] = true
|
245
|
+
# ======================================================================= #
|
246
|
+
# === :show_permission_bits
|
247
|
+
#
|
248
|
+
# If the following variable is set to true then the entry at hand
|
249
|
+
# will show inclusive "drwxr-xr-x".
|
250
|
+
# ======================================================================= #
|
251
|
+
@internal_hash[:show_permission_bits] = true
|
252
|
+
# ======================================================================= #
|
253
|
+
# === :show_dots_only_entries
|
254
|
+
#
|
255
|
+
# This setting filters away '.' and '..' from the result.
|
256
|
+
# ======================================================================= #
|
257
|
+
@internal_hash[:show_dots_only_entries] = false
|
258
|
+
# ======================================================================= #
|
259
|
+
# === :show_statistics
|
260
|
+
# ======================================================================= #
|
261
|
+
@internal_hash[:show_statistics] = true
|
262
|
+
# ======================================================================= #
|
263
|
+
# === :directory_content
|
264
|
+
#
|
265
|
+
# This variable will keep a reference to class
|
266
|
+
# DirectoryParadise::Content.
|
267
|
+
# ======================================================================= #
|
268
|
+
@internal_hash[:directory_content] = DirectoryParadise::Content.new
|
269
|
+
# ======================================================================= #
|
270
|
+
# === :hash_colours_for_bytes_value
|
271
|
+
#
|
272
|
+
# We need to capture this here because we may try to want to sanitize
|
273
|
+
# the given values, such as when the user types an incorrect colour,
|
274
|
+
# like "mediumpurples" rather than "mediumpurple".
|
275
|
+
# ======================================================================= #
|
276
|
+
@internal_hash[:hash_colours_for_bytes_value] = HASH_COLOURS_FOR_BYTES_VALUE
|
277
|
+
# ======================================================================= #
|
278
|
+
# === :show_simplified
|
279
|
+
#
|
280
|
+
# The following variable tells this class to keep a simplified directory
|
281
|
+
# layout.
|
282
|
+
#
|
283
|
+
# If it is true, then we only display a short variant of the file
|
284
|
+
# content.
|
285
|
+
# ======================================================================= #
|
286
|
+
@internal_hash[:show_simplified] = true
|
287
|
+
# ======================================================================= #
|
288
|
+
# === :result
|
289
|
+
# ======================================================================= #
|
290
|
+
@internal_hash[:result] = ''.dup
|
291
|
+
do_not_show_hidden_files # Do not show hidden files by default.
|
292
|
+
do_show_header
|
293
|
+
do_show_index
|
294
|
+
do_show_modification_time
|
295
|
+
do_show_the_content
|
296
|
+
do_not_stop_on_missing_symlink
|
297
|
+
end
|
298
|
+
|
299
|
+
# ========================================================================= #
|
300
|
+
# === try_to_report_the_total_filesize
|
301
|
+
#
|
302
|
+
# Use this method to report the total filesize from a given directory.
|
303
|
+
# ========================================================================= #
|
304
|
+
def try_to_report_the_total_filesize
|
305
|
+
total_file_size = total_file_size?
|
306
|
+
if total_file_size > 0
|
307
|
+
ee "\nTotal file size in the directory "
|
308
|
+
if use_colours?
|
309
|
+
e colourize_directory(which_dir?)
|
310
|
+
else
|
311
|
+
e which_dir?
|
312
|
+
end
|
313
|
+
append("\nTotal file size in the directory #{which_dir?}")
|
314
|
+
n_KB = (total_file_size / 1024.0)
|
315
|
+
n_MB = (n_KB / 1024.0)
|
316
|
+
append(
|
317
|
+
" #{total_file_size} bytes (#{n_KB.round(2)} KB) "\
|
318
|
+
"(#{n_MB.round(2)} MB)"
|
319
|
+
)
|
320
|
+
e steelblue(
|
321
|
+
" #{total_file_size} bytes (#{n_KB.round(2)} KB) "\
|
322
|
+
"(#{n_MB.round(2)} MB)"
|
323
|
+
)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
# ========================================================================= #
|
328
|
+
# === return_file_permission_of
|
329
|
+
# ========================================================================= #
|
330
|
+
def return_file_permission_of(i)
|
331
|
+
if condensed? and i.size == 10 # Then we assume we have the long format.
|
332
|
+
Roebe::PermissionAsciiFormat[i, :convert_into_decimal_format]
|
333
|
+
else # else we must convert it back.
|
334
|
+
i # Simply return as-is here.
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
# ========================================================================= #
|
339
|
+
# === set_sort_by
|
340
|
+
# ========================================================================= #
|
341
|
+
def set_sort_by(i)
|
342
|
+
@internal_hash[:sort_by] = i
|
343
|
+
end; alias sort_by= set_sort_by # === sort_by=
|
344
|
+
alias sort_by set_sort_by # === sort_by
|
345
|
+
|
346
|
+
# ========================================================================= #
|
347
|
+
# === sort_how (sort tag, sort how tag)
|
348
|
+
#
|
349
|
+
# Here we determine how to sort.
|
350
|
+
#
|
351
|
+
# The sort possibilities are:
|
352
|
+
#
|
353
|
+
# - by datesort_how
|
354
|
+
# - by size
|
355
|
+
# - in a reversed manner
|
356
|
+
#
|
357
|
+
# ========================================================================= #
|
358
|
+
def sort_how(
|
359
|
+
how = :size
|
360
|
+
)
|
361
|
+
how = how.to_s.downcase.to_sym # We want a downcased Symbol here.
|
362
|
+
case how # case tag
|
363
|
+
# ======================================================================= #
|
364
|
+
# === :reversed
|
365
|
+
# ======================================================================= #
|
366
|
+
when :reversed,
|
367
|
+
:reverse,
|
368
|
+
:by_reverse,
|
369
|
+
:by_reversed
|
370
|
+
set_sort_by(:reversed)
|
371
|
+
# ======================================================================= #
|
372
|
+
# === :date
|
373
|
+
# ======================================================================= #
|
374
|
+
when :date,
|
375
|
+
:by_date
|
376
|
+
set_sort_by(:date)
|
377
|
+
# ======================================================================= #
|
378
|
+
# === :size
|
379
|
+
# ======================================================================= #
|
380
|
+
when :size,
|
381
|
+
:sized,
|
382
|
+
:by_size # Sort by size.
|
383
|
+
set_sort_by(:size)
|
384
|
+
# ======================================================================= #
|
385
|
+
# === :modification_time
|
386
|
+
# ======================================================================= #
|
387
|
+
when :modification_time,
|
388
|
+
:by_modification_time
|
389
|
+
set_sort_by(:modification_time)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
# ========================================================================= #
|
394
|
+
# === show_help_options (help tag)
|
395
|
+
#
|
396
|
+
# To invoke this method, try:
|
397
|
+
#
|
398
|
+
# sdc --help
|
399
|
+
#
|
400
|
+
# ========================================================================= #
|
401
|
+
def show_help_options # Help tag.
|
402
|
+
e "#{rev}The currently available help options for "\
|
403
|
+
"#{simp('DirectoryContent::Report')} are:"
|
404
|
+
e
|
405
|
+
show_this_help_line :collapse, :short
|
406
|
+
show_this_help_line :toggle
|
407
|
+
show_this_help_line :nocolours
|
408
|
+
show_this_help_line :only_dirs
|
409
|
+
show_this_help_line :show_hidden_files
|
410
|
+
show_this_help_line :sized
|
411
|
+
show_this_help_line :date
|
412
|
+
show_this_help_line :lead
|
413
|
+
show_this_help_line :disable_show_modification_time
|
414
|
+
show_this_help_line :condensed
|
415
|
+
e
|
416
|
+
e 'Additionally, the following options are a bit more '\
|
417
|
+
'extensively documented here:'
|
418
|
+
e
|
419
|
+
Colours.eparse ' --show-only-symlinks # '\
|
420
|
+
'This will show only symlinks in the target directory'
|
421
|
+
e
|
422
|
+
exit
|
423
|
+
end
|
424
|
+
|
425
|
+
# ========================================================================= #
|
426
|
+
# === show_dots_only_entries?
|
427
|
+
# ========================================================================= #
|
428
|
+
def show_dots_only_entries?
|
429
|
+
@internal_hash[:show_dots_only_entries]
|
430
|
+
end
|
431
|
+
|
432
|
+
# ========================================================================= #
|
433
|
+
# === show_only_symlinks?
|
434
|
+
# ========================================================================= #
|
435
|
+
def show_only_symlinks?
|
436
|
+
@internal_hash[:show_only_symlinks]
|
437
|
+
end
|
438
|
+
|
439
|
+
# ========================================================================= #
|
440
|
+
# === ignore_backups?
|
441
|
+
# ========================================================================= #
|
442
|
+
def ignore_backups?
|
443
|
+
@internal_hash[:ignore_backups]
|
444
|
+
end
|
445
|
+
|
446
|
+
# ========================================================================= #
|
447
|
+
# === collapse?
|
448
|
+
#
|
449
|
+
# The revers of whether we will show the full path or not.
|
450
|
+
# ========================================================================= #
|
451
|
+
def collapse?
|
452
|
+
!show_full_path?
|
453
|
+
end
|
454
|
+
|
455
|
+
# ========================================================================= #
|
456
|
+
# === content?
|
457
|
+
# ========================================================================= #
|
458
|
+
def content?
|
459
|
+
@internal_hash[:directory_content].content?
|
460
|
+
end; alias content content? # === content?
|
461
|
+
|
462
|
+
# ========================================================================= #
|
463
|
+
# === show_inode?
|
464
|
+
# ========================================================================= #
|
465
|
+
def show_inode?
|
466
|
+
@internal_hash[:show_inode]
|
467
|
+
end
|
468
|
+
|
469
|
+
# ========================================================================= #
|
470
|
+
# === show_full_path?
|
471
|
+
# ========================================================================= #
|
472
|
+
def show_full_path?
|
473
|
+
@internal_hash[:show_full_path]
|
474
|
+
end; alias show_full_path show_full_path? # === show_full_path
|
475
|
+
|
476
|
+
# ========================================================================= #
|
477
|
+
# === show_group_information?
|
478
|
+
# ========================================================================= #
|
479
|
+
def show_group_information?
|
480
|
+
@internal_hash[:show_group_information]
|
481
|
+
end
|
482
|
+
|
483
|
+
# ========================================================================= #
|
484
|
+
# === show_size?
|
485
|
+
# ========================================================================= #
|
486
|
+
def show_size?
|
487
|
+
@internal_hash[:show_size]
|
488
|
+
end
|
489
|
+
|
490
|
+
# ========================================================================= #
|
491
|
+
# === colourize_path?
|
492
|
+
# ========================================================================= #
|
493
|
+
def colourize_path?
|
494
|
+
@internal_hash[:colourize_path]
|
495
|
+
end
|
496
|
+
|
497
|
+
# ========================================================================= #
|
498
|
+
# === show_permissionsbits?
|
499
|
+
# ========================================================================= #
|
500
|
+
def show_permission_bits?
|
501
|
+
@internal_hash[:show_permission_bits]
|
502
|
+
end; alias show_permissions? show_permission_bits? # === show_permissions?
|
503
|
+
|
504
|
+
# ========================================================================= #
|
505
|
+
# === directory_content?
|
506
|
+
# ========================================================================= #
|
507
|
+
def directory_content?
|
508
|
+
@internal_hash[:directory_content]
|
509
|
+
end
|
510
|
+
|
511
|
+
# ========================================================================= #
|
512
|
+
# === obtain_from_directory_content
|
513
|
+
# ========================================================================= #
|
514
|
+
def obtain_from_directory_content(i)
|
515
|
+
@internal_hash[:directory_content].obtain_from(i)
|
516
|
+
end
|
517
|
+
|
518
|
+
# ========================================================================= #
|
519
|
+
# === display_only_directories?
|
520
|
+
# ========================================================================= #
|
521
|
+
def display_only_directories?
|
522
|
+
@internal_hash[:display_only_directories]
|
523
|
+
end
|
524
|
+
|
525
|
+
# ========================================================================= #
|
526
|
+
# === show_hidden_files?
|
527
|
+
# ========================================================================= #
|
528
|
+
def show_hidden_files?
|
529
|
+
@internal_hash[:show_hidden_files]
|
530
|
+
end
|
531
|
+
|
532
|
+
# ========================================================================= #
|
533
|
+
# === show_index?
|
534
|
+
# ========================================================================= #
|
535
|
+
def show_index?
|
536
|
+
@internal_hash[:show_index]
|
537
|
+
end; alias use_index? show_index? # === use_index?
|
538
|
+
|
539
|
+
# ========================================================================= #
|
540
|
+
# === entries?
|
541
|
+
# ========================================================================= #
|
542
|
+
def entries?
|
543
|
+
@internal_hash[:directory_content].entries
|
544
|
+
end; alias _ entries? # === _
|
545
|
+
|
546
|
+
# ========================================================================= #
|
547
|
+
# === sort_by?
|
548
|
+
# ========================================================================= #
|
549
|
+
def sort_by?
|
550
|
+
@internal_hash[:sort_by]
|
551
|
+
end
|
552
|
+
|
553
|
+
# ========================================================================= #
|
554
|
+
# === symlinks?
|
555
|
+
# ========================================================================= #
|
556
|
+
def symlinks?
|
557
|
+
@internal_hash[:directory_content].symlinks?
|
558
|
+
end
|
559
|
+
|
560
|
+
# ========================================================================= #
|
561
|
+
# === n_symlinks?
|
562
|
+
# ========================================================================= #
|
563
|
+
def n_symlinks?
|
564
|
+
symlinks?.size
|
565
|
+
end
|
566
|
+
|
567
|
+
# ========================================================================= #
|
568
|
+
# === directories?
|
569
|
+
# ========================================================================= #
|
570
|
+
def directories? # Feedback all available directories here.
|
571
|
+
@internal_hash[:directory_content].directories?
|
572
|
+
end
|
573
|
+
|
574
|
+
# ========================================================================= #
|
575
|
+
# === files?
|
576
|
+
#
|
577
|
+
# Query for all available files, by delegating towards class
|
578
|
+
# DirectoryContent.
|
579
|
+
# ========================================================================= #
|
580
|
+
def files?
|
581
|
+
@internal_hash[:directory_content].files?
|
582
|
+
end
|
583
|
+
|
584
|
+
# ========================================================================= #
|
585
|
+
# === n_files?
|
586
|
+
# ========================================================================= #
|
587
|
+
def n_files?
|
588
|
+
files?.size
|
589
|
+
end
|
590
|
+
|
591
|
+
# ========================================================================= #
|
592
|
+
# === show_statistics?
|
593
|
+
# ========================================================================= #
|
594
|
+
def show_statistics?
|
595
|
+
@internal_hash[:show_statistics]
|
596
|
+
end
|
597
|
+
|
598
|
+
# ========================================================================= #
|
599
|
+
# === return_directory_content
|
600
|
+
# ========================================================================= #
|
601
|
+
def return_directory_content(
|
602
|
+
i = @internal_hash[:work_on_this_directory]
|
603
|
+
)
|
604
|
+
obtain_from_directory_content(i)
|
605
|
+
consider_sorting
|
606
|
+
_ = @internal_hash[:directory_content].entries?
|
607
|
+
return _
|
608
|
+
end; alias gather_content return_directory_content # === gather_content
|
609
|
+
alias gather return_directory_content # === gather
|
610
|
+
alias run_main_loop return_directory_content # === run_main_loop
|
611
|
+
alias obtain_directory_listing return_directory_content # === obtain_directory_listing
|
612
|
+
alias obtain_entries return_directory_content # === obtain_entries
|
613
|
+
|
614
|
+
# ========================================================================= #
|
615
|
+
# === display_content?
|
616
|
+
# ========================================================================= #
|
617
|
+
def display_content?
|
618
|
+
@internal_hash[:display_content]
|
619
|
+
end
|
620
|
+
|
621
|
+
# ========================================================================= #
|
622
|
+
# === do_not_show_simplified
|
623
|
+
# ========================================================================= #
|
624
|
+
def do_not_show_simplified
|
625
|
+
@internal_hash[:show_simplified] = false
|
626
|
+
end
|
627
|
+
|
628
|
+
# ========================================================================= #
|
629
|
+
# === do_show_simplified
|
630
|
+
# ========================================================================= #
|
631
|
+
def do_show_simplified
|
632
|
+
@internal_hash[:show_simplified] = true
|
633
|
+
end; alias show_simplified do_show_simplified # === show_simplified
|
634
|
+
|
635
|
+
# ========================================================================= #
|
636
|
+
# === n_directories?
|
637
|
+
#
|
638
|
+
# This will exclude directories with a trailing '.'
|
639
|
+
# ========================================================================= #
|
640
|
+
def n_directories?
|
641
|
+
directories = directories?.reject {|entry| entry.end_with? '/.' }
|
642
|
+
return directories.size
|
643
|
+
end
|
644
|
+
|
645
|
+
# ========================================================================= #
|
646
|
+
# === hash_colours_for_bytes_value?
|
647
|
+
# ========================================================================= #
|
648
|
+
def hash_colours_for_bytes_value?
|
649
|
+
@internal_hash[:hash_colours_for_bytes_value]
|
650
|
+
end
|
651
|
+
|
652
|
+
# ========================================================================= #
|
653
|
+
# === report_filesize?
|
654
|
+
# ========================================================================= #
|
655
|
+
def report_filesize?
|
656
|
+
@internal_hash[:report_filesize]
|
657
|
+
end; alias report_the_total_filesize? report_filesize? # === report_the_total_filesize?
|
658
|
+
|
659
|
+
# ========================================================================= #
|
660
|
+
# === total_filesize?
|
661
|
+
# ========================================================================= #
|
662
|
+
def total_filesize?
|
663
|
+
@internal_hash[:total_filesize]
|
664
|
+
end; alias total_file_size? total_filesize? # === total_file_size?
|
665
|
+
|
666
|
+
# ========================================================================= #
|
667
|
+
# === work_on_which_directory?
|
668
|
+
# ========================================================================= #
|
669
|
+
def work_on_which_directory?
|
670
|
+
@internal_hash[:work_on_this_directory]
|
671
|
+
end; alias from_which_directory? work_on_which_directory? # === from_which_directory?
|
672
|
+
alias base_directory? work_on_which_directory? # === base_directory?
|
673
|
+
alias input? work_on_which_directory? # === input?
|
674
|
+
alias which_directory? work_on_which_directory? # === which_directory?
|
675
|
+
alias which_dir? work_on_which_directory? # === which_dir?
|
676
|
+
alias base_dir? work_on_which_directory? # === base_dir?
|
677
|
+
alias dir? work_on_which_directory? # === dir?
|
678
|
+
|
679
|
+
# ========================================================================= #
|
680
|
+
# === dont_show_header
|
681
|
+
# ========================================================================= #
|
682
|
+
def dont_show_header
|
683
|
+
@internal_hash[:show_header] = false
|
684
|
+
end; alias do_not_show_the_header dont_show_header # === do_not_show_the_header
|
685
|
+
|
686
|
+
# ========================================================================= #
|
687
|
+
# === do_show_hidden_files
|
688
|
+
# ========================================================================= #
|
689
|
+
def do_show_hidden_files
|
690
|
+
@internal_hash[:show_hidden_files] = true
|
691
|
+
end
|
692
|
+
|
693
|
+
# ========================================================================= #
|
694
|
+
# == dont_show_index
|
695
|
+
# ========================================================================= #
|
696
|
+
def dont_show_index
|
697
|
+
@internal_hash[:show_index] = false
|
698
|
+
end; alias do_not_show_the_index dont_show_index # === do_not_show_the_index
|
699
|
+
alias do_not_show_index dont_show_index # === do_not_show_index
|
700
|
+
|
701
|
+
# ========================================================================= #
|
702
|
+
# === toggle_colourize
|
703
|
+
# ========================================================================= #
|
704
|
+
def toggle_colourize
|
705
|
+
if @internal_hash[:colourize_kb_and_mb] == false
|
706
|
+
@internal_hash[:colourize_kb_and_mb] = true
|
707
|
+
else
|
708
|
+
@internal_hash[:colourize_kb_and_mb] = false
|
709
|
+
end
|
710
|
+
end; alias toggle toggle_colourize # === toggle
|
711
|
+
|
712
|
+
# ========================================================================= #
|
713
|
+
# === do_not_ignore_backups
|
714
|
+
# ========================================================================= #
|
715
|
+
def do_not_ignore_backups
|
716
|
+
@internal_hash[:ignore_backups] = false
|
717
|
+
end
|
718
|
+
|
719
|
+
# ========================================================================= #
|
720
|
+
# === do_colourize_kb_and_mb
|
721
|
+
# ========================================================================= #
|
722
|
+
def do_colourize_kb_and_mb
|
723
|
+
@internal_hash[:colourize_kb_and_mb] = true
|
724
|
+
end
|
725
|
+
|
726
|
+
# ========================================================================= #
|
727
|
+
# === collapse=
|
728
|
+
# ========================================================================= #
|
729
|
+
def collapse=(i)
|
730
|
+
@internal_hash[:collapse] = i
|
731
|
+
end
|
732
|
+
|
733
|
+
# ========================================================================= #
|
734
|
+
# === stop_on_missing_symlink=
|
735
|
+
# ========================================================================= #
|
736
|
+
def stop_on_missing_symlink=(i)
|
737
|
+
@internal_hash[:stop_on_missing_symlink] = i
|
738
|
+
end
|
739
|
+
|
740
|
+
# ========================================================================= #
|
741
|
+
# === do_show_full_path
|
742
|
+
# ========================================================================= #
|
743
|
+
def do_show_full_path
|
744
|
+
@internal_hash[:show_full_path] = true
|
745
|
+
end
|
746
|
+
|
747
|
+
# ========================================================================= #
|
748
|
+
# === dont_show_full_path
|
749
|
+
#
|
750
|
+
# I assume that this option is interconnected with another option,
|
751
|
+
# namely the ability to show, or rather not show, a leading slash.
|
752
|
+
#
|
753
|
+
# Thus, as of May 2015, we will also disable showing the leading
|
754
|
+
# slash whenever we invoke this method here.
|
755
|
+
# ========================================================================= #
|
756
|
+
def dont_show_full_path
|
757
|
+
set_show_full_path(false)
|
758
|
+
do_not_show_leading_slash
|
759
|
+
end; alias do_not_show_full_path dont_show_full_path # === do_not_show_full_path
|
760
|
+
alias enable_collapse dont_show_full_path # === enable_collapse
|
761
|
+
alias do_not_show_the_full_path dont_show_full_path # === do_not_show_the_full_path
|
762
|
+
alias do_show_only_filename dont_show_full_path # === do_show_only_filename
|
763
|
+
|
764
|
+
# ========================================================================= #
|
765
|
+
# === check_whether_we_use_colours
|
766
|
+
#
|
767
|
+
# We will enable the colours if necessary.
|
768
|
+
# ========================================================================= #
|
769
|
+
def check_whether_we_use_colours
|
770
|
+
if use_colours?
|
771
|
+
enable_colours
|
772
|
+
check_whether_the_colours_defined_in_the_yaml_file_are_valid
|
773
|
+
define_colours
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
777
|
+
# ========================================================================= #
|
778
|
+
# === do_not_stop_on_missing_symlink
|
779
|
+
# ========================================================================= #
|
780
|
+
def do_not_stop_on_missing_symlink
|
781
|
+
@internal_hash[:stop_on_missing_symlink] = false # if true we will stop on missing symlink.
|
782
|
+
end
|
783
|
+
|
784
|
+
# ========================================================================= #
|
785
|
+
# === do_show_condensed_permissions
|
786
|
+
# ========================================================================= #
|
787
|
+
def do_show_condensed_permissions
|
788
|
+
@internal_hash[:show_condensed_permissions] = true
|
789
|
+
end
|
790
|
+
|
791
|
+
# ========================================================================= #
|
792
|
+
# === ignore_backups
|
793
|
+
# ========================================================================= #
|
794
|
+
def ignore_backups
|
795
|
+
@internal_hash[:ignore_backups] = true
|
796
|
+
end
|
797
|
+
|
798
|
+
# ========================================================================= #
|
799
|
+
# === do_not_report_filesize
|
800
|
+
# ========================================================================= #
|
801
|
+
def do_not_report_filesize
|
802
|
+
@internal_hash[:report_filesize] = false
|
803
|
+
end; alias dont_report_total_filesize do_not_report_filesize # === dont_report_total_filesize
|
804
|
+
|
805
|
+
# ========================================================================= #
|
806
|
+
# === do_show_index
|
807
|
+
# ========================================================================= #
|
808
|
+
def do_show_index
|
809
|
+
@internal_hash[:show_index] = true # if true then we will show the index.
|
810
|
+
end
|
811
|
+
|
812
|
+
# ========================================================================= #
|
813
|
+
# === do_report_filesize
|
814
|
+
# ========================================================================= #
|
815
|
+
def do_report_filesize
|
816
|
+
@internal_hash[:report_filesize] = true
|
817
|
+
end
|
818
|
+
|
819
|
+
# ========================================================================= #
|
820
|
+
# === do_not_show_size
|
821
|
+
# ========================================================================= #
|
822
|
+
def do_not_show_size
|
823
|
+
@internal_hash[:show_size] = false
|
824
|
+
end
|
825
|
+
|
826
|
+
# ========================================================================= #
|
827
|
+
# === do_show_almost_nothing
|
828
|
+
# ========================================================================= #
|
829
|
+
def do_show_almost_nothing
|
830
|
+
do_not_show_size
|
831
|
+
do_not_show_index
|
832
|
+
do_not_show_permissions
|
833
|
+
do_not_show_modtime
|
834
|
+
end
|
835
|
+
|
836
|
+
# ========================================================================= #
|
837
|
+
# === do_truncate_long_file_names
|
838
|
+
# ========================================================================= #
|
839
|
+
def do_truncate_long_file_names
|
840
|
+
@internal_hash[:truncate_long_file_names] = true
|
841
|
+
end; alias truncate do_truncate_long_file_names # === truncate
|
842
|
+
|
843
|
+
# ========================================================================= #
|
844
|
+
# === disable_show_modification_time
|
845
|
+
# ========================================================================= #
|
846
|
+
def disable_show_modification_time
|
847
|
+
@internal_hash[:show_modification_time] = false
|
848
|
+
end; alias dont_show_modification_time disable_show_modification_time
|
849
|
+
alias do_not_show_modification_time disable_show_modification_time
|
850
|
+
alias do_not_show_modtime disable_show_modification_time
|
851
|
+
|
852
|
+
# ========================================================================= #
|
853
|
+
# === do_shorten_display
|
854
|
+
# ========================================================================= #
|
855
|
+
def do_shorten_display
|
856
|
+
enable_collapse
|
857
|
+
disable_show_modification_time # Added Aug 2012.
|
858
|
+
end
|
859
|
+
|
860
|
+
# ========================================================================= #
|
861
|
+
# === do_not_debug
|
862
|
+
# ========================================================================= #
|
863
|
+
def do_not_debug
|
864
|
+
@internal_hash[:debug] = false # Whether we debug this class or not.
|
865
|
+
end
|
866
|
+
|
867
|
+
# ========================================================================= #
|
868
|
+
# === do_not_truncate_long_file_names
|
869
|
+
# ========================================================================= #
|
870
|
+
def do_not_truncate_long_file_names
|
871
|
+
@internal_hash[:truncate_long_file_names] = false
|
872
|
+
end
|
873
|
+
|
874
|
+
# ========================================================================= #
|
875
|
+
# === do_show_leading_slash
|
876
|
+
# ========================================================================= #
|
877
|
+
def do_show_leading_slash
|
878
|
+
@internal_hash[:show_leading_slash] = true
|
879
|
+
end
|
880
|
+
|
881
|
+
# ========================================================================= #
|
882
|
+
# === do_show_modification_time
|
883
|
+
# ========================================================================= #
|
884
|
+
def do_show_modification_time
|
885
|
+
@internal_hash[:show_modification_time] = true
|
886
|
+
end
|
887
|
+
|
888
|
+
# ========================================================================= #
|
889
|
+
# === do_not_show_inode
|
890
|
+
# ========================================================================= #
|
891
|
+
def do_not_show_inode
|
892
|
+
@internal_hash[:show_inode] = false
|
893
|
+
end
|
894
|
+
|
895
|
+
# ========================================================================= #
|
896
|
+
# === do_show_inode
|
897
|
+
# ========================================================================= #
|
898
|
+
def do_show_inode # Show the inode number if true.
|
899
|
+
@internal_hash[:show_inode] = true
|
900
|
+
end
|
901
|
+
|
902
|
+
# ========================================================================= #
|
903
|
+
# === do_hide_files
|
904
|
+
# ========================================================================= #
|
905
|
+
def do_hide_files
|
906
|
+
@internal_hash[:show_hidden_files] = false
|
907
|
+
end; alias do_not_show_hidden_files do_hide_files # === do_not_show_hidden_files
|
908
|
+
|
909
|
+
# ========================================================================= #
|
910
|
+
# === do_show_uncondensed_permissions
|
911
|
+
# ========================================================================= #
|
912
|
+
def do_show_uncondensed_permissions
|
913
|
+
@internal_hash[:show_condensed_permissions] = false
|
914
|
+
end; alias dont_show_condensed_permissions do_show_uncondensed_permissions
|
915
|
+
|
916
|
+
# ========================================================================= #
|
917
|
+
# === show_this_help_line
|
918
|
+
# ========================================================================= #
|
919
|
+
def show_this_help_line(
|
920
|
+
i = :toggle, optional_additional_argument = nil
|
921
|
+
)
|
922
|
+
if optional_additional_argument
|
923
|
+
e " - #{sfancy(i)} / #{sfancy(optional_additional_argument)}"
|
924
|
+
else
|
925
|
+
e " - #{sfancy(i)}"
|
926
|
+
end
|
927
|
+
end
|
928
|
+
|
929
|
+
# ========================================================================= #
|
930
|
+
# === set_show_full_path
|
931
|
+
# ========================================================================= #
|
932
|
+
def set_show_full_path(i = true)
|
933
|
+
@internal_hash[:show_full_path] = i
|
934
|
+
end
|
935
|
+
|
936
|
+
# ========================================================================= #
|
937
|
+
# === run_already?
|
938
|
+
# ========================================================================= #
|
939
|
+
def run_already?
|
940
|
+
@internal_hash[:run_already]
|
941
|
+
end
|
942
|
+
|
943
|
+
# ========================================================================= #
|
944
|
+
# === set_work_on_this_directory
|
945
|
+
#
|
946
|
+
# This method will determine on which target directory (the base
|
947
|
+
# directory) this class will work on.
|
948
|
+
#
|
949
|
+
# It must be ensured that this variable will have a trailing '/'
|
950
|
+
# character, to properly indicate that we are dealing with a
|
951
|
+
# directory here.
|
952
|
+
# ========================================================================= #
|
953
|
+
def set_work_on_this_directory(
|
954
|
+
i = return_pwd
|
955
|
+
)
|
956
|
+
# ======================================================================= #
|
957
|
+
# === Handle Hashes first
|
958
|
+
# ======================================================================= #
|
959
|
+
if i.is_a? Hash
|
960
|
+
if i.has_key? :from
|
961
|
+
i = i.delete(:from)
|
962
|
+
end
|
963
|
+
end
|
964
|
+
if i.is_a? Array
|
965
|
+
_ = return_non_hyphen_entries_from(i)
|
966
|
+
if _.empty?
|
967
|
+
i = return_pwd
|
968
|
+
else
|
969
|
+
i = _
|
970
|
+
end
|
971
|
+
i = i.join(' ').strip if i.is_a? Array
|
972
|
+
end
|
973
|
+
case i
|
974
|
+
# ======================================================================= #
|
975
|
+
# === :dont_run_yet
|
976
|
+
# ======================================================================= #
|
977
|
+
when :dont_run_yet
|
978
|
+
i = nil
|
979
|
+
@internal_hash[:run_already] = false
|
980
|
+
# ======================================================================= #
|
981
|
+
# === :show_content
|
982
|
+
# ======================================================================= #
|
983
|
+
when :show_content
|
984
|
+
do_show_the_content
|
985
|
+
i = return_pwd
|
986
|
+
end
|
987
|
+
begin
|
988
|
+
# ===================================================================== #
|
989
|
+
# Default values come next here in this clause.
|
990
|
+
# ===================================================================== #
|
991
|
+
i = return_pwd if i.nil?
|
992
|
+
i = i.dup if i.frozen?
|
993
|
+
# ===================================================================== #
|
994
|
+
# We need to default to the current directory if there exists a
|
995
|
+
# directory with that name.
|
996
|
+
# ===================================================================== #
|
997
|
+
i = return_pwd unless Dir.exist?(i)
|
998
|
+
if i.is_a? String and i.empty?
|
999
|
+
i = return_pwd
|
1000
|
+
end
|
1001
|
+
rescue Errno::ENOENT # Rescue non-existing directories.
|
1002
|
+
e 'An error occurred. The directory may have been removed or the local'
|
1003
|
+
e "filesystem is unavailable. Thus, we will display \"/\" instead.#{N}"
|
1004
|
+
i = '/'
|
1005
|
+
end
|
1006
|
+
i = i.dup if i.frozen?
|
1007
|
+
i << '/' unless i.end_with? '/'
|
1008
|
+
i.squeeze!('/')
|
1009
|
+
@internal_hash[:work_on_this_directory] = i
|
1010
|
+
end; alias set_from_which_directory set_work_on_this_directory # === set_from_which_directory
|
1011
|
+
alias set_dir set_work_on_this_directory # === set_dir
|
1012
|
+
alias set_main_directory set_work_on_this_directory # === set_main_directory
|
1013
|
+
alias set_base_directory set_work_on_this_directory # === set_base_directory
|
1014
|
+
|
1015
|
+
# ========================================================================= #
|
1016
|
+
# === yaml_file?
|
1017
|
+
# ========================================================================= #
|
1018
|
+
def yaml_file?
|
1019
|
+
FILE_COLOURS_FOR_BYTES_VALUES
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
# ========================================================================= #
|
1023
|
+
# === check_whether_the_colours_defined_in_the_yaml_file_are_valid
|
1024
|
+
# ========================================================================= #
|
1025
|
+
def check_whether_the_colours_defined_in_the_yaml_file_are_valid
|
1026
|
+
_ = @internal_hash[:hash_colours_for_bytes_value]
|
1027
|
+
_.each_pair {|key, value| # The entries will be 'KB' and :lightgreen, for instance.
|
1028
|
+
if Object.const_defined?(:Colours) and
|
1029
|
+
::Colours.respond_to?(value)
|
1030
|
+
else
|
1031
|
+
e 'Attention please: the Colours namespace does not have a'
|
1032
|
+
e 'colour named `'+value.to_s+'` defined.'
|
1033
|
+
e
|
1034
|
+
e 'One key (the one named '+key.to_s+') currently has this'
|
1035
|
+
e 'value defined, though.'
|
1036
|
+
e
|
1037
|
+
e 'Please change this by modifying the following file:'
|
1038
|
+
e
|
1039
|
+
e sfile(" #{yaml_file?}")
|
1040
|
+
e
|
1041
|
+
e 'To get a listing of all defined colour-names, do this:'
|
1042
|
+
e
|
1043
|
+
e " require 'colours'"
|
1044
|
+
e ' pp Colours.html_colours?'
|
1045
|
+
e
|
1046
|
+
exit
|
1047
|
+
end
|
1048
|
+
}
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
# ========================================================================= #
|
1052
|
+
# === apply_filter
|
1053
|
+
#
|
1054
|
+
# Use this method here to apply a filter on the main entries.
|
1055
|
+
# ========================================================================= #
|
1056
|
+
def apply_filter(i)
|
1057
|
+
i = i.dup if i.frozen?
|
1058
|
+
i.delete!('*') if i.include? '*'
|
1059
|
+
i.delete!('/') if i.include? '/' # This may be incorrect.
|
1060
|
+
obtain_entries unless entries?
|
1061
|
+
entries?.select! {|entry|
|
1062
|
+
entry.include?(i)
|
1063
|
+
}
|
1064
|
+
entries?
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
# ========================================================================= #
|
1068
|
+
# === consider_colourizing_filename
|
1069
|
+
# ========================================================================= #
|
1070
|
+
def consider_colourizing_filename(filename)
|
1071
|
+
result = ''.dup
|
1072
|
+
if File.exist? filename
|
1073
|
+
filetype = File.ftype(filename)
|
1074
|
+
unless show_leading_slash?
|
1075
|
+
filename[0,1] = '' if filename.start_with? '/'
|
1076
|
+
end
|
1077
|
+
# ===================================================================== #
|
1078
|
+
# Next, honour the variable @show_full_path if it was set to true.
|
1079
|
+
# ===================================================================== #
|
1080
|
+
unless show_full_path?
|
1081
|
+
filename = File.basename(filename)
|
1082
|
+
end
|
1083
|
+
case filetype
|
1084
|
+
# ===================================================================== #
|
1085
|
+
# === link
|
1086
|
+
# ===================================================================== #
|
1087
|
+
when 'link' # Handle Symlinks here.
|
1088
|
+
result = colourize_symlink(filename)
|
1089
|
+
# ===================================================================== #
|
1090
|
+
# === directory
|
1091
|
+
# ===================================================================== #
|
1092
|
+
when 'directory'
|
1093
|
+
result = colourize_directory(filename) # This is actually sdir().
|
1094
|
+
# ===================================================================== #
|
1095
|
+
# === file
|
1096
|
+
# ===================================================================== #
|
1097
|
+
when 'file'
|
1098
|
+
result = sfile(filename)
|
1099
|
+
end
|
1100
|
+
end
|
1101
|
+
return result
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
# ========================================================================= #
|
1105
|
+
# === do_ignore_backups
|
1106
|
+
# ========================================================================= #
|
1107
|
+
def do_ignore_backups
|
1108
|
+
# ======================================================================= #
|
1109
|
+
# Do not list implied entries ending with '~' in the following option.
|
1110
|
+
# ======================================================================= #
|
1111
|
+
if ignore_backups?
|
1112
|
+
directory_content?.ignore_backups
|
1113
|
+
end
|
68
1114
|
end
|
69
1115
|
|
70
1116
|
# ========================================================================= #
|
71
|
-
# ===
|
1117
|
+
# === consider_sorting_by
|
72
1118
|
#
|
73
|
-
#
|
1119
|
+
# This is the specific sorting-action. The method will delegate onto
|
1120
|
+
# class DirectoryContent::ShowDirectoryContent.
|
74
1121
|
# ========================================================================= #
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
if use_colours?
|
80
|
-
e colourize_directory(which_dir?)
|
81
|
-
else
|
82
|
-
e which_dir?
|
83
|
-
end
|
84
|
-
n_KB = (total_file_size / 1024.0)
|
85
|
-
n_MB = (n_KB / 1024.0)
|
86
|
-
e steelblue(
|
87
|
-
" #{total_file_size} bytes (#{n_KB.round(2)} KB) (#{n_MB.round(2)} MB)"
|
88
|
-
)
|
89
|
-
end
|
1122
|
+
def consider_sorting_by(
|
1123
|
+
i = sort_by?
|
1124
|
+
)
|
1125
|
+
directory_content?.consider_sorting_by(i)
|
90
1126
|
end
|
91
1127
|
|
92
1128
|
# ========================================================================= #
|
93
|
-
# ===
|
1129
|
+
# === shorten_file_elegantly
|
1130
|
+
#
|
1131
|
+
# We need to take into account that our file could be a directory too.
|
94
1132
|
# ========================================================================= #
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
1133
|
+
def shorten_file_elegantly(
|
1134
|
+
i, threshold = FILE_SIZE_THRESHOLD
|
1135
|
+
)
|
1136
|
+
i = i.to_s.dup
|
1137
|
+
middle_pos = (i.size / 2) - 10
|
1138
|
+
oversize = i.size - threshold # The oversize value
|
1139
|
+
if oversize > 0
|
1140
|
+
start_pos = middle_pos - (oversize / 2)
|
1141
|
+
end_pos = start_pos + oversize
|
1142
|
+
i[start_pos .. end_pos] = '[… Truncated …]' # This is the padding to use.
|
100
1143
|
end
|
1144
|
+
return i
|
101
1145
|
end
|
102
1146
|
|
103
1147
|
# ========================================================================= #
|
104
|
-
# ===
|
1148
|
+
# === do_not_display_content
|
105
1149
|
# ========================================================================= #
|
106
|
-
def
|
107
|
-
@internal_hash[:
|
108
|
-
end
|
109
|
-
alias sort_by set_sort_by # === sort_by
|
1150
|
+
def do_not_display_content
|
1151
|
+
@internal_hash[:display_content] = false # if true, we display() the result.
|
1152
|
+
end
|
110
1153
|
|
111
1154
|
# ========================================================================= #
|
112
|
-
# ===
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#
|
119
|
-
#
|
120
|
-
# - in a reversed manner
|
1155
|
+
# === do_show_the_content
|
1156
|
+
# ========================================================================= #
|
1157
|
+
def do_show_the_content
|
1158
|
+
@internal_hash[:display_content] = true
|
1159
|
+
end; alias do_display_content do_show_the_content # === do_display_content
|
1160
|
+
|
1161
|
+
# ========================================================================= #
|
1162
|
+
# === colourize_symlink
|
121
1163
|
#
|
1164
|
+
# Use this method to colourize a symlink.
|
122
1165
|
# ========================================================================= #
|
123
|
-
def
|
124
|
-
|
125
|
-
)
|
126
|
-
how = how.to_s.downcase.to_sym # We want a downcased Symbol here.
|
127
|
-
case how # case tag
|
128
|
-
# ======================================================================= #
|
129
|
-
# === :reversed
|
130
|
-
# ======================================================================= #
|
131
|
-
when :reversed,
|
132
|
-
:reverse,
|
133
|
-
:by_reverse,
|
134
|
-
:by_reversed
|
135
|
-
set_sort_by(:reversed)
|
136
|
-
# ======================================================================= #
|
137
|
-
# === :date
|
138
|
-
# ======================================================================= #
|
139
|
-
when :date,
|
140
|
-
:by_date
|
141
|
-
set_sort_by(:date)
|
1166
|
+
def colourize_symlink(i)
|
1167
|
+
result = return_name_of_this_symlink(i)
|
142
1168
|
# ======================================================================= #
|
143
|
-
#
|
144
|
-
# ======================================================================= #
|
145
|
-
when :size,
|
146
|
-
:sized,
|
147
|
-
:by_size # Sort by size.
|
148
|
-
set_sort_by(:size)
|
149
|
-
# ======================================================================= #
|
150
|
-
# === :modification_time
|
1169
|
+
# Check whether we will use colours or whether we will not.
|
151
1170
|
# ======================================================================= #
|
152
|
-
|
153
|
-
|
154
|
-
|
1171
|
+
if File.symlink?(i)
|
1172
|
+
if use_colours?
|
1173
|
+
if stop_on_missing_symlink? and !File.readlink?(i)
|
1174
|
+
opn; e "The symlink for #{i} does not exist."
|
1175
|
+
opn; e 'Exiting now, as set per a configuration option.'
|
1176
|
+
exit
|
1177
|
+
end
|
1178
|
+
result = " → #{skyblue(File.readlink(i))}" # Need to readlink on the original variant.
|
1179
|
+
else
|
1180
|
+
result = " → #{File.readlink(i)}"
|
1181
|
+
end
|
155
1182
|
end
|
1183
|
+
return result
|
156
1184
|
end
|
157
1185
|
|
158
1186
|
# ========================================================================= #
|
159
|
-
# ===
|
1187
|
+
# === return_name_of_this_symlink
|
160
1188
|
#
|
161
|
-
#
|
1189
|
+
# File.basename() kills off leading '/', hence we need this method.
|
1190
|
+
# ========================================================================= #
|
1191
|
+
def return_name_of_this_symlink(i)
|
1192
|
+
i = File.basename(i)
|
1193
|
+
if return_pwd == '/' and show_leading_slash?
|
1194
|
+
i.prepend '/'
|
1195
|
+
end
|
1196
|
+
return i
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
# ========================================================================= #
|
1200
|
+
# === do_show_only_symlinks
|
1201
|
+
# ========================================================================= #
|
1202
|
+
def do_show_only_symlinks
|
1203
|
+
@internal_hash[:show_only_symlinks] = true
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
# ========================================================================= #
|
1207
|
+
# === toggle_permission
|
1208
|
+
# ========================================================================= #
|
1209
|
+
def toggle_permission
|
1210
|
+
_ = @internal_hash[:show_condensed_permissions]
|
1211
|
+
@internal_hash[:show_condensed_permissions] = !_ # Toggle it here.
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
# ========================================================================= #
|
1215
|
+
# === do_not_display_only_directories
|
1216
|
+
# ========================================================================= #
|
1217
|
+
def do_not_display_only_directories
|
1218
|
+
@internal_hash[:display_only_directories] = false # Whether to display only directories or not.
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
# ========================================================================= #
|
1222
|
+
# === do_not_show_permissions
|
1223
|
+
# ========================================================================= #
|
1224
|
+
def do_not_show_permissions
|
1225
|
+
@internal_hash[:show_permission_bits] = false
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
# ========================================================================= #
|
1229
|
+
# === do_show_header
|
1230
|
+
# ========================================================================= #
|
1231
|
+
def do_show_header
|
1232
|
+
@internal_hash[:show_header] = true
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
# ========================================================================= #
|
1236
|
+
# === do_sort_reversed
|
1237
|
+
# ========================================================================= #
|
1238
|
+
def do_sort_reversed
|
1239
|
+
sort_how :reverse
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
# ========================================================================= #
|
1243
|
+
# === do_not_show_group_information
|
1244
|
+
# ========================================================================= #
|
1245
|
+
def do_not_show_group_information
|
1246
|
+
@internal_hash[:show_group_information] = false
|
1247
|
+
end; alias no_groups do_not_show_group_information # === no_groups
|
1248
|
+
|
1249
|
+
# ========================================================================= #
|
1250
|
+
# === do_not_show_the_owner
|
1251
|
+
# ========================================================================= #
|
1252
|
+
def do_not_show_the_owner
|
1253
|
+
@internal_hash[:show_owner] = false
|
1254
|
+
end
|
1255
|
+
|
1256
|
+
# ========================================================================= #
|
1257
|
+
# === do_show_group_information
|
1258
|
+
# ========================================================================= #
|
1259
|
+
def do_show_group_information
|
1260
|
+
@internal_hash[:show_group_information] = true
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
# ========================================================================= #
|
1264
|
+
# === do_show_owner
|
1265
|
+
# ========================================================================= #
|
1266
|
+
def do_show_owner
|
1267
|
+
@internal_hash[:show_owner] = true
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
# ========================================================================= #
|
1271
|
+
# === do_not_show_leading_slash
|
1272
|
+
# ========================================================================= #
|
1273
|
+
def do_not_show_leading_slash
|
1274
|
+
@internal_hash[:show_leading_slash] = false
|
1275
|
+
end
|
1276
|
+
|
1277
|
+
# ========================================================================= #
|
1278
|
+
# === do_show_permissions
|
1279
|
+
# ========================================================================= #
|
1280
|
+
def do_show_permissions
|
1281
|
+
@internal_hash[:show_permission_bits] = true
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
# ========================================================================= #
|
1285
|
+
# === only_directories
|
162
1286
|
#
|
163
|
-
#
|
1287
|
+
# Only get directories, with this method.
|
1288
|
+
# ========================================================================= #
|
1289
|
+
def only_directories
|
1290
|
+
@internal_hash[:display_only_directories] = true
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
# ========================================================================= #
|
1294
|
+
# === run_then_display
|
1295
|
+
# ========================================================================= #
|
1296
|
+
def run_then_display
|
1297
|
+
run
|
1298
|
+
display
|
1299
|
+
end; alias gather_then_display_content run_then_display # === gather_then_display_content
|
1300
|
+
|
1301
|
+
# ========================================================================= #
|
1302
|
+
# === show_header?
|
164
1303
|
#
|
1304
|
+
# Whether we will show the header or whether we will not. That header
|
1305
|
+
# is not typical for the normal GNU "ls" command, hence why we need
|
1306
|
+
# to have such an option.
|
165
1307
|
# ========================================================================= #
|
166
|
-
def
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
1308
|
+
def show_header?
|
1309
|
+
@internal_hash[:show_header]
|
1310
|
+
end
|
1311
|
+
|
1312
|
+
# ========================================================================= #
|
1313
|
+
# === colourize_kb_and_mb?
|
1314
|
+
# ========================================================================= #
|
1315
|
+
def colourize_kb_and_mb?
|
1316
|
+
@internal_hash[:colourize_kb_and_mb]
|
1317
|
+
end
|
1318
|
+
|
1319
|
+
# ========================================================================= #
|
1320
|
+
# === stop_on_missing_symlink?
|
1321
|
+
# ========================================================================= #
|
1322
|
+
def stop_on_missing_symlink?
|
1323
|
+
@internal_hash[:stop_on_missing_symlink]
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
# ========================================================================= #
|
1327
|
+
# === show_condensed_permissions?
|
1328
|
+
# ========================================================================= #
|
1329
|
+
def show_condensed_permissions?
|
1330
|
+
@internal_hash[:show_condensed_permissions]
|
1331
|
+
end; alias condensed? show_condensed_permissions? # === condensed?
|
1332
|
+
|
1333
|
+
# ========================================================================= #
|
1334
|
+
# === owner?
|
1335
|
+
# ========================================================================= #
|
1336
|
+
def owner?(i)
|
1337
|
+
@internal_hash[:directory_content].owner?(i)
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
# ========================================================================= #
|
1341
|
+
# === truncate_long_file_names?
|
1342
|
+
# ========================================================================= #
|
1343
|
+
def truncate_long_file_names?
|
1344
|
+
@internal_hash[:truncate_long_file_names]
|
1345
|
+
end
|
1346
|
+
|
1347
|
+
# ========================================================================= #
|
1348
|
+
# === show_modification_time?
|
1349
|
+
# ========================================================================= #
|
1350
|
+
def show_modification_time?
|
1351
|
+
@internal_hash[:show_modification_time]
|
1352
|
+
end
|
1353
|
+
|
1354
|
+
# ========================================================================= #
|
1355
|
+
# === show_leading_slash?
|
1356
|
+
# ========================================================================= #
|
1357
|
+
def show_leading_slash?
|
1358
|
+
@internal_hash[:show_leading_slash]
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
# ========================================================================= #
|
1362
|
+
# === colour_for_files?
|
1363
|
+
# ========================================================================= #
|
1364
|
+
def colour_for_files?
|
1365
|
+
@internal_hash[:colour_for_files]
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
# ========================================================================= #
|
1369
|
+
# === colour_for_symlinks?
|
1370
|
+
# ========================================================================= #
|
1371
|
+
def colour_for_symlinks?
|
1372
|
+
@internal_hash[:colour_for_symlinks]
|
1373
|
+
end
|
1374
|
+
|
1375
|
+
# ========================================================================= #
|
1376
|
+
# === colour_for_directories?
|
1377
|
+
# ========================================================================= #
|
1378
|
+
def colour_for_directories?
|
1379
|
+
@internal_hash[:colour_for_directories]
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
# ========================================================================= #
|
1383
|
+
# === show_simplified?
|
1384
|
+
# ========================================================================= #
|
1385
|
+
def show_simplified?
|
1386
|
+
@internal_hash[:show_simplified]
|
188
1387
|
end
|
189
1388
|
|
190
1389
|
# ========================================================================= #
|
@@ -199,7 +1398,7 @@ class Report < Base # === DirectoryParadise::Report
|
|
199
1398
|
# ========================================================================= #
|
200
1399
|
def consider_sorting
|
201
1400
|
if sort_by?
|
202
|
-
|
1401
|
+
@internal_hash[:directory_content].do_sort(sort_by?)
|
203
1402
|
end
|
204
1403
|
end
|
205
1404
|
|
@@ -222,6 +1421,7 @@ class Report < Base # === DirectoryParadise::Report
|
|
222
1421
|
def report(
|
223
1422
|
_ = return_directory_content # This will return a Hash.
|
224
1423
|
)
|
1424
|
+
result?.clear # Clear the old results.
|
225
1425
|
@internal_hash[:total_filesize] = 0 # Reset it always here.
|
226
1426
|
show_condensed_permissions = show_condensed_permissions?
|
227
1427
|
show_the_index = show_index?
|
@@ -259,9 +1459,12 @@ class Report < Base # === DirectoryParadise::Report
|
|
259
1459
|
# =================================================================== #
|
260
1460
|
# Last but not least notify the user of the findings.
|
261
1461
|
# =================================================================== #
|
262
|
-
|
263
|
-
|
264
|
-
|
1462
|
+
cmd = "#{rev}The directory #{sdir(work_on_which_directory?)}"
|
1463
|
+
append(
|
1464
|
+
"The directory #{work_on_which_directory?}"
|
1465
|
+
)
|
1466
|
+
e cmd
|
1467
|
+
cmd = "#{rev}contains "+
|
265
1468
|
sfile(
|
266
1469
|
n_files.to_s+' file'+file_string
|
267
1470
|
)+', '+
|
@@ -271,31 +1474,50 @@ class Report < Base # === DirectoryParadise::Report
|
|
271
1474
|
ssymlink(
|
272
1475
|
n_symlinks.to_s+' symlink'+symlink_string
|
273
1476
|
)+'.'
|
1477
|
+
append("contains "+
|
1478
|
+
n_files.to_s+' file'+file_string+
|
1479
|
+
', '+
|
1480
|
+
n_directories.to_s+' director'+directory_string+
|
1481
|
+
' and '+
|
1482
|
+
n_symlinks.to_s+' symlink'+symlink_string+
|
1483
|
+
'.'
|
1484
|
+
)
|
1485
|
+
e cmd
|
274
1486
|
end
|
275
1487
|
header = ''.dup
|
276
1488
|
header << "#{rev}" if use_colours?
|
1489
|
+
append(:liner)
|
277
1490
|
# ===================================================================== #
|
278
1491
|
# Add the index next onto the header.
|
279
1492
|
# ===================================================================== #
|
280
1493
|
if show_the_index
|
281
|
-
|
1494
|
+
padded = 'Index'.ljust(6)
|
1495
|
+
header << sfancy(padded)
|
1496
|
+
raw_append(padded)
|
282
1497
|
end
|
283
1498
|
# ===================================================================== #
|
284
1499
|
# Show permission bits
|
285
1500
|
# ===================================================================== #
|
286
1501
|
if show_permission_bits
|
287
|
-
|
1502
|
+
permissions = 'Permissions'.ljust(16)
|
1503
|
+
header << springgreen(permissions)
|
1504
|
+
raw_append(permissions)
|
288
1505
|
end
|
289
1506
|
# ===================================================================== #
|
290
1507
|
# Next, determine whether we will display the modification-time
|
291
1508
|
# or whether we will not:
|
292
1509
|
# ===================================================================== #
|
293
1510
|
if show_modification_time
|
294
|
-
|
1511
|
+
modtime = 'ModTime'.ljust(8)
|
1512
|
+
raw_append(modtime)
|
1513
|
+
header << modtime
|
295
1514
|
end
|
296
1515
|
header << 'FileSize'.ljust(9)
|
1516
|
+
raw_append('FileSize'.ljust(9))
|
297
1517
|
header << 'Name'.ljust(5)
|
1518
|
+
append('Name'.ljust(5))
|
298
1519
|
eliner
|
1520
|
+
append(:liner)
|
299
1521
|
e header
|
300
1522
|
end
|
301
1523
|
# ======================================================================= #
|
@@ -357,6 +1579,7 @@ class Report < Base # === DirectoryParadise::Report
|
|
357
1579
|
end
|
358
1580
|
index_to_display = ("(#{index})") # Add () here as well.
|
359
1581
|
index_to_display = index_to_display.ljust(use_this_value_for_ljusting)
|
1582
|
+
raw_append(index_to_display)
|
360
1583
|
if use_colours?
|
361
1584
|
index_to_display.gsub!(/\((.+)\)/, '('+sfancy("\\1")+')')
|
362
1585
|
end
|
@@ -372,14 +1595,22 @@ class Report < Base # === DirectoryParadise::Report
|
|
372
1595
|
# =================================================================== #
|
373
1596
|
if show_inode?
|
374
1597
|
inode = ' Inode: '
|
1598
|
+
raw_append(inode)
|
375
1599
|
inode = simp(inode) if use_colours?
|
376
1600
|
line << inode+File.stat(path).ino.to_s # Add the Inode here.
|
1601
|
+
append(File.stat(path).ino.to_s)
|
377
1602
|
end
|
378
1603
|
# =================================================================== #
|
379
1604
|
# Next show the permission bits, if requested to do so.
|
380
1605
|
# =================================================================== #
|
1606
|
+
raw_append("#{return_chmod_value_of_this_file(path).ljust(5)}")
|
381
1607
|
line << springgreen("#{return_chmod_value_of_this_file(path).ljust(5)}")
|
382
1608
|
unless show_condensed_permissions
|
1609
|
+
raw_append(
|
1610
|
+
return_file_permission_of(
|
1611
|
+
inner_hash[:ascii_representation]
|
1612
|
+
).ljust(11)
|
1613
|
+
)
|
383
1614
|
line << return_file_permission_of(
|
384
1615
|
inner_hash[:ascii_representation]
|
385
1616
|
).ljust(11)
|
@@ -393,9 +1624,11 @@ class Report < Base # === DirectoryParadise::Report
|
|
393
1624
|
# This could be last_modified.strftime(' %d.%m.%Y %H:%M') instead.
|
394
1625
|
# ===================================================================== #
|
395
1626
|
if show_modification_time?
|
1627
|
+
raw_append("#{return_assumed_modification_time(last_modified)} ")
|
396
1628
|
line << "#{return_assumed_modification_time(last_modified)} "
|
397
1629
|
end
|
398
|
-
|
1630
|
+
original_file_size_as_string = file_size.rjust(8)
|
1631
|
+
file_size = original_file_size_as_string.dup
|
399
1632
|
# ===================================================================== #
|
400
1633
|
# Insert proper units next.
|
401
1634
|
# ===================================================================== #
|
@@ -418,6 +1651,7 @@ class Report < Base # === DirectoryParadise::Report
|
|
418
1651
|
# prevent mis-alignments.
|
419
1652
|
# ===================================================================== #
|
420
1653
|
unless show_simplified?
|
1654
|
+
raw_append(" #{name_of_owner.ljust(6)}")
|
421
1655
|
line << " #{name_of_owner.ljust(6)}"
|
422
1656
|
end
|
423
1657
|
# ===================================================================== #
|
@@ -427,12 +1661,14 @@ class Report < Base # === DirectoryParadise::Report
|
|
427
1661
|
# ===================================================================== #
|
428
1662
|
if show_group_information?
|
429
1663
|
if inner_hash and inner_hash[:name_of_group]
|
1664
|
+
raw_append(" #{inner_hash[:name_of_group].ljust(7)}")
|
430
1665
|
line << " #{inner_hash[:name_of_group].ljust(7)}"
|
431
1666
|
end
|
432
1667
|
end
|
433
1668
|
# ===================================================================== #
|
434
1669
|
# Add the file size next:
|
435
1670
|
# ===================================================================== #
|
1671
|
+
raw_append(" #{original_file_size_as_string}")
|
436
1672
|
line << " #{file_size}"
|
437
1673
|
# ===================================================================== #
|
438
1674
|
# === Truncate long file names
|
@@ -455,7 +1691,8 @@ class Report < Base # === DirectoryParadise::Report
|
|
455
1691
|
if File.directory?(path) and !path.end_with?('/')
|
456
1692
|
path << '/'
|
457
1693
|
end
|
458
|
-
|
1694
|
+
raw_append(" #{path}")
|
1695
|
+
line << " #{steelblue(path)}" # ← Add the filename here.
|
459
1696
|
if colourize_path and path.include?('/')
|
460
1697
|
splitted = path.split('/')
|
461
1698
|
# =================================================================== #
|
@@ -465,6 +1702,7 @@ class Report < Base # === DirectoryParadise::Report
|
|
465
1702
|
if File.directory? last
|
466
1703
|
last << '/' unless last.end_with?('/')
|
467
1704
|
end
|
1705
|
+
raw_append(splitted[0..-2].join('/')+'/'+last)
|
468
1706
|
last = lightblue(last)
|
469
1707
|
path = splitted[0..-2].join('/')+'/'+last
|
470
1708
|
end
|
@@ -480,11 +1718,13 @@ class Report < Base # === DirectoryParadise::Report
|
|
480
1718
|
line << colourize_symlink(path)
|
481
1719
|
end
|
482
1720
|
end
|
1721
|
+
append_newline
|
483
1722
|
# ===================================================================== #
|
484
1723
|
# Finally display the line to the user.
|
485
1724
|
# ===================================================================== #
|
486
1725
|
e line
|
487
1726
|
}
|
1727
|
+
append(:liner)
|
488
1728
|
eliner
|
489
1729
|
# ======================================================================= #
|
490
1730
|
# Only add the filesize if we will report it.
|
@@ -499,7 +1739,97 @@ class Report < Base # === DirectoryParadise::Report
|
|
499
1739
|
alias display_main_string report # === display_main_string
|
500
1740
|
|
501
1741
|
# ========================================================================= #
|
502
|
-
# ===
|
1742
|
+
# === result?
|
1743
|
+
#
|
1744
|
+
# This will show the string that can be displayed.
|
1745
|
+
# ========================================================================= #
|
1746
|
+
def result?
|
1747
|
+
@internal_hash[:result]
|
1748
|
+
end
|
1749
|
+
|
1750
|
+
# ========================================================================= #
|
1751
|
+
# === string?
|
1752
|
+
# ========================================================================= #
|
1753
|
+
def string?
|
1754
|
+
result?.to_s
|
1755
|
+
end; alias text? string? # === text?
|
1756
|
+
|
1757
|
+
# ========================================================================= #
|
1758
|
+
# === append_to_the_result
|
1759
|
+
#
|
1760
|
+
# This currently always appends with a newline as well.
|
1761
|
+
# ========================================================================= #
|
1762
|
+
def append_to_the_result(i)
|
1763
|
+
case i
|
1764
|
+
# ======================================================================= #
|
1765
|
+
# === :liner
|
1766
|
+
# ======================================================================= #
|
1767
|
+
when :liner,
|
1768
|
+
:cliner
|
1769
|
+
i = '―' * 80
|
1770
|
+
end
|
1771
|
+
@internal_hash[:result] << "#{i}\n"
|
1772
|
+
end; alias append append_to_the_result # === append
|
1773
|
+
|
1774
|
+
# ========================================================================= #
|
1775
|
+
# === append_newline
|
1776
|
+
# ========================================================================= #
|
1777
|
+
def append_newline
|
1778
|
+
@internal_hash[:result] << "\n"
|
1779
|
+
end
|
1780
|
+
|
1781
|
+
# ========================================================================= #
|
1782
|
+
# === raw_append
|
1783
|
+
# ========================================================================= #
|
1784
|
+
def raw_append(i)
|
1785
|
+
@internal_hash[:result] << i
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
# ========================================================================= #
|
1789
|
+
# === rev
|
1790
|
+
#
|
1791
|
+
# The rev value can be re-defined by the user of this class.
|
1792
|
+
# ========================================================================= #
|
1793
|
+
def rev
|
1794
|
+
@internal_hash[:default_colour]
|
1795
|
+
end
|
1796
|
+
|
1797
|
+
# ========================================================================= #
|
1798
|
+
# === define_colours
|
1799
|
+
#
|
1800
|
+
# define_colours() is called from reset()
|
1801
|
+
# ========================================================================= #
|
1802
|
+
def define_colours(
|
1803
|
+
optional_hash_use_these_colours = nil
|
1804
|
+
) # Colours tag, colors tag.
|
1805
|
+
_ = optional_hash_use_these_colours
|
1806
|
+
if use_colours?
|
1807
|
+
if _ # If the Hash is defined, enter here.
|
1808
|
+
pp 111
|
1809
|
+
@internal_hash[:default_colour] = Colours.beautiful _['colour_for_normal']
|
1810
|
+
@internal_hash[:colour_for_files] = Colours.beautiful _['colour_for_files']
|
1811
|
+
@internal_hash[:colour_for_symlinks] = Colours.beautiful _['colour_for_symlinks']
|
1812
|
+
@internal_hash[:colour_for_directories] = Colours.beautiful _['colour_for_directories']
|
1813
|
+
else # Try to use Konsole after this point.
|
1814
|
+
if Object.const_defined? :Colours
|
1815
|
+
pp 222
|
1816
|
+
@internal_hash[:default_colour] = Colours.restore? # Restore the default again.
|
1817
|
+
@internal_hash[:colour_for_files] = Colours.springgreen
|
1818
|
+
@internal_hash[:colour_for_symlinks] = Colours.slateblue
|
1819
|
+
@internal_hash[:colour_for_directories] = Colours.paleturquoise
|
1820
|
+
else # Else, use the default colours. They are defined in the module Colours.
|
1821
|
+
pp 333
|
1822
|
+
@internal_hash[:default_colour] = Colours::WHITE
|
1823
|
+
@internal_hash[:colour_for_files] = Colours::GREEN
|
1824
|
+
@internal_hash[:colour_for_symlinks] = Colours::BLUE
|
1825
|
+
@internal_hash[:colour_for_directories] = Colours::CYAN # Which colour to use for directories.
|
1826
|
+
end
|
1827
|
+
end
|
1828
|
+
end
|
1829
|
+
end
|
1830
|
+
|
1831
|
+
# ========================================================================= #
|
1832
|
+
# === run (run tag)
|
503
1833
|
# ========================================================================= #
|
504
1834
|
def run
|
505
1835
|
check_whether_we_use_colours
|
@@ -520,8 +1850,25 @@ end; self.instance_eval { alias [] show } # === DirectoryParadise[]
|
|
520
1850
|
self.instance_eval { alias do_show show } # === DirectoryParadise.do_show
|
521
1851
|
self.instance_eval { alias report show } # === DirectoryParadise.report
|
522
1852
|
|
1853
|
+
# =========================================================================== #
|
1854
|
+
# === DirectoryParadise.new
|
1855
|
+
# =========================================================================== #
|
1856
|
+
def self.new(
|
1857
|
+
work_on_this_directory = return_pwd,
|
1858
|
+
run_already = true
|
1859
|
+
)
|
1860
|
+
DirectoryParadise.new(work_on_this_directory, run_already)
|
1861
|
+
end
|
1862
|
+
|
523
1863
|
end
|
524
1864
|
|
525
1865
|
if __FILE__ == $PROGRAM_NAME
|
526
|
-
|
1866
|
+
alias e puts
|
1867
|
+
_ = DirectoryParadise.report(ARGV)
|
1868
|
+
#pp _
|
1869
|
+
# _.print_the_namespace
|
1870
|
+
e
|
1871
|
+
e 'The raw string is:'
|
1872
|
+
e
|
1873
|
+
e _.result?
|
527
1874
|
end # rcontent
|