Class: ColorLS::Core
- Inherits:
-
Object
- Object
- ColorLS::Core
- Defined in:
- lib/colorls/core.rb
Instance Method Summary collapse
-
#initialize(input, all: false, report: false, sort: false, show: false, mode: nil, git_status: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil) ⇒ Core
constructor
A new instance of Core.
- #ls ⇒ Object
Constructor Details
#initialize(input, all: false, report: false, sort: false, show: false, mode: nil, git_status: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil) ⇒ Core
Returns a new instance of Core.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/colorls/core.rb', line 5 def initialize(input, all: false, report: false, sort: false, show: false, mode: nil, git_status: false, almost_all: false, colors: [], group: nil, reverse: false, hyperlink: false, tree_depth: nil) @input = File.absolute_path(input) @count = {folders: 0, recognized_files: 0, unrecognized_files: 0} @all = all @almost_all = almost_all @hyperlink = hyperlink @report = report @sort = sort @reverse = reverse @group = group @show = show @one_per_line = mode == :one_per_line @long = mode == :long @tree = {mode: mode == :tree, depth: tree_depth} @horizontal = mode == :horizontal process_git_status_details(git_status) @screen_width = IO.console.winsize[1] @screen_width = 80 if @screen_width.zero? init_colors colors @contents = init_contents(input) init_icons end |
Instance Method Details
#ls ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/colorls/core.rb', line 33 def ls return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty? layout = case when @tree[:mode] then print "\n" return tree_traverse(@input, 0, 1, 2) when @horizontal HorizontalLayout.new(@contents, item_widths, @screen_width) when @one_per_line || @long SingleColumnLayout.new(@contents) else VerticalLayout.new(@contents, item_widths, @screen_width) end layout.each_line do |line, widths| ls_line(line, widths) end display_report if @report true end |