Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
581a1245
Commit
581a1245
authored
8 years ago
by
Markus Reiter
Browse files
Options
Downloads
Patches
Plain Diff
Move `Formatter.columns` into `utils/formatter`.
parent
ef70677e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/utils/formatter.rb
+41
-1
41 additions, 1 deletion
Library/Homebrew/utils/formatter.rb
Library/Homebrew/utils/formatter/columns.rb
+0
-46
0 additions, 46 deletions
Library/Homebrew/utils/formatter/columns.rb
with
41 additions
and
47 deletions
Library/Homebrew/utils/formatter.rb
+
41
−
1
View file @
581a1245
require
"utils/formatter/columns"
require
"utils/tty"
module
Formatter
...
...
@@ -50,4 +49,45 @@ module Formatter
end
end
private_class_method
:prefix
def
columns
(
*
objects
,
gap_size:
2
)
objects
=
objects
.
flatten
.
map
(
&
:to_s
)
fallback
=
proc
do
return
objects
.
join
(
"
\n
"
).
concat
(
"
\n
"
)
end
fallback
.
call
if
objects
.
empty?
fallback
.
call
if
respond_to?
(
:tty?
)
?
!
tty?
:
!
$stdout
.
tty?
console_width
=
Tty
.
width
object_lengths
=
objects
.
map
{
|
obj
|
Tty
.
strip_ansi
(
obj
).
length
}
cols
=
(
console_width
+
gap_size
)
/
(
object_lengths
.
max
+
gap_size
)
fallback
.
call
if
cols
<
2
rows
=
(
objects
.
count
+
cols
-
1
)
/
cols
cols
=
(
objects
.
count
+
rows
-
1
)
/
rows
# avoid empty trailing columns
col_width
=
(
console_width
+
gap_size
)
/
cols
-
gap_size
gap_string
=
""
.
rjust
(
gap_size
)
output
=
""
rows
.
times
do
|
row_index
|
item_indices_for_row
=
row_index
.
step
(
objects
.
size
-
1
,
rows
).
to_a
first_n
=
item_indices_for_row
[
0
...-
1
].
map
{
|
index
|
objects
[
index
]
+
""
.
rjust
(
col_width
-
object_lengths
[
index
])
}
# don't add trailing whitespace to last column
last
=
objects
.
values_at
(
item_indices_for_row
.
last
)
output
.
concat
((
first_n
+
last
).
join
(
gap_string
)).
concat
(
"
\n
"
)
end
output
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/utils/formatter/columns.rb
deleted
100644 → 0
+
0
−
46
View file @
ef70677e
require
"utils/tty"
module
Formatter
module_function
def
columns
(
*
objects
,
gap_size:
2
)
objects
=
objects
.
flatten
.
map
(
&
:to_s
)
fallback
=
proc
do
return
objects
.
join
(
"
\n
"
).
concat
(
"
\n
"
)
end
fallback
.
call
if
objects
.
empty?
fallback
.
call
if
respond_to?
(
:tty?
)
?
!
tty?
:
!
$stdout
.
tty?
console_width
=
Tty
.
width
object_lengths
=
objects
.
map
{
|
obj
|
Tty
.
strip_ansi
(
obj
).
length
}
cols
=
(
console_width
+
gap_size
)
/
(
object_lengths
.
max
+
gap_size
)
fallback
.
call
if
cols
<
2
rows
=
(
objects
.
count
+
cols
-
1
)
/
cols
cols
=
(
objects
.
count
+
rows
-
1
)
/
rows
# avoid empty trailing columns
col_width
=
(
console_width
+
gap_size
)
/
cols
-
gap_size
gap_string
=
""
.
rjust
(
gap_size
)
output
=
""
rows
.
times
do
|
row_index
|
item_indices_for_row
=
row_index
.
step
(
objects
.
size
-
1
,
rows
).
to_a
first_n
=
item_indices_for_row
[
0
...-
1
].
map
{
|
index
|
objects
[
index
]
+
""
.
rjust
(
col_width
-
object_lengths
[
index
])
}
# don't add trailing whitespace to last column
last
=
objects
.
values_at
(
item_indices_for_row
.
last
)
output
.
concat
((
first_n
+
last
).
join
(
gap_string
)).
concat
(
"
\n
"
)
end
output
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment