Module: OllamaChat::Pager
- Included in:
- Chat, MessageList
- Defined in:
- lib/ollama_chat/pager.rb
Overview
Module for handling pager functionality in the chat application.
Provides methods to display long-form content using pagers like ‘less’ or ‘more’, automatically handling terminal line capacity and improving the user experience when viewing large amounts of output.
This module is used throughout the application to paginate long messages, configuration outputs, and other text content that might not fit in the current terminal window.
Instance Method Summary collapse
-
#use_pager {|the| ... } ⇒ Object
The use_pager method wraps the given block with a pager context.
Instance Method Details
#use_pager {|the| ... } ⇒ Object
The use_pager method wraps the given block with a pager context. If the output would exceed the terminal’s line capacity, it pipes the content through an appropriate pager command (like ‘less’ or ‘more’).
17 18 19 20 21 22 23 24 25 |
# File 'lib/ollama_chat/pager.rb', line 17 def use_pager command = determine_pager_command output_buffer = StringIO.new yield output_buffer buffer = output_buffer.string Kramdown::ANSI::Pager.pager(command:, lines: buffer.count(?\n)) do |output| output.puts buffer end end |