Skip to content

Commit

Permalink
Shorten too long message at uninstalling
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Mar 9, 2024
1 parent a699102 commit ced648f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tool/rbuninstall.rb
Expand Up @@ -21,15 +21,33 @@
end
$dirs = []
$files = []
COLUMNS = $tty && (ENV["COLUMNS"]&.to_i || begin require 'io/console/size'; rescue; else IO.console_size&.at(1); end)&.then do |n|
n-1 if n > 1
end
if COLUMNS
$column = 0
def message(str = nil)
$stdout.print "\b \b" * $column
if str
if str.size > COLUMNS
str = "..." + str[(-COLUMNS+3)..-1]
end
$stdout.print str
end
$stdout.flush
$column = str&.size || 0
end
else
alias message puts
end
}
list = ($_.chomp!('/') ? $dirs : $files)
list << $_
END {
status = true
$\ = nil
ors = (!$dryrun and $tty) ? "\e[K\r" : "\n"
$files.each do |file|
print "rm #{file}#{ors}"
message "rm #{file}"
unless $dryrun
file = File.join($destdir, file) if $destdir
begin
Expand All @@ -47,7 +65,7 @@
end
while dir = $dirs.pop
dir = File.dirname(dir) while File.basename(dir) == '.'
print "rmdir #{dir}#{ors}"
message "rmdir #{dir}"
unless $dryrun
realdir = $destdir ? File.join($destdir, dir) : dir
begin
Expand All @@ -68,6 +86,6 @@
end
end
end
print ors.chomp
message
exit(status)
}

0 comments on commit ced648f

Please sign in to comment.