Class: LLM::Repl::Window Private
- Inherits:
-
Object
- Object
- LLM::Repl::Window
- Defined in:
- lib/llm/repl/window.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The LLM::Repl::Window class draws the curses screen for the REPL.
Constant Summary collapse
- TOP_ROWS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Rows reserved for the top chrome (the blue model/cwd row).
1
Instance Attribute Summary collapse
- #status ⇒ LLM::Repl::Status readonly private
- #buffer ⇒ LLM::Repl::Buffer readonly private
- #input ⇒ LLM::Repl::Input readonly private
Instance Method Summary collapse
- #scroll_to_bottom private
- #open { ... } private
- #redraw private
- #rows ⇒ Integer private
- #columns ⇒ Integer private
-
#resize
private
Redraws the window after it has been resized.
- #getch ⇒ Object private
-
#read_paste ⇒ String
private
Drains all available characters from the terminal input buffer without blocking.
- #scroll_up private
- #scroll_down private
- #initialize(repl) ⇒ LLM::Repl::Window constructor private
Constructor Details
#initialize(repl) ⇒ LLM::Repl::Window
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 |
# File 'lib/llm/repl/window.rb', line 30 def initialize(repl) @repl = repl @status = repl.status @buffer = repl.buffer @input = repl.input end |
Instance Attribute Details
#status ⇒ LLM::Repl::Status (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/llm/repl/window.rb', line 16 def status @status end |
#buffer ⇒ LLM::Repl::Buffer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/llm/repl/window.rb', line 20 def buffer @buffer end |
#input ⇒ LLM::Repl::Input (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/llm/repl/window.rb', line 24 def input @input end |
Instance Method Details
#scroll_to_bottom
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
123 124 125 |
# File 'lib/llm/repl/window.rb', line 123 def scroll_to_bottom buffer.scroll_to_bottom end |
#open { ... }
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/llm/repl/window.rb', line 40 def open Curses.init_screen Color.enable Curses.cbreak Curses.noecho Curses.stdscr.keypad(true) Curses.stdscr.nodelay = true hide_cursor yield ensure show_cursor Curses.close_screen end |
#redraw
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
56 57 58 59 60 61 62 63 |
# File 'lib/llm/repl/window.rb', line 56 def redraw (offset: Curses.lines) draw_status(offset: input.height + 1) draw_divider(offset: 5) draw_buffer(offset: TOP_ROWS) draw_input Curses.refresh end |
#rows ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/llm/repl/window.rb', line 67 def rows [Curses.lines - (input.height + 4), 1].max end |
#columns ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/llm/repl/window.rb', line 73 def columns Curses.cols end |
#resize
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Redraws the window after it has been resized.
80 81 82 83 |
# File 'lib/llm/repl/window.rb', line 80 def resize Curses.clear redraw end |
#getch ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 |
# File 'lib/llm/repl/window.rb', line 87 def getch Curses.getch end |
#read_paste ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Drains all available characters from the terminal input
buffer without blocking. Used in place of Curses.getstr
when the paste flag is set, so that a huge multi-line
paste is consumed in a single shot instead of being
processed character-by-character.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/llm/repl/window.rb', line 98 def read_paste chars = +"" loop do ch = Curses.getch break unless ch and ch != -1 chars << ch end input.paste = false chars end |
#scroll_up
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
111 112 113 |
# File 'lib/llm/repl/window.rb', line 111 def scroll_up buffer.scroll_up(rows) end |
#scroll_down
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
117 118 119 |
# File 'lib/llm/repl/window.rb', line 117 def scroll_down buffer.scroll_down end |