Repository: pterm/pterm
Pull request #590 (2023-11-28 01:24:01)

chore(deps): bump golang.org/x/term from 0.13.0 to 0.15.0
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.13.0 to 0.15.0.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/golang/term/commit/ee66497fa39f03ba841b568a7b4f4ee4e4546f74"><code>ee66497</code></a> go.mod: update golang.org/x dependencies</li>
<li><a href="https://github.com/golang/term/commit/70d3a0bd3f7eb457a282ab2a2a8452a69a79400c"><code>70d3a0b</code></a> go.mod: update golang.org/x dependencies</li>
<li><a href="https://github.com/golang/term/commit/6a610bc55bff057aed1d188757e3d0247a3badf2"><code>6a610bc</code></a> all: update go directive to 1.18</li>
<li>See full diff in <a href="https://github.com/golang/term/compare/v0.13.0...v0.15.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang.org/x/term&package-manager=go_modules&previous-version=0.13.0&new-version=0.15.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pterm/pterm/pull/590?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pterm) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`4d9914e`)](https://app.codecov.io/gh/pterm/pterm/commit/4d9914e569553af7e10e552c9a7a98f442f4b93f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pterm) 81.83% compared to head [(`537a184`)](https://app.codecov.io/gh/pterm/pterm/pull/590?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pterm) 81.83%.
> Report is 1 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #590   +/-   ##
=======================================
  Coverage   81.83%   81.83%           
=======================================
  Files          33       33           
  Lines        4118     4118           
=======================================
  Hits         3370     3370           
  Misses        684      684           
  Partials       64       64           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pterm/pterm/pull/590?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pterm).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pterm).


Patch:
diff --git a/go.mod b/go.mod
index a9742f53..02cd2ac3 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@ require (
 	github.com/gookit/color v1.5.4
 	github.com/lithammer/fuzzysearch v1.1.8
 	github.com/mattn/go-runewidth v0.0.15
-	golang.org/x/term v0.13.0
+	golang.org/x/term v0.15.0
 	golang.org/x/text v0.13.0
 )
 
@@ -22,5 +22,5 @@ require (
 	github.com/rivo/uniseg v0.4.4 // indirect
 	github.com/sergi/go-diff v1.2.0 // indirect
 	github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
-	golang.org/x/sys v0.13.0 // indirect
+	golang.org/x/sys v0.15.0 // indirect
 )
