Commit db0aab65fd
Unsigned
Layout: unified · split
cmd/curd/main.go +9 −5
| @@ -15,6 +15,14 @@ import ( | |||
| 15 | 15 | ||
| 16 | var version string // Will be set by ldflags during build | 16 | var version string // Will be set by ldflags during build |
| 17 | 17 | ||
| 18 | func resolvedVersion() string { | ||
| 19 | if version == "" { | ||
| 20 | return "1.3.7" | ||
| 21 | } | ||
| 22 | |||
| 23 | return version | ||
| 24 | } | ||
| 25 | |||
| 18 | func main() { | 26 | func main() { |
| 19 | var anime internal.Anime | 27 | var anime internal.Anime |
| 20 | var user internal.User | 28 | var user internal.User |
| @@ -84,11 +92,7 @@ func main() { | |||
| 84 | 92 | ||
| 85 | // Check version before screen clearing | 93 | // Check version before screen clearing |
| 86 | if *versionFlag { | 94 | if *versionFlag { |
| 87 | internal.RestoreScreen() | 95 | fmt.Printf("Curd version: %s\n", resolvedVersion()) |
| 88 | if version == "" { | ||
| 89 | version = "1.3.7" | ||
| 90 | } | ||
| 91 | fmt.Printf("Curd version: %s\n", version) | ||
| 92 | os.Exit(0) | 96 | os.Exit(0) |
| 93 | } | 97 | } |
| 94 | 98 | ||
internal/curd.go +8 −3
| @@ -20,6 +20,8 @@ import ( | |||
| 20 | "github.com/pkg/browser" | 20 | "github.com/pkg/browser" |
| 21 | ) | 21 | ) |
| 22 | 22 | ||
| 23 | var alternateScreenActive bool | ||
| 24 | |||
| 23 | func EditConfig(configFilePath string) { | 25 | func EditConfig(configFilePath string) { |
| 24 | // Get the user's preferred editor from the EDITOR environment variable | 26 | // Get the user's preferred editor from the EDITOR environment variable |
| 25 | editor := os.Getenv("EDITOR") | 27 | editor := os.Getenv("EDITOR") |
| @@ -107,6 +109,9 @@ func Log(data interface{}) error { | |||
| 107 | // ClearScreen clears the terminal screen and saves the state | 109 | // ClearScreen clears the terminal screen and saves the state |
| 108 | func ClearScreen() { | 110 | func ClearScreen() { |
| 109 | userCurdConfig := GetGlobalConfig() | 111 | userCurdConfig := GetGlobalConfig() |
| 112 | if userCurdConfig == nil { | ||
| 113 | return | ||
| 114 | } | ||
| 110 | 115 | ||
| 111 | if userCurdConfig.AlternateScreen == false { | 116 | if userCurdConfig.AlternateScreen == false { |
| 112 | return | 117 | return |
| @@ -115,17 +120,17 @@ func ClearScreen() { | |||
| 115 | fmt.Print("\033[?1049h") // Switch to alternate screen buffer | 120 | fmt.Print("\033[?1049h") // Switch to alternate screen buffer |
| 116 | fmt.Print("\033[2J") // Clear the entire screen | 121 | fmt.Print("\033[2J") // Clear the entire screen |
| 117 | fmt.Print("\033[H") // Move cursor to the top left | 122 | fmt.Print("\033[H") // Move cursor to the top left |
| 123 | alternateScreenActive = true | ||
| 118 | } | 124 | } |
| 119 | 125 | ||
| 120 | // RestoreScreen restores the original terminal state | 126 | // RestoreScreen restores the original terminal state |
| 121 | func RestoreScreen() { | 127 | func RestoreScreen() { |
| 122 | userCurdConfig := GetGlobalConfig() | 128 | if !alternateScreenActive { |
| 123 | |||
| 124 | if userCurdConfig.AlternateScreen == false { | ||
| 125 | return | 129 | return |
| 126 | } | 130 | } |
| 127 | 131 | ||
| 128 | fmt.Print("\033[?1049l") // Switch back to the main screen buffer | 132 | fmt.Print("\033[?1049l") // Switch back to the main screen buffer |
| 133 | alternateScreenActive = false | ||
| 129 | } | 134 | } |
| 130 | 135 | ||
| 131 | func ExitCurd(err error) { | 136 | func ExitCurd(err error) { |