(title string)
| 2851 | } |
| 2852 | |
| 2853 | func (p *Plugin) showLiveOutputModal(title string) (appendLine func(string), closeModalFn func()) { |
| 2854 | pages := p.app.Pages() |
| 2855 | pages.RemovePage(liveOutputPageName) |
| 2856 | |
| 2857 | text := tview.NewTextView() |
| 2858 | text.SetBorder(true) |
| 2859 | text.SetBorderColor(theme.Colors.Border) |
| 2860 | text.SetTitle(" " + title + " ") |
| 2861 | text.SetTitleColor(theme.Colors.Primary) |
| 2862 | text.SetDynamicColors(false) |
| 2863 | text.SetWrap(true) |
| 2864 | text.SetWordWrap(true) |
| 2865 | text.SetScrollable(true) |
| 2866 | text.SetText("(streaming output...)\n") |
| 2867 | |
| 2868 | closeModal := func() { |
| 2869 | pages.RemovePage(liveOutputPageName) |
| 2870 | } |
| 2871 | |
| 2872 | text.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { |
| 2873 | if isBackKey(event) || (event.Key() == tcell.KeyRune && (event.Rune() == 'q' || event.Rune() == 'Q')) { |
| 2874 | p.cancelRunningCommand() |
| 2875 | closeModal() |
| 2876 | return nil |
| 2877 | } |
| 2878 | return event |
| 2879 | }) |
| 2880 | |
| 2881 | pages.AddPage(liveOutputPageName, p.centerModal(text, 120, 30), true, true) |
| 2882 | p.app.SetFocus(text) |
| 2883 | |
| 2884 | appendFn := func(line string) { |
| 2885 | trimmed := strings.TrimSpace(line) |
| 2886 | if trimmed == "" { |
| 2887 | return |
| 2888 | } |
| 2889 | p.app.QueueUpdateDraw(func() { |
| 2890 | _, _ = fmt.Fprintln(text, trimmed) |
| 2891 | text.ScrollToEnd() |
| 2892 | }) |
| 2893 | } |
| 2894 | |
| 2895 | return appendFn, closeModal |
| 2896 | } |
| 2897 | |
| 2898 | func runCommandWithStreaming(cmd *exec.Cmd, stream func(string)) (string, error) { |
| 2899 | stdoutPipe, err := cmd.StdoutPipe() |
no test coverage detected