Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/utilities/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ func VersionCmd() *cobra.Command {
}

func DisplayVersionWithUpdateCheck() {
fmt.Print(GetVersionOutput())
fmt.Println(GetVersionOutput())
checkForUpdates()
ui.NewlineBelow()
}

func GetVersionOutput() string {
versionLine := fmt.Sprintf("tmpo version %s %s", ui.Success(Version), ui.Muted(GetFormattedDate(Date)))
changelogLine := ui.Muted(GetChangelogUrl(Version))
return fmt.Sprintf("\n%s\n%s\n\n", versionLine, changelogLine)
return fmt.Sprintf("\n%s\n%s", versionLine, changelogLine)
}

func GetFormattedDate(inputDate string) string {
Expand Down Expand Up @@ -76,8 +77,8 @@ func checkForUpdates() {
}

if updateInfo.HasUpdate {
fmt.Printf("%s %s\n", ui.Info("New Update Available:"), ui.Bold(strings.TrimPrefix(updateInfo.LatestVersion, "v")))
fmt.Printf("%s\n\n", ui.Muted(updateInfo.UpdateURL))
fmt.Printf("\n%s %s\n", ui.Info("New Update Available:"), ui.Bold(strings.TrimPrefix(updateInfo.LatestVersion, "v")))
fmt.Printf("%s", ui.Muted(updateInfo.UpdateURL))
}
}

Expand Down
17 changes: 17 additions & 0 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package shell

import (
"os"
"runtime"
)

func IsLegacyWindowsCMD() bool {
if runtime.GOOS != "windows" {
return false
}

isCMD := os.Getenv("PROMPT") != ""
isUnixLike := os.Getenv("TERM") != ""

return isCMD && !isUnixLike
}
60 changes: 60 additions & 0 deletions internal/shell/shell_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package shell

import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsLegacyWindowsCMD(t *testing.T) {
if runtime.GOOS != "windows" {
t.Run("returns false on non-Windows platforms", func(t *testing.T) {
result := IsLegacyWindowsCMD()
assert.False(t, result)
})
return
}

tests := []struct {
name string
prompt string
term string
expected bool
}{
{
name: "legacy CMD with PROMPT set and no TERM",
prompt: "$P$G",
term: "",
expected: true,
},
{
name: "not CMD because PROMPT is not set",
prompt: "",
term: "",
expected: false,
},
{
name: "Unix-like shell overrides PROMPT",
prompt: "$P$G",
term: "xterm-256color",
expected: false,
},
{
name: "neither PROMPT nor TERM set",
prompt: "",
term: "xterm-256color",
expected: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("PROMPT", tt.prompt)
t.Setenv("TERM", tt.term)

result := IsLegacyWindowsCMD()
assert.Equal(t, tt.expected, result)
})
}
}
6 changes: 5 additions & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"time"

"github.com/DylanDevelops/tmpo/internal/shell"
)

// ANSI Color Constants
Expand Down Expand Up @@ -141,7 +143,9 @@ func NewlineAbove() {
}

func NewlineBelow() {
fmt.Println()
if !shell.IsLegacyWindowsCMD() {
fmt.Println()
}
}

func FormatDuration(d time.Duration) string {
Expand Down
Loading