(m *TuiModel, conv string)
| 24 | ) |
| 25 | |
| 26 | func 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 | |
| 53 | func GetInterfaceFromString(str string, original *interface{}) interface{} { |
| 54 | switch (*original).(type) { |
no test coverage detected