diff --git a/go.sum b/go.sum
index ccb6d0ae..62752799 100644
--- a/go.sum
+++ b/go.sum
@@ -86,15 +86,15 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
-golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
+golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
-golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
-golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
+golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
+golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
diff --git a/interactive_continue_printer.go b/interactive_continue_printer.go
index f7e49e8a..4049cde9 100644
--- a/interactive_continue_printer.go
+++ b/interactive_continue_printer.go
@@ -2,7 +2,6 @@ package pterm
 
 import (
 	"fmt"
-	"os"
 	"strings"
 
 	"atomicgo.dev/cursor"
@@ -155,7 +154,7 @@ func (p InteractiveContinuePrinter) Show(text ...string) (string, error) {
 			result = p.Options[p.DefaultValueIndex]
 			return true, nil
 		case keys.CtrlC:
-			os.Exit(1)
+			internal.Exit(1)
 			return true, nil
 		}
 		return false, nil
diff --git a/internal/cancelation_signal.go b/internal/cancelation_signal.go
index ed424daf..33f17cc1 100644
--- a/internal/cancelation_signal.go
+++ b/internal/cancelation_signal.go
@@ -9,8 +9,12 @@ func NewCancelationSignal(interruptFunc func()) (func(), func()) {
 	}
 
 	exit := func() {
-		if canceled && interruptFunc != nil {
-			interruptFunc()
+		if canceled {
+			if interruptFunc != nil {
+				interruptFunc()
+			} else {
+				Exit(1)
+			}
 		}
 	}
 
diff --git a/internal/exit.go b/internal/exit.go
new file mode 100644
index 00000000..f29f74e8
--- /dev/null
+++ b/internal/exit.go
@@ -0,0 +1,14 @@
+package internal
+
+import "os"
+
+// ExitFuncType is the type of function used to exit the program.
+type ExitFuncType func(int)
+
+// DefaultExitFunc is the default function used to exit the program.
+var DefaultExitFunc ExitFuncType = os.Exit
+
+// Exit calls the current exit function.
+func Exit(code int) {
+    DefaultExitFunc(code)
+}
\ No newline at end of file


Test patch:
diff --git a/interactive_textinput_printer_test.go b/interactive_textinput_printer_test.go
index 2f925a02..8d9c54c8 100644
--- a/interactive_textinput_printer_test.go
+++ b/interactive_textinput_printer_test.go
@@ -1,6 +1,7 @@
 package pterm_test
 
 import (
+	"os"
 	"reflect"
 	"testing"
 	"time"
@@ -10,6 +11,7 @@ import (
 	"github.com/MarvinJWendt/testza"
 
 	"github.com/pterm/pterm"
+	"github.com/pterm/pterm/internal"
 )
 
 func TestInteractiveTextInputPrinter_WithDefaultText(t *testing.T) {
@@ -56,12 +58,23 @@ func TestInteractiveTextInputPrinter_WithMask(t *testing.T) {
 }
 
 func TestInteractiveTextInputPrinter_WithCancel(t *testing.T) {
-	go func() {
-		time.Sleep(1 * time.Millisecond)
-		keyboard.SimulateKeyPress(keys.CtrlC)
-	}()
-	result, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show()
-	testza.AssertEqual(t, "", result)
+    exitCalled := false
+    internal.DefaultExitFunc = func(code int) {
+        exitCalled = true
+    }
+    defer func() { internal.DefaultExitFunc = os.Exit }()
+
+    go func() {
+        time.Sleep(1 * time.Millisecond)
+        keyboard.SimulateKeyPress(keys.CtrlC)
+    }()
+
+    result, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show()
+    testza.AssertEqual(t, "", result)
+
+    if !exitCalled {
+        t.Errorf("Expected exit to be called on Ctrl+C")
+    }
 }
 
 func TestInteractiveTextInputPrinter_OnEnter(t *testing.T) {
diff --git a/internal/cancelation_signal_test.go b/internal/cancelation_signal_test.go
new file mode 100644
index 00000000..5972bc66
--- /dev/null
+++ b/internal/cancelation_signal_test.go
@@ -0,0 +1,54 @@
+package internal
+
+import (
+	"os"
+	"testing"
+)
+
+func TestNewCancelationSignal(t *testing.T) {
+    // Mock DefaultExitFunc
+    exitCalled := false
+    exitCode := 0
+    DefaultExitFunc = func(code int) {
+        exitCalled = true
+        exitCode = code
+    }
+    defer func() { DefaultExitFunc = os.Exit }() // Reset after tests
+
+    // Scenario 1: Testing cancel function
+    cancel, exit := NewCancelationSignal(nil)
+    if exitCalled {
+        t.Error("Exit function should not be called immediately after NewCancelationSignal")
+    }
+
+    // Scenario 2: Testing exit function without cancel
+    exit()
+    if exitCalled {
+        t.Error("Exit function should not be called when cancel is not set")
+    }
+
+    // Scenario 3: Testing cancel then exit with no interruptFunc
+    cancel()
+    exit()
+    if !exitCalled || exitCode != 1 {
+        t.Errorf("Expected Exit(1) to be called, exitCalled: %v, exitCode: %d", exitCalled, exitCode)
+    }
+
+    // Reset for next scenario
+    exitCalled = false
+    exitCode = 0
+
+    // Scenario 4: Testing cancel then exit with interruptFunc
+    interruptCalled := false
+    cancel, exit = NewCancelationSignal(func() {
+        interruptCalled = true
+    })
+    cancel()
+    exit()
+    if interruptCalled == false {
+        t.Error("Expected interruptFunc to be called")
+    }
+    if exitCalled {
+        t.Error("Exit should not be called when interruptFunc is provided")
+    }
+}
diff --git a/internal/exit_test.go b/internal/exit_test.go
new file mode 100644
index 00000000..5b15473b
--- /dev/null
+++ b/internal/exit_test.go
@@ -0,0 +1,23 @@
+package internal_test
+
+import (
+	"os"
+	"testing"
+
+	"github.com/pterm/pterm/internal"
+)
+
+func TestExit(t *testing.T) {
+    var lastExitCode int
+    internal.DefaultExitFunc = func(code int) {
+        lastExitCode = code
+    }
+
+    defer func() { internal.DefaultExitFunc = os.Exit }() 
+
+    internal.Exit(1)
+
+    if lastExitCode != 1 {
+        t.Errorf("Expected exit code 1, got %d", lastExitCode)
+    }
+}