()
| 384 | } |
| 385 | |
| 386 | func (m model) View() string { |
| 387 | if m.fatalErr != nil { |
| 388 | return fmt.Sprintf("An unrecoverable error occured: %v\n", m.fatalErr) |
| 389 | } |
| 390 | if m.selected == Selected || m.selected == SelectedWithChangeDir { |
| 391 | SELECTED_COMMAND = m.tableEntries[m.table.Cursor()].Command |
| 392 | if m.selected == SelectedWithChangeDir { |
| 393 | changeDir := m.tableEntries[m.table.Cursor()].CurrentWorkingDirectory |
| 394 | if strings.HasPrefix(changeDir, "~/") { |
| 395 | homedir, err := os.UserHomeDir() |
| 396 | if err != nil { |
| 397 | hctx.GetLogger().Warnf("UserHomeDir() return err=%v, skipping replacing ~/", err) |
| 398 | } else { |
| 399 | strippedChangeDir, _ := strings.CutPrefix(changeDir, "~/") |
| 400 | changeDir = filepath.Join(homedir, strippedChangeDir) |
| 401 | } |
| 402 | } |
| 403 | SELECTED_COMMAND = "cd \"" + changeDir + "\" && " + SELECTED_COMMAND |
| 404 | } |
| 405 | return "" |
| 406 | } |
| 407 | if m.quitting { |
| 408 | return "" |
| 409 | } |
| 410 | additionalMessages := make([]string, 0) |
| 411 | if m.isLoading { |
| 412 | additionalMessages = append(additionalMessages, fmt.Sprintf("%s Loading hishtory entries from other devices...", m.spinner.View())) |
| 413 | } |
| 414 | if m.isOffline { |
| 415 | additionalMessages = append(additionalMessages, "Warning: failed to contact the hishtory backend (are you offline?), so some results may be stale") |
| 416 | } |
| 417 | if m.searchErr != nil { |
| 418 | additionalMessages = append(additionalMessages, fmt.Sprintf("Warning: failed to search: %v", m.searchErr)) |
| 419 | } |
| 420 | if LAST_PROCESSED_QUERY_ID < LAST_DISPATCHED_QUERY_ID && time.Since(LAST_DISPATCHED_QUERY_TIMESTAMP) > time.Second { |
| 421 | additionalMessages = append(additionalMessages, fmt.Sprintf("%s Executing search query...", m.spinner.View())) |
| 422 | } |
| 423 | additionalMessagesStr := strings.Join(additionalMessages, "\n") + "\n" |
| 424 | if isExtraCompactHeightMode(m.ctx) { |
| 425 | additionalMessagesStr = "\n" |
| 426 | } |
| 427 | helpView := m.help.View(loadedKeyBindings) |
| 428 | if isExtraCompactHeightMode(m.ctx) { |
| 429 | helpView = "" |
| 430 | } |
| 431 | additionalSpacing := "\n" |
| 432 | if isCompactHeightMode(m.ctx) { |
| 433 | additionalSpacing = "" |
| 434 | } |
| 435 | return fmt.Sprintf("%s%s%s%sSearch Query: %s\n%s%s\n", additionalSpacing, additionalMessagesStr, m.banner, additionalSpacing, m.queryInput.View(), additionalSpacing, renderNullableTable(m, helpView)) + helpView |
| 436 | } |
| 437 | |
| 438 | func isExtraCompactHeightMode(ctx context.Context) bool { |
| 439 | if hctx.GetConf(ctx).ForceCompactMode { |
no test coverage detected