Class: ColorLS::Core
- Inherits:
-
Object
- Object
- ColorLS::Core
- Defined in:
- lib/colorls/core.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- MIN_SIZE_CHARS =
4
Instance Method Summary collapse
- #additional_chars_per_item ⇒ Object
- #display_report(report_mode) ⇒ Object
-
#initialize(all: false, sort: false, show: false, mode: nil, show_git: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, indicator_style: 'slash', long_style_options: {}, icons: true) ⇒ Core
constructor
A new instance of Core.
- #ls_dir(info) ⇒ Object
- #ls_files(files) ⇒ Object
Constructor Details
#initialize(all: false, sort: false, show: false, mode: nil, show_git: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, indicator_style: 'slash', long_style_options: {}, icons: true) ⇒ Core
Returns a new instance of Core.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/colorls/core.rb', line 30 def initialize(all: false, sort: false, show: false, mode: nil, show_git: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil, show_inode: false, indicator_style: 'slash', long_style_options: {}, icons: true) @count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @all = all @almost_all = almost_all @hyperlink = hyperlink @sort = sort @reverse = reverse @group = group @show = show @one_per_line = mode == :one_per_line @show_inode = show_inode init_long_format(mode,) @tree = {mode: mode == :tree, depth: tree_depth} @horizontal = mode == :horizontal @git_status = init_git_status(show_git) @time_style = .key?(:time_style) ? [:time_style] : '' @indicator_style = indicator_style @hard_links_count = .key?(:hard_links_count) ? [:hard_links_count] : true @icons = icons init_colors colors init_icons end |
Instance Method Details
#additional_chars_per_item ⇒ Object
57 58 59 |
# File 'lib/colorls/core.rb', line 57 def additional_chars_per_item 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0) end |
#display_report(report_mode) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/colorls/core.rb', line 88 def display_report(report_mode) if report_mode == :short puts <<~REPORT \s\s\s\sFolders: #{@count[:folders]}, Files: #{@count[:recognized_files] + @count[:unrecognized_files]}. REPORT .colorize(@colors[:report]) else puts <<~REPORT Found #{@count.values.sum} items in total. \tFolders\t\t\t: #{@count[:folders]} \tRecognized files\t: #{@count[:recognized_files]} \tUnrecognized files\t: #{@count[:unrecognized_files]} REPORT .colorize(@colors[:report]) end end |
#ls_dir(info) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/colorls/core.rb', line 61 def ls_dir(info) if @tree[:mode] print "\n" return tree_traverse(info.path, 0, 1, 2) end @contents = Dir.entries(info.path, encoding: ColorLS.file_encoding) filter_hidden_contents @contents.map! { |e| FileInfo.dir_entry(info.path, e, link_info: @long) } filter_contents if @show sort_contents if @sort group_contents if @group return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty? ls end |
#ls_files(files) ⇒ Object
82 83 84 85 86 |
# File 'lib/colorls/core.rb', line 82 def ls_files(files) @contents = files ls end |