Class: LLM::Repl::Window Private

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, transcript, input) ⇒ 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.

Parameters:



26
27
28
29
30
# File 'lib/llm/repl/window.rb', line 26

def initialize(status, transcript, input)
  @status = status
  @transcript = transcript
  @input = input
end

Instance Attribute Details

#statusLLM::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.

Returns:



11
12
13
# File 'lib/llm/repl/window.rb', line 11

def status
  @status
end

#transcriptLLM::Repl::Transcript (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.



15
16
17
# File 'lib/llm/repl/window.rb', line 15

def transcript
  @transcript
end

#inputLLM::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.

Returns:



19
20
21
# File 'lib/llm/repl/window.rb', line 19

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.



100
101
102
# File 'lib/llm/repl/window.rb', line 100

def scroll_to_bottom
  transcript.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.

Yields:



35
36
37
38
39
40
41
42
43
44
# File 'lib/llm/repl/window.rb', line 35

def open
  Curses.init_screen
  Curses.cbreak
  Curses.noecho
  Curses.stdscr.keypad(true)
  Curses.stdscr.nodelay = true
  yield
ensure
  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.



48
49
50
51
52
53
54
# File 'lib/llm/repl/window.rb', line 48

def redraw
  draw_status(offset: input.height + 1)
  draw_divider(offset: 5)
  draw_transcript(offset: 0)
  draw_input
  Curses.refresh
end

#rowsInteger

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.

Returns:

  • (Integer)


58
59
60
# File 'lib/llm/repl/window.rb', line 58

def rows
  [Curses.lines - (input.height + 4), 1].max
end

#getchObject

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.

Returns:



64
65
66
# File 'lib/llm/repl/window.rb', line 64

def getch
  Curses.getch
end

#read_pasteString

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.

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
84
# File 'lib/llm/repl/window.rb', line 75

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.



88
89
90
# File 'lib/llm/repl/window.rb', line 88

def scroll_up
  transcript.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.



94
95
96
# File 'lib/llm/repl/window.rb', line 94

def scroll_down
  transcript.scroll_down
end