mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-29 05:16:29 -04:00
Replace most occurrences of os.Exit(0) in the backend and sync packages with a custom backend.Exit function that can allow "soft exit" in GUI/TUI environments to avoid killing the entire process; currently all major errors still result in killing the entire process
This commit is contained in:
@@ -35,7 +35,7 @@ func ParseConfig(readKeys []string, missingValueError string) []string {
|
||||
case "":
|
||||
fmt.Println(AnsiError + "Failed to find value for key \"" + key + "\" in section \"[LIBMUTTON]\" in libmutton.ini" + AnsiReset)
|
||||
case "0":
|
||||
os.Exit(0)
|
||||
Exit(0)
|
||||
default:
|
||||
fmt.Println(AnsiError + missingValueError + AnsiReset)
|
||||
}
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ func ClipClearArgument() {
|
||||
oldContents := clipScanner.Text()
|
||||
clipClear(oldContents)
|
||||
} else {
|
||||
os.Exit(0)
|
||||
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func copyField(executableName, copySubject string) {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,5 +55,5 @@ func clipClear(oldContents string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func copyField(executableName, copySubject string) {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,5 +53,5 @@ func clipClear(oldContents string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func copyField(executableName, copySubject string) {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,5 +77,5 @@ func clipClear(oldContents string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func copyField(executableName, copySubject string) {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@ func clipClear(oldContents string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
os.Exit(0) // use os.Exit instead of backend.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ func Rename(oldLocation, newLocation string) {
|
||||
}
|
||||
|
||||
// TODO implement synced renaming
|
||||
os.Exit(0)
|
||||
Exit(0)
|
||||
}
|
||||
|
||||
// EnsureSliceLength ensures slice is long enough to contain the specified index
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//go:build !returnOnExit
|
||||
|
||||
package backend
|
||||
|
||||
import "os"
|
||||
|
||||
func Exit(code int) {
|
||||
os.Exit(code)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build returnOnExit
|
||||
|
||||
package backend
|
||||
|
||||
func Exit(code int) {
|
||||
return code
|
||||
}
|
||||
Reference in New Issue
Block a user