DisplaySelection does that or writes it to a file if the selection is over a limit
(m *TuiModel)
| 226 | |
| 227 | // DisplaySelection does that or writes it to a file if the selection is over a limit |
| 228 | func DisplaySelection(m *TuiModel) string { |
| 229 | col := m.GetColumnData() |
| 230 | row := m.GetRow() |
| 231 | m.UI.ExpandColumn = m.GetColumn() |
| 232 | if m.MouseData.Y >= m.Viewport.Height+HeaderHeight && |
| 233 | !m.UI.RenderSelection { // this is for when the selection is outside the bounds |
| 234 | return DisplayTable(m) |
| 235 | } |
| 236 | |
| 237 | base := m.GetBaseStyle() |
| 238 | |
| 239 | if m.Data().EditTextBuffer != "" { // this is basically just if its a string follow these rules |
| 240 | conv := m.Data().EditTextBuffer |
| 241 | if c, err := FormatJson(m.Data().EditTextBuffer); err == nil { |
| 242 | conv = c |
| 243 | } |
| 244 | rows := SplitLines(wordwrap.String(conv, m.Viewport.Width)) |
| 245 | min := 0 |
| 246 | if len(rows) > m.Viewport.Height { |
| 247 | min = m.Viewport.YOffset |
| 248 | } |
| 249 | max := min + m.Viewport.Height |
| 250 | rows = rows[min:Min(len(rows), max)] |
| 251 | |
| 252 | for len(rows) < m.Viewport.Height { |
| 253 | rows = append(rows, "") |
| 254 | } |
| 255 | return base.Render(lipgloss.JoinVertical(lipgloss.Left, rows...)) |
| 256 | } |
| 257 | |
| 258 | var prettyPrint string |
| 259 | raw := col[row] |
| 260 | |
| 261 | if conv, ok := raw.(int64); ok { |
| 262 | prettyPrint = strconv.Itoa(int(conv)) |
| 263 | } else if i, ok := raw.(float64); ok { |
| 264 | prettyPrint = base.Render(fmt.Sprintf("%.2f", i)) |
| 265 | } else if t, ok := raw.(time.Time); ok { |
| 266 | str := t.String() |
| 267 | prettyPrint = base.Render(str) |
| 268 | } else if raw == nil { |
| 269 | prettyPrint = base.Render("NULL") |
| 270 | } |
| 271 | |
| 272 | lines := SplitLines(prettyPrint) |
| 273 | for len(lines) < m.Viewport.Height { |
| 274 | lines = append(lines, "") |
| 275 | } |
| 276 | |
| 277 | prettyPrint = " " + base.Render(lipgloss.JoinVertical(lipgloss.Left, lines...)) |
| 278 | |
| 279 | return wordwrap.String(prettyPrint, m.Viewport.Width) |
| 280 | } |
no test coverage detected