[ditz-talk] [PATCH] Add configuration setting for controlling pager invocation

Daniel Kalør daniel at kalor.dk
Wed Nov 5 23:42:02 EST 2008


Only mess with LESS env var when config is set to 'auto', and don't
ignore previous LESS settings.

Ditz-issue: 50c68d6ebd81149d12fc44e311792a3418f2e687
---
 bin/ditz                  |    2 +-
 lib/ditz.rb               |    9 ++++++---
 lib/ditz/model-objects.rb |    6 ++++++
 lib/ditz/operator.rb      |   16 ++++++++--------
 lib/ditz/views.rb         |    2 +-
 5 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/bin/ditz b/bin/ditz
index 886a8fd..a0b9f80 100755
--- a/bin/ditz
+++ b/bin/ditz
@@ -134,7 +134,7 @@ when "reconfigure" # might not be able to load the project
   op.do cmd, nil, config, ARGV
   exit
 when "help"
-  op.do cmd, nil, nil, ARGV
+  op.do cmd, nil, config, ARGV
   exit
 end
 
diff --git a/lib/ditz.rb b/lib/ditz.rb
index 8c17ed3..6d686f2 100644
--- a/lib/ditz.rb
+++ b/lib/ditz.rb
@@ -67,9 +67,10 @@ end
 # Git-style automatic pagination of all output.
 # Call run_pa	ger from any opperator needing pagination.
 # Yoinked from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby#comments
-def run_pager
+def run_pager config
   return if PLATFORM =~ /win32/
   return unless STDOUT.tty?
+  return if config.paginate == 'never'
 
   read, write = IO.pipe
 
@@ -86,8 +87,10 @@ def run_pager
   read.close
   write.close
 
-  ENV['LESS'] ||= 'FSRX'  # Don't page if the input is short enough, unless
-                          # the user already have a LESS variable.
+  if config.paginate == 'auto'
+    ENV['LESS'] = '' unless ENV['LESS']  # += doesn't work on undefined var
+    ENV['LESS'] += ' FSRX'  # Don't page if the input is short enough
+  end
 
   Kernel.select [STDIN] # Wait until we have input before we start the pager
   pager = ENV['PAGER'] || 'less'
diff --git a/lib/ditz/model-objects.rb b/lib/ditz/model-objects.rb
index ffec6db..7b3298d 100644
--- a/lib/ditz/model-objects.rb
+++ b/lib/ditz/model-objects.rb
@@ -332,6 +332,7 @@ class Config < ModelObject
   field :email, :prompt => "Your email address", :default_generator => :get_default_email
   field :issue_dir, :prompt => "Directory to store issues state in", :default => ".ditz"
   field :use_editor_if_possible, :interactive_generator => :get_use_editor
+  field :paginate, :interactive_generator => :get_paginate
 
   def user; "#{name} <#{email}>" end
 
@@ -339,6 +340,11 @@ class Config < ModelObject
     self.use_editor_if_possible = true if self.use_editor_if_possible.nil?
   end
 
+  def get_paginate
+    page = ask "Paginate output (always/never/auto)?", :restrict => /^(always|never|auto)$/i
+    page.downcase
+  end
+
   def get_use_editor
     yon = ask "Use your text editor for multi-line input when possible (y/n)?", :restrict => /^(y|yes|n|no)$/i
     yon =~ /y/ ? true : false
diff --git a/lib/ditz/operator.rb b/lib/ditz/operator.rb
index 0a45867..ff7d466 100644
--- a/lib/ditz/operator.rb
+++ b/lib/ditz/operator.rb
@@ -136,7 +136,7 @@ class Operator
       puts "All is well with the world now. A bit more methane though."
       return
     end
-    run_pager
+    run_pager config
     return help_single(command) if command
     puts <<EOS
 Ditz commands:
@@ -253,7 +253,7 @@ EOS
 
   operation :status, "Show project status", :maybe_release
   def status project, config, releases
-    run_pager
+    run_pager config
     releases ||= project.unreleased_releases + [:unassigned]
 
     if releases.empty?
@@ -348,7 +348,7 @@ EOS
   end
 
   def actually_do_todo project, config, releases, full
-    run_pager
+    run_pager config
     releases ||= project.unreleased_releases + [:unassigned]
     releases = [*releases]
     releases.each do |r|
@@ -482,7 +482,7 @@ EOS
 
   operation :releases, "Show releases"
   def releases project, config
-    run_pager
+    run_pager config
     a, b = project.releases.partition { |r| r.released? }
     (b + a.sort_by { |r| r.release_time }).each do |r|
       status = r.released? ? "released #{r.release_time.pretty_date}" : r.status
@@ -501,7 +501,7 @@ EOS
 
   operation :changelog, "Generate a changelog for a release", :release
   def changelog project, config, r
-    run_pager
+    run_pager config
     puts "== #{r.name} / #{r.released? ? r.release_time.pretty_date : 'unreleased'}"
     project.group_issues(project.issues_for_release(r)).each do |type, issues|
       issues.select { |i| i.closed? }.each do |i|
@@ -530,7 +530,7 @@ EOS
   end
 
   def grep project, config, opts, match
-    run_pager
+    run_pager config
     re = Regexp.new match, opts[:ignore_case]
     issues = project.issues.select do |i|
       i.title =~ re || i.desc =~ re ||
@@ -541,7 +541,7 @@ EOS
 
   operation :log, "Show recent activity"
   def log project, config
-    run_pager
+    run_pager config
     project.issues.map { |i| i.log_events.map { |e| [e, i] } }.
       flatten_one_level.sort_by { |e| e.first.first }.reverse.
       each do |(date, author, what, comment), i|
@@ -560,7 +560,7 @@ EOS
 
   operation :shortlog, "Show recent activity (short form)"
   def shortlog project, config
-    run_pager
+    run_pager config
     project.issues.map { |i| i.log_events.map { |e| [e, i] } }.
       flatten_one_level.sort_by { |e| e.first.first }.reverse.
       each do |(date, author, what, comment), i|
diff --git a/lib/ditz/views.rb b/lib/ditz/views.rb
index 3c68df1..d17b0a6 100644
--- a/lib/ditz/views.rb
+++ b/lib/ditz/views.rb
@@ -30,7 +30,7 @@ class ScreenView < View
     else
       "\n" + issue.desc.gsub(/^/, "  ") + "\n"
     end
-    run_pager
+    run_pager @config
     @device.puts <<EOS
 #{"Issue #{issue.name}".underline}
       Title: #{issue.title}
-- 
1.6.0.3



More information about the ditz-talk mailing list