class LineByLine
Shows a text-file line by line
Public Class Methods
new(args)
click to toggle source
# File lib/line_by_line.rb, line 34 def initialize(args) init_logger() if(args.empty?) @log.warn("\n\n\tNo Arguments!\n") @log.info("Call with option \"-h\" to see some options\n") exit true end options = ArgParser::parse(args) # file = args[0] file = options.file advance = options.line @log.debug('file is ' << file.to_s) if(file && File::exist?(file) && File::readable?(file)) f = File.open(file) system('clear') until f.eof c = nil begin until(advance == 0 || f.eof) do f.readline advance -= 1 end line = '' loop do line = f.readline if(options.fast ) print line else char_by_char line end last_char = line.strip[-1] @log.debug 'last char of |' << line.strip << '| is ' << (last_char ? last_char : 'N I L') break unless ('↵' == last_char || '\\' == last_char ) end unless "\n" == line c = wait_for_user end rescue Interrupt @log.info("\n\n\tprogram interrupted by user") exit true end # key 'f' if(102 == c) options.fast = true # key 's' elsif(115 == c) options.fast = false # keys ctrl+c, ctrl+d, 'q' elsif(4 == c || 3 == c || 113 == c) exit true end end else @log.error("File %s is unsuitable as input to %s"%[file, $0]) end end
Private Instance Methods
char_by_char(line)
click to toggle source
# File lib/line_by_line.rb, line 94 def char_by_char(line) line.split('').each do |c| if ('↵' != c && '\\' != c) @log.debug('printing ' << c) print c; sleep 0.1 end end end
usage()
click to toggle source
# File lib/line_by_line.rb, line 103 def usage usage = %~ Usage: %s [text-file]~ %$0 print usage end