log_bench 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/log_bench/app/copy_handler.rb +74 -15
- data/lib/log_bench/app/input_handler.rb +8 -1
- data/lib/log_bench/app/renderer/details.rb +17 -7
- data/lib/log_bench/app/renderer/main.rb +4 -0
- data/lib/log_bench/app/screen.rb +18 -0
- data/lib/log_bench/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 988ff524c8e07d752d9105bbe0d58008d8209fb0b58d31e0d398cb574ed97b44
|
4
|
+
data.tar.gz: 02c7efab76e2203c1fd77d55ad2c30ecdbb50362eae751e83e7616dd0f4919ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f84d49ef55a3d88345ce5fee35b645298569743cbd04a210e459bef19a2fa39cf212058db3e11665c3e4e0827db65ebbfbdaa1c4d67439f41a710af63bd67fd
|
7
|
+
data.tar.gz: 659277186d2eac29a7aebd33b15a07237701fb260e0a1890d6f6cd4bdb909a90b9e56fa9b5815dee38b17aaba5c08ec51421cc1013f9e9aef90eaa888c619a5f
|
@@ -16,6 +16,26 @@ module LogBench
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def find_companion_call_line(request, selected_entry_id)
|
20
|
+
# Get the detail lines for the current request
|
21
|
+
lines = renderer&.get_cached_detail_lines(request)
|
22
|
+
return nil unless lines
|
23
|
+
|
24
|
+
# Find all lines belonging to the selected entry
|
25
|
+
selected_lines = lines.select { |line| line[:entry_id] == selected_entry_id }
|
26
|
+
|
27
|
+
# Look for a call line (starts with "↳") in the same entry group
|
28
|
+
call_line = selected_lines.find do |line|
|
29
|
+
text = line[:text]&.gsub(/\e\[[0-9;]*m/, "")&.strip
|
30
|
+
text&.start_with?("↳")
|
31
|
+
end
|
32
|
+
|
33
|
+
if call_line
|
34
|
+
# Clean and return the call line content
|
35
|
+
call_line[:text].gsub(/\e\[[0-9;]*m/, "").strip
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
19
39
|
private
|
20
40
|
|
21
41
|
attr_accessor :state, :renderer
|
@@ -51,7 +71,7 @@ module LogBench
|
|
51
71
|
request = state.current_request
|
52
72
|
return unless request
|
53
73
|
|
54
|
-
# Get the detail lines for the current request
|
74
|
+
# Get the detail lines for the current request to find entry IDs
|
55
75
|
lines = renderer&.get_cached_detail_lines(request)
|
56
76
|
return unless lines
|
57
77
|
|
@@ -63,24 +83,63 @@ module LogBench
|
|
63
83
|
selected_entry_id = entry_ids[state.detail_selected_entry]
|
64
84
|
return unless selected_entry_id
|
65
85
|
|
66
|
-
# Find
|
86
|
+
# Find lines belonging to the selected entry and look for original_entry reference
|
67
87
|
selected_lines = lines.select { |line| line[:entry_id] == selected_entry_id }
|
68
88
|
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
content_text = content.join(" ")
|
78
|
-
is_sql_query = sql_query?(content_text)
|
89
|
+
# Look for a line that has the original_entry reference
|
90
|
+
original_entry = nil
|
91
|
+
selected_lines.each do |line|
|
92
|
+
if line[:original_entry]
|
93
|
+
original_entry = line[:original_entry]
|
94
|
+
break
|
95
|
+
end
|
96
|
+
end
|
79
97
|
|
80
|
-
if
|
81
|
-
|
98
|
+
if original_entry
|
99
|
+
# Use the original log entry content
|
100
|
+
content = original_entry.content
|
101
|
+
return unless content
|
102
|
+
|
103
|
+
# Remove ANSI escape codes for clean copying
|
104
|
+
clean_content = content.gsub(/\e\[[0-9;]*m/, "").strip
|
105
|
+
|
106
|
+
# Check if this is a SQL query and if there's a companion call line
|
107
|
+
is_sql_query = sql_query?(clean_content)
|
108
|
+
|
109
|
+
if is_sql_query
|
110
|
+
# Look for companion call line in the same entry group
|
111
|
+
call_line_content = find_companion_call_line(request, selected_entry_id)
|
112
|
+
|
113
|
+
if call_line_content
|
114
|
+
# Include both SQL query and call line
|
115
|
+
full_content = "#{clean_content}\n#{call_line_content}"
|
116
|
+
Clipboard.copy("```sql\n#{full_content}\n```")
|
117
|
+
else
|
118
|
+
# Just the SQL query
|
119
|
+
Clipboard.copy("```sql\n#{clean_content}\n```")
|
120
|
+
end
|
121
|
+
else
|
122
|
+
Clipboard.copy(clean_content)
|
123
|
+
end
|
82
124
|
else
|
83
|
-
|
125
|
+
# Fallback to the old method - join wrapped lines but try to reconstruct original
|
126
|
+
content = selected_lines.map do |line|
|
127
|
+
text = line[:text] || ""
|
128
|
+
# Remove ANSI escape codes and trim padding
|
129
|
+
text.gsub(/\e\[[0-9;]*m/, "").strip
|
130
|
+
end.reject(&:empty?)
|
131
|
+
|
132
|
+
# Try to join the content intelligently
|
133
|
+
content_text = content.join(" ").gsub(/\s+/, " ").strip
|
134
|
+
|
135
|
+
# Check if this is a SQL query
|
136
|
+
is_sql_query = sql_query?(content_text)
|
137
|
+
|
138
|
+
if is_sql_query
|
139
|
+
Clipboard.copy("```sql\n#{content_text}\n```")
|
140
|
+
else
|
141
|
+
Clipboard.copy(content_text)
|
142
|
+
end
|
84
143
|
end
|
85
144
|
end
|
86
145
|
|
@@ -34,7 +34,9 @@ module LogBench
|
|
34
34
|
return
|
35
35
|
end
|
36
36
|
|
37
|
-
if ch ==
|
37
|
+
if ch == KEY_RESIZE
|
38
|
+
handle_resize
|
39
|
+
elsif ch == KEY_MOUSE
|
38
40
|
mouse_handler.handle_mouse_input
|
39
41
|
elsif filter_mode_active?
|
40
42
|
handle_filter_input(ch)
|
@@ -43,6 +45,11 @@ module LogBench
|
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
48
|
+
def handle_resize
|
49
|
+
screen.handle_resize
|
50
|
+
renderer&.invalidate_caches
|
51
|
+
end
|
52
|
+
|
46
53
|
private
|
47
54
|
|
48
55
|
attr_accessor :state, :screen, :renderer, :mouse_handler, :copy_handler
|
@@ -41,6 +41,11 @@ module LogBench
|
|
41
41
|
cached_lines
|
42
42
|
end
|
43
43
|
|
44
|
+
def invalidate_cache
|
45
|
+
self.cached_lines = nil
|
46
|
+
self.cache_key = nil
|
47
|
+
end
|
48
|
+
|
44
49
|
private
|
45
50
|
|
46
51
|
attr_accessor :screen, :state, :scrollbar, :ansi_renderer, :cached_lines, :cache_key
|
@@ -439,16 +444,16 @@ module LogBench
|
|
439
444
|
# Check if current log is a SQL/cache query followed by a call source line
|
440
445
|
if [:sql, :cache].include?(current_log.type) && next_log && next_log.type == :sql_call_line
|
441
446
|
# Group the query and call source together with the same entry_id
|
442
|
-
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 0)
|
443
|
-
render_padded_text_with_spacing(next_log.content, lines, entry_id, extra_empty_lines: 1, use_separator: true)
|
447
|
+
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 0, original_entry: current_log)
|
448
|
+
render_padded_text_with_spacing(next_log.content, lines, entry_id, extra_empty_lines: 1, use_separator: true, original_entry: current_log)
|
444
449
|
i += 2 # Skip the next log since we processed it
|
445
450
|
else
|
446
451
|
# Handle standalone logs
|
447
452
|
case current_log.type
|
448
453
|
when :sql, :cache
|
449
|
-
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 0)
|
454
|
+
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 0, original_entry: current_log)
|
450
455
|
else
|
451
|
-
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 1)
|
456
|
+
render_padded_text_with_spacing(current_log.content, lines, entry_id, extra_empty_lines: 1, original_entry: current_log)
|
452
457
|
end
|
453
458
|
i += 1
|
454
459
|
end
|
@@ -485,7 +490,7 @@ module LogBench
|
|
485
490
|
matched_indices.sort.map { |index| related_logs[index] }
|
486
491
|
end
|
487
492
|
|
488
|
-
def render_padded_text_with_spacing(text, lines, entry_id, extra_empty_lines: 1, use_separator: false)
|
493
|
+
def render_padded_text_with_spacing(text, lines, entry_id, extra_empty_lines: 1, use_separator: false, original_entry: nil)
|
489
494
|
# Helper function that renders text with padding, breaking long text into multiple lines
|
490
495
|
content_width = detail_win.maxx - 8 # Account for padding (4 spaces each side)
|
491
496
|
|
@@ -501,12 +506,17 @@ module LogBench
|
|
501
506
|
end
|
502
507
|
|
503
508
|
# Render each chunk as a separate line with padding
|
504
|
-
text_chunks.
|
505
|
-
|
509
|
+
text_chunks.each_with_index do |chunk, index|
|
510
|
+
line_data = if has_ansi
|
506
511
|
{text: " #{chunk} ", color: nil, raw_ansi: true, entry_id: entry_id}
|
507
512
|
else
|
508
513
|
{text: " #{chunk} ", color: nil, entry_id: entry_id}
|
509
514
|
end
|
515
|
+
|
516
|
+
# Add original_entry reference to the first line of each entry
|
517
|
+
line_data[:original_entry] = original_entry if index == 0 && original_entry
|
518
|
+
|
519
|
+
lines << line_data
|
510
520
|
end
|
511
521
|
|
512
522
|
# Add extra empty lines after all chunks
|
@@ -34,6 +34,10 @@ module LogBench
|
|
34
34
|
details.get_cached_detail_lines(request)
|
35
35
|
end
|
36
36
|
|
37
|
+
def invalidate_caches
|
38
|
+
details.invalidate_cache
|
39
|
+
end
|
40
|
+
|
37
41
|
private
|
38
42
|
|
39
43
|
attr_accessor :screen, :state, :header, :scrollbar, :request_list, :ansi_renderer, :details, :update_modal
|
data/lib/log_bench/app/screen.rb
CHANGED
@@ -33,6 +33,7 @@ module LogBench
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def cleanup
|
36
|
+
cleanup_windows
|
36
37
|
close_screen
|
37
38
|
end
|
38
39
|
|
@@ -59,6 +60,17 @@ module LogBench
|
|
59
60
|
enabled ? mousemask(0) : mousemask(BUTTON1_CLICKED)
|
60
61
|
end
|
61
62
|
|
63
|
+
def handle_resize
|
64
|
+
# Update terminal dimensions
|
65
|
+
resizeterm(0, 0)
|
66
|
+
clear
|
67
|
+
refresh
|
68
|
+
|
69
|
+
# Recreate windows with new dimensions
|
70
|
+
cleanup_windows
|
71
|
+
setup_windows
|
72
|
+
end
|
73
|
+
|
62
74
|
private
|
63
75
|
|
64
76
|
attr_writer :header_win, :log_win, :panel_width, :detail_win
|
@@ -89,6 +101,12 @@ module LogBench
|
|
89
101
|
init_pair(SELECTION_HIGHLIGHT, COLOR_BLACK, COLOR_CYAN) # Selection highlighting
|
90
102
|
end
|
91
103
|
|
104
|
+
def cleanup_windows
|
105
|
+
header_win&.close
|
106
|
+
log_win&.close
|
107
|
+
detail_win&.close
|
108
|
+
end
|
109
|
+
|
92
110
|
def setup_windows
|
93
111
|
self.panel_width = width / 2 - 2
|
94
112
|
|
data/lib/log_bench/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_bench
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamín Silva
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-09-03 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: zeitwerk
|