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, show_group: true, show_user: true) ⇒ 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, show_group: true, show_user: true) ⇒ Core
Returns a new instance of Core.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/colorls/core.rb', line 12 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, show_group: true, show_user: true) @input = (+input).force_encoding(ColorLS.file_encoding) @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 init_long_format(mode,show_group,show_user) @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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/colorls/core.rb', line 40 def ls return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty? layout = case when @tree[:mode] 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 |