Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Feb 2011 17:18:02 -0800
From:      Gary Kline <kline@thought.org>
To:        FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG>
Subject:   revised pager.....
Message-ID:  <20110221011755.GA16912@thought.org>

next in thread | raw e-mail | index | archive | help

	THis is to the entire list, mostly to Chip.  It is o8.rb, my 
	very slightly tweaked version of what you ma/// rather, what i
	found and began messing with a couple, three hours ago.

	I searched++  and could not find the C equivalent of
	"if counter % N == 0" in ruby.  For some reason, use of parens
	in ruby seems to be discouraged.  Anyway, I would have coded that
	ruby line as 

	if ( counter % 15) == 0

	but didn't want to risk it since i don't know ruby.

	Anyway, o8.rb included.  This version, using the "[][][][][]" to
	emulate a bar, makes reading a reasonably-sized bunch of text
	much easier.

	Thanks again for your help.  

-- 
 Gary Kline  kline@thought.org  http://www.thought.org  Public Service Unix

 %%%% ruby script appended.


#!/usr/bin/env ruby
require 'optparse'

pagesize = 15
count = 0

optparse = OptionParser.new do |opts|
  opts.banner = 'usage: npg [-n pagesize] file...'

  opts.on('-n', '--numlines pagesize', 'Specify page size in number of lines') do |n|
    pagesize = n.to_i
  end

end

begin
  optparse.parse!
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  puts e
  puts optparse
  exit 1
end

loop do
  if count == 0
     puts("\n[][][][][][][][][][][][][][][][][][][][][][][]")
	 count += 1
  end

  pagesize.times do
    if line = gets
      puts line
	  if count % 15 == 0
	     puts("===")
		 count = 0
     end
    else
      exit
    end
  end
  puts("\n[][][][][][][][][][][][][][][][][][][][][][][]\n\n")
  print "More..."
  system "stty raw"
  STDIN.getc
  system "stty -raw"
end




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110221011755.GA16912>