MCPcopy
hub / github.com/mathaou/termdbms / TruncateIfApplicable

Function TruncateIfApplicable

viewer/util.go:26–51  ·  view source on GitHub ↗
(m *TuiModel, conv string)

Source from the content-addressed store, hash-verified

24)
25
26func TruncateIfApplicable(m *TuiModel, conv string) (s string) {
27 max := 0
28 viewportWidth := m.Viewport.Width
29 cellWidth := m.CellWidth()
30 if m.UI.RenderSelection || m.UI.ExpandColumn > -1 {
31 max = viewportWidth
32 } else {
33 max = cellWidth
34 }
35
36 if strings.Count(conv, "\n") > 0 {
37 conv = SplitLines(conv)[0]
38 }
39
40 textWidth := lipgloss.Width(conv)
41 minVal := Min(textWidth, max)
42
43 if max == minVal && textWidth >= max { // truncate
44 s = conv[:minVal]
45 s = s[:lipgloss.Width(s)-3] + "..."
46 } else {
47 s = conv
48 }
49
50 return s
51}
52
53func GetInterfaceFromString(str string, original *interface{}) interface{} {
54 switch (*original).(type) {

Callers 2

initFunction · 0.85
DisplayTableFunction · 0.85

Calls 4

SplitLinesFunction · 0.85
MinFunction · 0.85
CellWidthMethod · 0.80
WidthMethod · 0.80

Tested by

no test coverage detected