colorls 1.2.1.pre.600 → 1.2.1.pre.603
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/colorls.rb +1 -0
- data/lib/colorls/core.rb +33 -47
- data/lib/colorls/flags.rb +7 -5
- data/lib/colorls/layout.rb +91 -0
- data/man/colorls.1 +8 -4
- data/zsh/_colorls +3 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb7f4f4123aa809327372636d3def2506fd78446e4177d8b2ba401aa93a6cc7
|
4
|
+
data.tar.gz: f24be4a1bf2306e84b2dd247eb4dba5b6a8a227c65b525cc9ddae4d4272da3d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ab762d41a7d746ffe9e992c7cf432577f8901d50fae7080446654eba5ad9c2a694158f4f3c3b63d073c2aa87c94f923024239f7ac6f13c47563f793da5a83cf
|
7
|
+
data.tar.gz: fb3563bb2a6da81520b6775518302a73ffcc46c1bbe36fa7b047431f64365a05ba9b032d8d27627257173a23f3cdb70bb30044335736ac38c1f1d4ea6f2143ab
|
data/lib/colorls.rb
CHANGED
data/lib/colorls/core.rb
CHANGED
@@ -18,6 +18,7 @@ module ColorLS
|
|
18
18
|
@one_per_line = mode == :one_per_line
|
19
19
|
@long = mode == :long
|
20
20
|
@tree = {mode: mode == :tree, depth: tree_depth}
|
21
|
+
@horizontal = mode == :horizontal
|
21
22
|
process_git_status_details(git_status)
|
22
23
|
|
23
24
|
@screen_width = IO.console.winsize[1]
|
@@ -26,20 +27,28 @@ module ColorLS
|
|
26
27
|
init_colors colors
|
27
28
|
|
28
29
|
@contents = init_contents(input)
|
29
|
-
@max_widths = @contents.map { |c| c.name.length }
|
30
30
|
init_icons
|
31
31
|
end
|
32
32
|
|
33
33
|
def ls
|
34
34
|
return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty?
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
layout = case
|
37
|
+
when @tree[:mode] then
|
38
|
+
print "\n"
|
39
|
+
return tree_traverse(@input, 0, 1, 2)
|
40
|
+
when @horizontal then
|
41
|
+
HorizontalLayout.new(@contents, item_widths, @screen_width)
|
42
|
+
when @one_per_line || @long then
|
43
|
+
SingleColumnLayout.new(@contents)
|
44
|
+
else
|
45
|
+
VerticalLayout.new(@contents, item_widths, @screen_width)
|
46
|
+
end
|
47
|
+
|
48
|
+
layout.each_line do |line, widths|
|
49
|
+
ls_line(line, widths)
|
42
50
|
end
|
51
|
+
|
43
52
|
display_report if @report
|
44
53
|
true
|
45
54
|
end
|
@@ -59,6 +68,13 @@ module ColorLS
|
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
71
|
+
# how much characters an item occupies besides its name
|
72
|
+
CHARS_PER_ITEM = 12
|
73
|
+
|
74
|
+
def item_widths
|
75
|
+
@contents.map { |item| item.name.size + CHARS_PER_ITEM }
|
76
|
+
end
|
77
|
+
|
62
78
|
def init_contents(path)
|
63
79
|
info = FileInfo.new(path, link_info = @long)
|
64
80
|
|
@@ -144,30 +160,6 @@ module ColorLS
|
|
144
160
|
@folder_aliases = ColorLS::Yaml.new('folder_aliases.yaml').load(aliase: true)
|
145
161
|
end
|
146
162
|
|
147
|
-
def chunkify
|
148
|
-
return @contents.zip if @one_per_line || @long
|
149
|
-
|
150
|
-
chunk_size = @contents.size
|
151
|
-
max_widths = @max_widths
|
152
|
-
|
153
|
-
until in_line(chunk_size, max_widths) || chunk_size <= 1
|
154
|
-
chunk_size -= 1
|
155
|
-
max_widths = @max_widths.each_slice(chunk_size).to_a
|
156
|
-
max_widths[-1] += [0] * (chunk_size - max_widths.last.size)
|
157
|
-
max_widths = max_widths.transpose.map(&:max)
|
158
|
-
end
|
159
|
-
@max_widths = max_widths
|
160
|
-
@contents = get_chunk(chunk_size)
|
161
|
-
end
|
162
|
-
|
163
|
-
def get_chunk(chunk_size)
|
164
|
-
@contents.each_slice(chunk_size).to_a
|
165
|
-
end
|
166
|
-
|
167
|
-
def in_line(chunk_size, max_widths)
|
168
|
-
(max_widths.sum + 12 * chunk_size <= @screen_width)
|
169
|
-
end
|
170
|
-
|
171
163
|
def display_report
|
172
164
|
print "\n Found #{@total_content_length} contents in directory "
|
173
165
|
.colorize(@colors[:report])
|
@@ -280,33 +272,27 @@ module ColorLS
|
|
280
272
|
end
|
281
273
|
end
|
282
274
|
|
283
|
-
def slash?(content)
|
284
|
-
content.directory? ? '/'.colorize(@colors[:dir]) : ' '
|
285
|
-
end
|
286
|
-
|
287
275
|
def fetch_string(path, content, key, color, increment)
|
288
276
|
@count[increment] += 1
|
289
277
|
value = increment == :folders ? @folders[key] : @files[key]
|
290
278
|
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }
|
291
279
|
name = content.name
|
292
280
|
name = make_link(path, name) if @hyperlink
|
281
|
+
name += content.directory? ? '/' : ' '
|
282
|
+
entry = logo + ' ' + name
|
293
283
|
|
294
|
-
|
295
|
-
long_info(content),
|
296
|
-
" #{git_info(content)} ",
|
297
|
-
logo.colorize(color),
|
298
|
-
" #{name.colorize(color)}#{slash?(content)}#{symlink_info(content)}"
|
299
|
-
].join
|
284
|
+
"#{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}"
|
300
285
|
end
|
301
286
|
|
302
|
-
def ls_line(chunk)
|
287
|
+
def ls_line(chunk, widths)
|
288
|
+
padding = 0
|
289
|
+
line = +''
|
303
290
|
chunk.each_with_index do |content, i|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
print ' ' * (@max_widths[i] - content.name.length) unless @one_per_line || @long
|
291
|
+
line << ' ' * padding
|
292
|
+
line << ' ' << fetch_string(@input, content, *options(content))
|
293
|
+
padding = widths[i] - content.name.length - CHARS_PER_ITEM
|
308
294
|
end
|
309
|
-
print "\n"
|
295
|
+
print line << "\n"
|
310
296
|
end
|
311
297
|
|
312
298
|
def file_color(file, key)
|
data/lib/colorls/flags.rb
CHANGED
@@ -15,7 +15,7 @@ module ColorLS
|
|
15
15
|
sort: true,
|
16
16
|
reverse: false,
|
17
17
|
group: nil,
|
18
|
-
mode: STDOUT.tty?
|
18
|
+
mode: STDOUT.tty? ? :vertical : :one_per_line,
|
19
19
|
all: false,
|
20
20
|
almost_all: false,
|
21
21
|
report: false,
|
@@ -106,22 +106,24 @@ module ColorLS
|
|
106
106
|
|
107
107
|
def add_format_options(options)
|
108
108
|
options.on(
|
109
|
-
'--format=WORD', %w[
|
110
|
-
'use format:
|
109
|
+
'--format=WORD', %w[across horizontal long single-column],
|
110
|
+
'use format: across (-x), horizontal (-x), long (-l), single-column (-1), vertical (-C)'
|
111
111
|
) do |word|
|
112
112
|
case word
|
113
|
-
when '
|
113
|
+
when 'across', 'horizontal' then @opts[:mode] = :horizontal
|
114
|
+
when 'vertical' then @opts[:mode] = :vertical
|
114
115
|
when 'long' then @opts[:mode] = :long
|
115
116
|
when 'single-column' then @opts[:mode] = :one_per_line
|
116
117
|
end
|
117
118
|
end
|
118
119
|
options.on('-1', 'list one file per line') { @opts[:mode] = :one_per_line }
|
119
120
|
options.on('-l', '--long', 'use a long listing format') { @opts[:mode] = :long }
|
120
|
-
options.on('-x', 'list entries by lines instead of by columns') { @opts[:mode] = true }
|
121
121
|
options.on('--tree=[DEPTH]', Integer, 'shows tree view of the directory') do |depth|
|
122
122
|
@opts[:tree_depth] = depth
|
123
123
|
@opts[:mode] = :tree
|
124
124
|
end
|
125
|
+
options.on('-x', 'list entries by lines instead of by columns') { @opts[:mode] = :horizontal }
|
126
|
+
options.on('-C', 'list entries by columns instead of by lines') { @opts[:mode] = :vertical }
|
125
127
|
end
|
126
128
|
|
127
129
|
def add_general_options(options)
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ColorLS
|
4
|
+
class Layout
|
5
|
+
def initialize(contents, widths, line_size)
|
6
|
+
@max_widths = widths
|
7
|
+
@contents = contents
|
8
|
+
@screen_width = line_size
|
9
|
+
end
|
10
|
+
|
11
|
+
def each_line
|
12
|
+
return if @contents.empty?
|
13
|
+
|
14
|
+
get_chunks(chunk_size).each { |line| yield(line.compact, @max_widths) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def chunk_size
|
20
|
+
min_size = @max_widths.min
|
21
|
+
max_chunks = [1, @screen_width / min_size].max
|
22
|
+
max_chunks = [max_chunks, @max_widths.size].min
|
23
|
+
min_chunks = 1
|
24
|
+
|
25
|
+
loop do
|
26
|
+
mid = ((max_chunks + min_chunks).to_f / 2).ceil
|
27
|
+
|
28
|
+
size, max_widths = column_widths(mid)
|
29
|
+
|
30
|
+
if min_chunks < max_chunks && not_in_line(max_widths)
|
31
|
+
max_chunks = mid - 1
|
32
|
+
elsif min_chunks < mid
|
33
|
+
min_chunks = mid
|
34
|
+
else
|
35
|
+
@max_widths = max_widths
|
36
|
+
return size
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def not_in_line(max_widths)
|
42
|
+
max_widths.sum > @screen_width
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class SingleColumnLayout < Layout
|
47
|
+
def initialize(contents)
|
48
|
+
super(contents, [1], 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def chunk_size
|
54
|
+
1
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_chunks(_chunk_size)
|
58
|
+
@contents.each_slice(1)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class HorizontalLayout < Layout
|
63
|
+
private
|
64
|
+
|
65
|
+
def column_widths(mid)
|
66
|
+
max_widths = @max_widths.each_slice(mid).to_a
|
67
|
+
last_size = max_widths.last.size
|
68
|
+
max_widths.last.fill(0, last_size, max_widths.first.size - last_size)
|
69
|
+
[mid, max_widths.transpose.map!(&:max)]
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_chunks(chunk_size)
|
73
|
+
@contents.each_slice(chunk_size)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class VerticalLayout < Layout
|
78
|
+
private
|
79
|
+
|
80
|
+
def column_widths(mid)
|
81
|
+
chunk_size = (@max_widths.size.to_f / mid).ceil
|
82
|
+
[chunk_size, @max_widths.each_slice(chunk_size).map(&:max).to_a]
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_chunks(chunk_size)
|
86
|
+
columns = @contents.each_slice(chunk_size).to_a
|
87
|
+
columns.last[chunk_size - 1] = nil if columns.last.size < chunk_size
|
88
|
+
columns.transpose
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/man/colorls.1
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "COLORLS" "1" "
|
4
|
+
.TH "COLORLS" "1" "July 2019" "colorls 1.2.0" "colorls Manual"
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
7
|
\fBcolorls\fR \- list directory contents with colors and icons
|
@@ -48,7 +48,7 @@ show brief report
|
|
48
48
|
.
|
49
49
|
.TP
|
50
50
|
\fB\-\-format\fR
|
51
|
-
use format:
|
51
|
+
use format: across (\-x), horizontal (\-x), long (\-l), single\-column (\-1), vertical (\-C)
|
52
52
|
.
|
53
53
|
.TP
|
54
54
|
\fB\-1\fR
|
@@ -59,12 +59,16 @@ list one file per line
|
|
59
59
|
use a long listing format
|
60
60
|
.
|
61
61
|
.TP
|
62
|
+
\fB\-\-tree\fR
|
63
|
+
shows tree view of the directory
|
64
|
+
.
|
65
|
+
.TP
|
62
66
|
\fB\-x\fR
|
63
67
|
list entries by lines instead of by columns
|
64
68
|
.
|
65
69
|
.TP
|
66
|
-
\fB
|
67
|
-
|
70
|
+
\fB\-C\fR
|
71
|
+
list entries by columns instead of by lines
|
68
72
|
.
|
69
73
|
.TP
|
70
74
|
\fB\-\-sd\fR, \fB\-\-sort\-dirs\fR, \fB\-\-group\-directories\-first\fR
|
data/zsh/_colorls
CHANGED
@@ -15,12 +15,13 @@ _arguments -s -S \
|
|
15
15
|
"--gs[show git status for each file]" \
|
16
16
|
"--git-status[show git status for each file]" \
|
17
17
|
"--report[show brief report]" \
|
18
|
-
"--format[use format:
|
18
|
+
"--format[use format: across (-x), horizontal (-x), long (-l), single-column (-1), vertical (-C)]" \
|
19
19
|
"-1[list one file per line]" \
|
20
20
|
"-l[use a long listing format]" \
|
21
21
|
"--long[use a long listing format]" \
|
22
|
-
"-x[list entries by lines instead of by columns]" \
|
23
22
|
"--tree[shows tree view of the directory]" \
|
23
|
+
"-x[list entries by lines instead of by columns]" \
|
24
|
+
"-C[list entries by columns instead of by lines]" \
|
24
25
|
"--sd[sort directories first]" \
|
25
26
|
"--sort-dirs[sort directories first]" \
|
26
27
|
"--group-directories-first[sort directories first]" \
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.1.pre.
|
4
|
+
version: 1.2.1.pre.603
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Athitya Kumar
|
@@ -283,6 +283,7 @@ files:
|
|
283
283
|
- lib/colorls/fileinfo.rb
|
284
284
|
- lib/colorls/flags.rb
|
285
285
|
- lib/colorls/git.rb
|
286
|
+
- lib/colorls/layout.rb
|
286
287
|
- lib/colorls/monkeys.rb
|
287
288
|
- lib/colorls/version.rb
|
288
289
|
- lib/colorls/yaml.rb
|