Class: RubyRich::AppShell::HeaderView

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/app_shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ HeaderView

Returns a new instance of HeaderView.



247
248
249
250
251
# File 'lib/ruby_rich/app_shell.rb', line 247

def initialize(shell)
  @shell = shell
  @width = 0
  @height = 1
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



245
246
247
# File 'lib/ruby_rich/app_shell.rb', line 245

def height
  @height
end

#widthObject

Returns the value of attribute width.



245
246
247
# File 'lib/ruby_rich/app_shell.rb', line 245

def width
  @width
end

Instance Method Details

#renderObject



253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/ruby_rich/app_shell.rb', line 253

def render
  theme = @shell.theme
  left = "#{theme.style(@shell.instance_variable_get(:@title), :accent)}  #{theme.style(@shell.instance_variable_get(:@subtitle), :muted)}"
  usage = @shell.token_usage
  usage_text = if usage && !usage.empty?
                 total = usage[:total] || usage[:tokens]
                 total ? "#{total} tok" : usage.map { |key, value| "#{key}=#{value}" }.join(" ")
               else
                 "tokens --"
               end
  right = "#{theme.style(@shell.instance_variable_get(:@model), :status)}  #{theme.style('● Live', :body)}  #{theme.style(usage_text, :status)}"
  [join_edges(left, right, @width)]
end