Class: Rubino::UI::QueuedIndicators

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/ui/queued_indicators.rb

Overview

The BottomComposer‘s stack of EXPLICITLY-queued messages (Alt+Enter / “/queued <msg>”) awaiting their turn, rendered as live “⏳ queued: <msg>” rows above the input — never committed to scrollback. Wraps the list the chat loop SHARES across the per-turn composers, so the indicator survives a composer teardown and is removed (and the item committed as a normal message) when the queued item’s turn runs. Pure state + row formatting: the composer owns the render mutex and the redraw around every mutation.

Constant Summary collapse

MAX_ROWS =

Hard cap on the visible rows so a burst of explicit queues can never push the prompt off-screen. Beyond the cap, a dim count row stands in for the overflow.

4

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ QueuedIndicators

Returns a new instance of QueuedIndicators.

Parameters:

  • list (Array<String>)

    the shared (or private) pending stack.



21
22
23
# File 'lib/rubino/ui/queued_indicators.rb', line 21

def initialize(list)
  @list = list
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rubino/ui/queued_indicators.rb', line 25

def any?
  @list.any?
end

#push(msg, front: false) ⇒ Object

Add msg to the pending stack. front jumps the queue (the interrupt-by-default Enter): its indicator leads the pending rows so the visible order matches the run order (#129).



32
33
34
# File 'lib/rubino/ui/queued_indicators.rb', line 32

def push(msg, front: false)
  front ? @list.unshift(msg) : @list.push(msg)
end

#remove(msg) ⇒ Object

Remove the FIRST pending indicator matching msg (the chat loop calls through when the queued item’s turn starts). Returns the removed message, or nil when none matched.



39
40
41
42
43
44
# File 'lib/rubino/ui/queued_indicators.rb', line 39

def remove(msg)
  idx = @list.index(msg)
  return unless idx

  @list.delete_at(idx)
end

#rowsObject

The “⏳ queued: <msg>” indicator rows for the pending stack, in submission order. House grammar: the ⏳ glyph, dim. Capped to MAX_ROWS with a dim “┄ +N more queued ┄” overflow row.



49
50
51
52
53
54
55
56
57
# File 'lib/rubino/ui/queued_indicators.rb', line 49

def rows
  return [] if @list.empty?

  shown = @list.first(MAX_ROWS)
  rows = shown.map { |msg| pastel.dim("⏳ queued: #{msg}") }
  overflow = @list.size - shown.size
  rows << pastel.dim("┄ +#{overflow} more queued ┄") if overflow.positive?
  rows
end