Skip to content

Commit de6c829

Browse files
committed
fix bug
1 parent a24d95e commit de6c829

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

ui.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ func drawBuffer(b *Buffer, t *tview.Table, trs bool) {
6565
}
6666

6767
// Apply text wrapping if column is marked for wrapping
68-
if maxWidth, isWrapped := wrappedColumns[c]; isWrapped {
69-
cellText = wrapText(cellText, maxWidth)
68+
maxWidth := 0 // 0 means no limit
69+
if wrapWidth, isWrapped := wrappedColumns[c]; isWrapped {
70+
cellText = wrapText(cellText, wrapWidth)
71+
maxWidth = wrapWidth
7072
}
7173

7274
if r == 0 && args.Header != -1 && args.Header != 2 {
@@ -75,7 +77,7 @@ func drawBuffer(b *Buffer, t *tview.Table, trs bool) {
7577
SetTextColor(color).
7678
SetBackgroundColor(backgroundColor).
7779
SetAlign(tview.AlignLeft).
78-
SetMaxWidth(0). // 0 means no limit, allows wrapping
80+
SetMaxWidth(maxWidth).
7981
SetExpansion(1))
8082
continue
8183
}
@@ -84,7 +86,7 @@ func drawBuffer(b *Buffer, t *tview.Table, trs bool) {
8486
SetTextColor(color).
8587
SetBackgroundColor(backgroundColor).
8688
SetAlign(tview.AlignLeft).
87-
SetMaxWidth(0).
89+
SetMaxWidth(maxWidth).
8890
SetExpansion(1))
8991
}
9092
}
@@ -130,6 +132,10 @@ func drawUI(b *Buffer, trs bool) error {
130132
bufferTable.SetBorders(false)
131133
bufferTable.SetFixed(b.rowFreeze, b.colFreeze)
132134
bufferTable.Select(0, 0)
135+
136+
// Auto-detect and enable wrapping for long columns
137+
autoDetectAndWrapLongColumns(b)
138+
133139
drawBuffer(b, bufferTable, trs)
134140

135141
//main page init with modern footer colors

utils.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,53 @@ func getColumnMaxWidth(colIndex int) int {
181181
return defaultWidth
182182
}
183183

184+
// autoDetectAndWrapLongColumns analyzes buffer columns and auto-enables wrapping for long content
185+
// This scans sample rows to detect if any column has content exceeding the threshold
186+
func autoDetectAndWrapLongColumns(b *Buffer) {
187+
if b == nil || b.rowLen == 0 || b.colLen == 0 {
188+
return
189+
}
190+
191+
const maxSampleRows = 100 // Sample up to 100 rows for detection
192+
const lengthThreshold = 50 // Auto-wrap columns with content > 50 chars
193+
const defaultWrapWidth = 40 // Default wrap width for long columns
194+
195+
b.mu.RLock()
196+
defer b.mu.RUnlock()
197+
198+
// Determine how many rows to sample
199+
sampleRows := b.rowLen
200+
if sampleRows > maxSampleRows {
201+
sampleRows = maxSampleRows
202+
}
203+
204+
// Start from row after headers
205+
startRow := b.rowFreeze
206+
if startRow >= b.rowLen {
207+
return
208+
}
209+
210+
// Check each column
211+
for col := 0; col < b.colLen; col++ {
212+
maxLength := 0
213+
214+
// Sample rows to find max content length in this column
215+
for row := startRow; row < startRow+sampleRows && row < b.rowLen; row++ {
216+
if col < len(b.cont[row]) {
217+
cellLen := len(b.cont[row][col])
218+
if cellLen > maxLength {
219+
maxLength = cellLen
220+
}
221+
}
222+
}
223+
224+
// Auto-enable wrapping if content exceeds threshold
225+
if maxLength > lengthThreshold {
226+
wrappedColumns[col] = defaultWrapWidth
227+
}
228+
}
229+
}
230+
184231
// performSearch searches for a query string in the buffer and stores results
185232
func performSearch(b *Buffer, query string, caseSensitive bool) []SearchResult {
186233
results := []SearchResult{}

0 commit comments

Comments
 (0)