Module: Ollama::Utils::Width
- Included in:
- ANSIMarkdown
- Defined in:
- lib/ollama/utils/width.rb
Class Method Summary collapse
Class Method Details
.width(percentage: 100.0) ⇒ Object
6 7 8 |
# File 'lib/ollama/utils/width.rb', line 6 def width(percentage: 100.0) ((Float(percentage) * Tins::Terminal.columns) / 100).floor end |
.wrap(text, percentage: nil, length: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ollama/utils/width.rb', line 10 def wrap(text, percentage: nil, length: nil) percentage.nil? ^ length.nil? or raise ArgumentError, "either pass percentage or length argument" percentage and length ||= width(percentage:) text.gsub(/(?<!\n)\n(?!\n)/, ' ').lines.map do |line| if line.length > length line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").strip else line.strip end end * ?\n end |