null+****@clear*****
null+****@clear*****
Thu Jun 28 12:01:57 JST 2012
SHIMADA Koji 2012-05-30 20:02:44 +0900 (Wed, 30 May 2012) New Revision: 0c0c41cd957dbe4cfa34ce885387fd653dd623d3 https://github.com/logaling/logaling-command/commit/0c0c41cd957dbe4cfa34ce885387fd653dd623d3 Merged 7228757: Merge pull request #60 from logaling/refactor-structure Log: Extract Pager module Added files: lib/logaling/command/pager.rb Modified files: lib/logaling/command.rb lib/logaling/command/application.rb Modified: lib/logaling/command.rb (+1 -0) =================================================================== --- lib/logaling/command.rb 2012-05-30 15:26:51 +0900 (d79cfce) +++ lib/logaling/command.rb 2012-05-30 20:02:44 +0900 (fbeecbc) @@ -17,3 +17,4 @@ require "logaling/command/version" require "logaling/command/application" +require "logaling/command/pager" Modified: lib/logaling/command/application.rb (+1 -30) =================================================================== --- lib/logaling/command/application.rb 2012-05-30 15:26:51 +0900 (0027539) +++ lib/logaling/command/application.rb 2012-05-30 20:02:44 +0900 (0118b02) @@ -310,10 +310,6 @@ module Logaling::Command end private - def windows? - RUBY_PLATFORM =~ /win32|mingw32/i - end - def glossary_source @glossary_source ||= Logaling::GlossarySource.new(@config.glossary, @config.source_language, @config.target_language, @logaling_home) end @@ -349,33 +345,8 @@ module Logaling::Command end end - # http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby def run_pager - return if options["no-pager"] - return if windows? - return unless STDOUT.tty? - - read, write = IO.pipe - - unless Kernel.fork # Child process - STDOUT.reopen(write) - STDERR.reopen(write) if STDERR.tty? - read.close - write.close - return - end - - # Parent process, become pager - STDIN.reopen(read) - read.close - write.close - - ENV['LESS'] = 'FSRX' # Don't page if the input is short enough - - # wait until we have input before we start the pager - Kernel.select [STDIN] - pager = ENV['PAGER'] || 'less' - exec pager rescue exec "/bin/sh", "-c", pager + Pager.run unless options["no-pager"] end def extract_keyword_and_coloring(snipped_term, term) Added: lib/logaling/command/pager.rb (+36 -0) 100644 =================================================================== --- /dev/null +++ lib/logaling/command/pager.rb 2012-05-30 20:02:44 +0900 (4541141) @@ -0,0 +1,36 @@ +module Logaling::Command + # http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby + module Pager + def self.run + return if windows? + return unless STDOUT.tty? + + read, write = IO.pipe + + unless Kernel.fork # Child process + STDOUT.reopen(write) + STDERR.reopen(write) if STDERR.tty? + read.close + write.close + return + end + + # Parent process, become pager + STDIN.reopen(read) + read.close + write.close + + ENV['LESS'] = 'FSRX' # Don't page if the input is short enough + + # wait until we have input before we start the pager + Kernel.select [STDIN] + pager = ENV['PAGER'] || 'less' + exec pager rescue exec "/bin/sh", "-c", pager + end + + private + def self.windows? + RUBY_PLATFORM =~ /win32|mingw32/i + end + end +end -------------- next part -------------- An HTML attachment was scrubbed... Download