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, git_status: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: true) ⇒ Core

Returns a new instance of Core.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/colorls/core.rb', line 19

def initialize(all: false, sort: false, show: false,
  mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
  reverse: false, hyperlink: false, tree_depth: nil, show_group: true, show_user: 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
  init_long_format(mode,show_group,show_user)
  @tree         = {mode: mode == :tree, depth: tree_depth}
  @horizontal   = mode == :horizontal
  @git_status   = init_git_status(git_status)

  init_colors colors

  init_icons
end

Instance Method Details

#display_reportObject



68
69
70
71
72
73
74
75
# File 'lib/colorls/core.rb', line 68

def display_report
  print "\n   Found #{@count.values.sum} items in total.".colorize(@colors[:report])

  puts  "\n\n\tFolders\t\t\t: #{@count[:folders]}"\
    "\n\tRecognized files\t: #{@count[:recognized_files]}"\
    "\n\tUnrecognized files\t: #{@count[:unrecognized_files]}"
    .colorize(@colors[:report])
end

#ls_dir(info) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/colorls/core.rb', line 41

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



62
63
64
65
66
# File 'lib/colorls/core.rb', line 62

def ls_files(files)
  @contents = files

  ls
end