{"action":"created","comment":{"url":"https://api.github.com/repos/SUSE/machinery/pulls/comments/27201789","id":27201789,"diff_hunk":"@@ -17,62 +17,66 @@\n \n module Machinery\n   class Ui\n-    def self.internal_scope_list_to_string(scopes)\n-      list = Array(scopes)\n-      list.map { |e| e.tr(\"_\", \"-\") }.join(\", \")\n-    end\n+    class <<self\n+      attr_accessor :use_pager\n \n-    def self.write_output_to_pager(output)\n-      IO.popen(\"$PAGER\", \"w\") do |f|\n-        begin\n-          f.puts output\n-        rescue Errno::EPIPE\n-          # We just ignore broken pipes.\n-        end\n+      def internal_scope_list_to_string(scopes)\n+        list = Array(scopes)\n+        list.map { |e| e.tr(\"_\", \"-\") }.join(\", \")\n       end\n-    end\n \n-    def self.print_output(output, options = {})\n-      if options[:no_pager] || !$stdout.tty?\n+      def write_output_to_pager(output)\n+        @pager ||= IO.popen(\"$PAGER\", \"w\")\n+\n         begin\n-          Machinery::Ui.puts output\n+          @pager.puts output\n         rescue Errno::EPIPE\n           # We just ignore broken pipes.\n         end\n-      else\n-        if !ENV['PAGER'] || ENV['PAGER'] == ''\n-          ENV['PAGER'] = 'less'\n-          ENV['LESS'] = 'FSRX'\n+      end\n+\n+      def close_pager\n+        @pager.close if @pager\n+      end\n+\n+      def puts(output)\n+        if !use_pager || !$stdout.tty?\n           begin\n-            LocalSystem.validate_existence_of_package(\"less\")\n-            write_output_to_pager(output)\n-          rescue Machinery::Errors::MissingRequirement\n-            Machinery::Ui.puts output\n+            STDOUT.puts output\n+          rescue Errno::EPIPE\n+            # We just ignore broken pipes.\n           end\n         else\n-          IO.popen(\"$PAGER &>/dev/null\", \"w\") { |f| f.close }\n-          if $?.success?\n-            write_output_to_pager(output)\n+          if !ENV['PAGER'] || ENV['PAGER'] == ''","path":"lib/ui.rb","position":60,"original_position":60,"commit_id":"5cf4fb8daaf13dae6509855eadba042386dd9779","original_commit_id":"5cf4fb8daaf13dae6509855eadba042386dd9779","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.","created_at":"2015-03-26T10:31:51Z","updated_at":"2015-03-26T10:31:51Z","html_url":"https://github.com/SUSE/machinery/pull/771#discussion_r27201789","pull_request_url":"https://api.github.com/repos/SUSE/machinery/pulls/771","_links":{"self":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/comments/27201789"},"html":{"href":"https://github.com/SUSE/machinery/pull/771#discussion_r27201789"},"pull_request":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/771"}}},"pull_request":{"url":"https://api.github.com/repos/SUSE/machinery/pulls/771","id":32004935,"html_url":"https://github.com/SUSE/machinery/pull/771","diff_url":"https://github.com/SUSE/machinery/pull/771.diff","patch_url":"https://github.com/SUSE/machinery/pull/771.patch","issue_url":"https://api.github.com/repos/SUSE/machinery/issues/771","number":771,"state":"open","locked":false,"title":"Get rid of Ui.print_output, Ui.puts supports paging transparently now","user":{"login":"aduffeck","id":203813,"avatar_url":"https://avatars.githubusercontent.com/u/203813?v=3","gravatar_id":"","url":"https://api.github.com/users/aduffeck","html_url":"https://github.com/aduffeck","followers_url":"https://api.github.com/users/aduffeck/followers","following_url":"https://api.github.com/users/aduffeck/following{/other_user}","gists_url":"https://api.github.com/users/aduffeck/gists{/gist_id}","starred_url":"https://api.github.com/users/aduffeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduffeck/subscriptions","organizations_url":"https://api.github.com/users/aduffeck/orgs","repos_url":"https://api.github.com/users/aduffeck/repos","events_url":"https://api.github.com/users/aduffeck/events{/privacy}","received_events_url":"https://api.github.com/users/aduffeck/received_events","type":"User","site_admin":false},"body":"Machinery::Ui.print_output was used to print output either on the\nconsole (when no pager was available or when the user gave the\n--no-pager option) or a pager. That approach was not very flexible,\nthough, because the whole output had to be given as a string at once.\n\nThe new approach now uses the normal Machinery::Ui.puts method. It\nwrites to the console by default, but a pager can be enabled using\n\n  Machinery::Ui.use_pager = true\n\nThat way the output can be composed from several places and can be\nstreamed to the user instead of having to wait for the whole output\nbefore showing it.\n","created_at":"2015-03-26T10:31:44Z","updated_at":"2015-03-26T10:31:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3bb475cbae7613a418cdd6408a7acffb30586cbd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SUSE/machinery/pulls/771/commits","review_comments_url":"https://api.github.com/repos/SUSE/machinery/pulls/771/comments","review_comment_url":"https://api.github.com/repos/SUSE/machinery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SUSE/machinery/issues/771/comments","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/5cf4fb8daaf13dae6509855eadba042386dd9779","head":{"label":"SUSE:review_150326_improve_pager_support","ref":"review_150326_improve_pager_support","sha":"5cf4fb8daaf13dae6509855eadba042386dd9779","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":21424418,"name":"machinery","full_name":"SUSE/machinery","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/machinery","description":"A systems management toolkit for Linux","fork":false,"url":"https://api.github.com/repos/SUSE/machinery","forks_url":"https://api.github.com/repos/SUSE/machinery/forks","keys_url":"https://api.github.com/repos/SUSE/machinery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/machinery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/machinery/teams","hooks_url":"https://api.github.com/repos/SUSE/machinery/hooks","issue_events_url":"https://api.github.com/repos/SUSE/machinery/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/machinery/events","assignees_url":"https://api.github.com/repos/SUSE/machinery/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/machinery/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/machinery/tags","blobs_url":"https://api.github.com/repos/SUSE/machinery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/machinery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/machinery/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/machinery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/machinery/languages","stargazers_url":"https://api.github.com/repos/SUSE/machinery/stargazers","contributors_url":"https://api.github.com/repos/SUSE/machinery/contributors","subscribers_url":"https://api.github.com/repos/SUSE/machinery/subscribers","subscription_url":"https://api.github.com/repos/SUSE/machinery/subscription","commits_url":"https://api.github.com/repos/SUSE/machinery/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/machinery/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/machinery/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/machinery/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUSE/machinery/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/machinery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/machinery/merges","archive_url":"https://api.github.com/repos/SUSE/machinery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/machinery/downloads","issues_url":"https://api.github.com/repos/SUSE/machinery/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/machinery/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/machinery/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/machinery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/machinery/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/machinery/releases{/id}","created_at":"2014-07-02T13:07:04Z","updated_at":"2015-03-25T08:27:03Z","pushed_at":"2015-03-26T10:31:45Z","git_url":"git://github.com/SUSE/machinery.git","ssh_url":"git@github.com:SUSE/machinery.git","clone_url":"https://github.com/SUSE/machinery.git","svn_url":"https://github.com/SUSE/machinery","homepage":"machinery-project.org","size":15756,"stargazers_count":42,"watchers_count":42,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":35,"forks":7,"open_issues":35,"watchers":42,"default_branch":"master"}},"base":{"label":"SUSE:master","ref":"master","sha":"dd5ced9942131b75d1ddd403bf4a4d74456c0b0d","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":21424418,"name":"machinery","full_name":"SUSE/machinery","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/machinery","description":"A systems management toolkit for Linux","fork":false,"url":"https://api.github.com/repos/SUSE/machinery","forks_url":"https://api.github.com/repos/SUSE/machinery/forks","keys_url":"https://api.github.com/repos/SUSE/machinery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/machinery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/machinery/teams","hooks_url":"https://api.github.com/repos/SUSE/machinery/hooks","issue_events_url":"https://api.github.com/repos/SUSE/machinery/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/machinery/events","assignees_url":"https://api.github.com/repos/SUSE/machinery/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/machinery/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/machinery/tags","blobs_url":"https://api.github.com/repos/SUSE/machinery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/machinery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/machinery/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/machinery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/machinery/languages","stargazers_url":"https://api.github.com/repos/SUSE/machinery/stargazers","contributors_url":"https://api.github.com/repos/SUSE/machinery/contributors","subscribers_url":"https://api.github.com/repos/SUSE/machinery/subscribers","subscription_url":"https://api.github.com/repos/SUSE/machinery/subscription","commits_url":"https://api.github.com/repos/SUSE/machinery/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/machinery/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/machinery/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/machinery/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUSE/machinery/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/machinery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/machinery/merges","archive_url":"https://api.github.com/repos/SUSE/machinery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/machinery/downloads","issues_url":"https://api.github.com/repos/SUSE/machinery/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/machinery/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/machinery/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/machinery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/machinery/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/machinery/releases{/id}","created_at":"2014-07-02T13:07:04Z","updated_at":"2015-03-25T08:27:03Z","pushed_at":"2015-03-26T10:31:45Z","git_url":"git://github.com/SUSE/machinery.git","ssh_url":"git@github.com:SUSE/machinery.git","clone_url":"https://github.com/SUSE/machinery.git","svn_url":"https://github.com/SUSE/machinery","homepage":"machinery-project.org","size":15756,"stargazers_count":42,"watchers_count":42,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":35,"forks":7,"open_issues":35,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/771"},"html":{"href":"https://github.com/SUSE/machinery/pull/771"},"issue":{"href":"https://api.github.com/repos/SUSE/machinery/issues/771"},"comments":{"href":"https://api.github.com/repos/SUSE/machinery/issues/771/comments"},"review_comments":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/771/comments"},"review_comment":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/771/commits"},"statuses":{"href":"https://api.github.com/repos/SUSE/machinery/statuses/5cf4fb8daaf13dae6509855eadba042386dd9779"}}}}