From 31f6ae587d654cf7e581c77a1d1a462967792727 Mon Sep 17 00:00:00 2001 From: Daniel Bayley Date: Mon, 25 May 2020 16:10:41 +0100 Subject: [PATCH] Fix output of list_running_app_ids script (#83164) Tidy up code following #67948, avoid shelling out as much, and slightly improve column alignment in output. --- developer/bin/list_running_app_ids | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/developer/bin/list_running_app_ids b/developer/bin/list_running_app_ids index d06494f6fe..71afe8f6e8 100755 --- a/developer/bin/list_running_app_ids +++ b/developer/bin/list_running_app_ids @@ -9,12 +9,14 @@ require "open3" require "set" +require "io/console" ### ### globals ### $opt_test = nil +$COLUMNS = IO.console.winsize.last ### ### methods @@ -86,23 +88,18 @@ def excluded_app_name(app_name) %r{^osascript$}.match(app_name) # this script itself end -def expand(table) - @COLUMNS = `/usr/bin/tput cols`.to_i - puts `echo '#{table}'| /usr/bin/expand -t#{@COLUMNS / 2}` -end - def report_apps running = Set.new @app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, _unix_id| next if excluded_bundle_id bundle_id next if excluded_app_name app_name bundle_id.gsub!(%r{^(missing value)$}, '<\1>') - running.add "#{bundle_id}\t#{app_name}" + running.add "#{bundle_id.ljust($COLUMNS / 2)}\t#{app_name}" end - expand "bundle_id\tapp_name" - puts "-" * @COLUMNS + "\n" - expand running.to_a.sort.join "\n" + puts "bundle_id".ljust($COLUMNS / 2) + "\tapp_name" + puts "-" * $COLUMNS + puts running.to_a.sort.join "\n" end ###