Class: ColorLS::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/colorls/core.rb

Instance Method Summary collapse

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: {}) ⇒ Core

Returns a new instance of Core.



28
29
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 28

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: {})
  @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,long_style_options)
  @tree         = {mode: mode == :tree, depth: tree_depth}
  @horizontal   = mode == :horizontal
  @git_status   = init_git_status(show_git)
  @time_style   = long_style_options.key?(:time_style) ? long_style_options[:time_style] : ''
  @indicator_style = indicator_style
  @hard_links_count = long_style_options.key?(:hard_links_count) ? long_style_options[:hard_links_count] : true
  # how much characters an item occupies besides its name
  @additional_chars_per_item = 12 + (@show_git ? 4 : 0) + (@show_inode ? 10 : 0)

  init_colors colors

  init_icons
end

Instance Method Details

#display_report(report_mode) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/colorls/core.rb', line 84

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/colorls/core.rb', line 57

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



78
79
80
81
82
# File 'lib/colorls/core.rb', line 78

def ls_files(files)
  @contents = files

  ls
end