Class: Binocs::TUI::SequenceDiagram
- Inherits:
-
Window
- Object
- Window
- Binocs::TUI::SequenceDiagram
show all
- Defined in:
- lib/binocs/tui/sequence_diagram.rb
Instance Attribute Summary collapse
Attributes inherited from Window
#height, #left, #top, #width, #win
Instance Method Summary
collapse
Methods inherited from Window
#clear, #close, #copy_to_clipboard, #draw_box, #noutrefresh, #refresh, #resize, #write, #write_centered
Constructor Details
#initialize(height:, width:, top:, left:) ⇒ SequenceDiagram
Returns a new instance of SequenceDiagram.
8
9
10
11
12
13
14
15
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 8
def initialize(height:, width:, top:, left:)
super
@requests = []
@client_identifiers = []
@client_index = 0
@selected_index = 0
@scroll_offset = 0
end
|
Instance Attribute Details
#client_index ⇒ Object
Returns the value of attribute client_index.
6
7
8
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 6
def client_index
@client_index
end
|
#selected_index ⇒ Object
Returns the value of attribute selected_index.
6
7
8
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 6
def selected_index
@selected_index
end
|
Instance Method Details
#content_as_text ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 88
def content_as_text
lines = []
lines << "Sequence Diagram - Client: #{client_label(current_client)}"
lines << "=" * 80
lines << ""
@requests.each do |req|
time = req.created_at&.strftime("%H:%M:%S.%L") || "?"
lines << " #{time} #{req.method} #{req.path}"
lines << " #{' ' * 12} ← #{req.status_code || '???'} #{req.formatted_duration}"
lines << ""
end
lines.join("\n")
end
|
#current_client ⇒ Object
26
27
28
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 26
def current_client
@client_identifiers[@client_index]
end
|
#draw ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 78
def draw
clear
draw_box("Sequence Diagram")
draw_client_selector
draw_separator
draw_requests
draw_status_bar
end
|
#go_to_bottom ⇒ Object
63
64
65
66
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 63
def go_to_bottom
@selected_index = [@requests.length - 1, 0].max
adjust_scroll
end
|
#go_to_top ⇒ Object
58
59
60
61
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 58
def go_to_top
@selected_index = 0
@scroll_offset = 0
end
|
#load_data ⇒ Object
17
18
19
20
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 17
def load_data
@client_identifiers = Binocs::Request.client_identifiers
load_requests_for_current_client
end
|
#move_down ⇒ Object
44
45
46
47
48
49
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 44
def move_down
if @selected_index < @requests.length - 1
@selected_index += 1
adjust_scroll
end
end
|
#move_up ⇒ Object
51
52
53
54
55
56
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 51
def move_up
if @selected_index > 0
@selected_index -= 1
adjust_scroll
end
end
|
#next_client ⇒ Object
30
31
32
33
34
35
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 30
def next_client
return if @client_identifiers.empty?
@client_index = (@client_index + 1) % @client_identifiers.length
load_requests_for_current_client
end
|
#page_down ⇒ Object
68
69
70
71
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 68
def page_down
@selected_index = [@selected_index + visible_rows, @requests.length - 1].min
adjust_scroll
end
|
#page_up ⇒ Object
73
74
75
76
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 73
def page_up
@selected_index = [@selected_index - visible_rows, 0].max
adjust_scroll
end
|
#prev_client ⇒ Object
37
38
39
40
41
42
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 37
def prev_client
return if @client_identifiers.empty?
@client_index = (@client_index - 1) % @client_identifiers.length
load_requests_for_current_client
end
|
#selected_request ⇒ Object
22
23
24
|
# File 'lib/binocs/tui/sequence_diagram.rb', line 22
def selected_request
@requests[@selected_index]
end
|