5def fold(filename, max_width)
6 File.open(filename, 'r:utf-8') do |file|
7 # Words in this paragraph
10 file.each_line do |line|
11 # If we encounter an empty line, we reformat and dump the current
14 puts fold_paragraph(paragraph, max_width)
17 # Otherwise, we append the words found in the line to the paragraph
19 paragraph.concat line.split
24 puts fold_paragraph(paragraph, max_width) unless paragraph.empty?
28# Fold a single paragraph to the desired width
29def fold_paragraph(paragraph, max_width)
30 # Gradually build our output
31 str, *rest = paragraph
35 if width + word.length + 1 <= max_width
37 width += word.length + 1
48 t = benchmark { fold(f, 80) }
49 STDERR.puts "#{f}: #{t}"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list