(imageFull string, errFirst *promptForDownloadError)
| 833 | } |
| 834 | |
| 835 | func showPromptForDownloadSecond(imageFull string, errFirst *promptForDownloadError) bool { |
| 836 | oldState, err := term.GetState(os.Stdin) |
| 837 | if err != nil { |
| 838 | logrus.Debugf("Show prompt for download: failed to get terminal state: %s", err) |
| 839 | return false |
| 840 | } |
| 841 | |
| 842 | defer term.SetState(os.Stdin, oldState) |
| 843 | |
| 844 | lockedState := term.NewStateFrom(oldState, |
| 845 | term.WithVMIN(1), |
| 846 | term.WithVTIME(0), |
| 847 | term.WithoutECHO(), |
| 848 | term.WithoutICANON()) |
| 849 | |
| 850 | if err := term.SetState(os.Stdin, lockedState); err != nil { |
| 851 | logrus.Debugf("Show prompt for download: failed to set terminal state: %s", err) |
| 852 | return false |
| 853 | } |
| 854 | |
| 855 | parentCtx := context.Background() |
| 856 | discardCtx, discardCancel := context.WithCancelCause(parentCtx) |
| 857 | defer discardCancel(errors.New("clean-up")) |
| 858 | |
| 859 | discardCh, discardErrCh := discardInputAsync(discardCtx) |
| 860 | |
| 861 | var prompt string |
| 862 | if errors.Is(errFirst, context.Canceled) { |
| 863 | prompt = createPromptForDownload(imageFull, errFirst.ImageSize) |
| 864 | } else { |
| 865 | prompt = createPromptForDownload(imageFull, "") |
| 866 | } |
| 867 | |
| 868 | fmt.Printf("\r") |
| 869 | |
| 870 | askCtx, askCancel := context.WithCancelCause(parentCtx) |
| 871 | defer askCancel(errors.New("clean-up")) |
| 872 | |
| 873 | var askForConfirmationPreFnDone bool |
| 874 | askForConfirmationPreFn := func() error { |
| 875 | defer discardCancel(errors.New("clean-up")) |
| 876 | if askForConfirmationPreFnDone { |
| 877 | return nil |
| 878 | } |
| 879 | |
| 880 | // Erase to end of line |
| 881 | fmt.Printf("\033[K") |
| 882 | |
| 883 | // Save the cursor position. |
| 884 | fmt.Printf("\033[s") |
| 885 | |
| 886 | if err := term.SetState(os.Stdin, oldState); err != nil { |
| 887 | return fmt.Errorf("failed to restore terminal state: %w", err) |
| 888 | } |
| 889 | |
| 890 | cause := errors.New("terminal restored") |
| 891 | discardCancel(cause) |
| 892 |
no test coverage detected
searching dependent graphs…