fix: improve star theme

relates to #45
This commit is contained in:
Jan De Dobbeleer 2020-10-09 15:49:08 +02:00 committed by Jan De Dobbeleer
parent df739cbb84
commit 3193487234
4 changed files with 84 additions and 38 deletions

View file

@ -48,7 +48,7 @@ func (env *environment) getcwd() string {
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues // on Windows, and being case sentisitive and not consistent and all, this gives silly issues
return strings.Replace(pwd, "c:", "C:", 1) return strings.Replace(pwd, "c:", "C:", 1)
} }
if *env.args.PWD != "" { if env.args.PWD != nil && *env.args.PWD != "" {
return correctPath(*env.args.PWD) return correctPath(*env.args.PWD)
} }
dir, err := os.Getwd() dir, err := os.Getwd()

View file

@ -6,8 +6,16 @@ type node struct {
nodeVersion string nodeVersion string
} }
const (
//DisplayVersion show the version number or not
DisplayVersion Property = "display_version"
)
func (n *node) string() string { func (n *node) string() string {
return n.nodeVersion if n.props.getBool(DisplayVersion, true) {
return n.nodeVersion
}
return ""
} }
func (n *node) init(props *properties, env environmentInfo) { func (n *node) init(props *properties, env environmentInfo) {

View file

@ -7,10 +7,11 @@ import (
) )
type nodeArgs struct { type nodeArgs struct {
enabled bool enabled bool
nodeVersion string nodeVersion string
hasJS bool hasJS bool
hasTS bool hasTS bool
displayVersion bool
} }
func bootStrapNodeTest(args *nodeArgs) *node { func bootStrapNodeTest(args *nodeArgs) *node {
@ -19,8 +20,14 @@ func bootStrapNodeTest(args *nodeArgs) *node {
env.On("runCommand", "node", []string{"--version"}).Return(args.nodeVersion) env.On("runCommand", "node", []string{"--version"}).Return(args.nodeVersion)
env.On("hasFiles", "*.js").Return(args.hasJS) env.On("hasFiles", "*.js").Return(args.hasJS)
env.On("hasFiles", "*.ts").Return(args.hasTS) env.On("hasFiles", "*.ts").Return(args.hasTS)
props := &properties{
values: map[Property]interface{}{
DisplayVersion: args.displayVersion,
},
}
n := &node{ n := &node{
env: env, env: env,
props: props,
} }
return n return n
} }
@ -44,9 +51,10 @@ func TestNodeWriterDisabledNoJSorTSFiles(t *testing.T) {
func TestNodeEnabledJSFiles(t *testing.T) { func TestNodeEnabledJSFiles(t *testing.T) {
expected := "1.14" expected := "1.14"
args := &nodeArgs{ args := &nodeArgs{
enabled: true, enabled: true,
nodeVersion: expected, nodeVersion: expected,
hasJS: true, hasJS: true,
displayVersion: true,
} }
node := bootStrapNodeTest(args) node := bootStrapNodeTest(args)
assert.True(t, node.enabled()) assert.True(t, node.enabled())
@ -56,9 +64,10 @@ func TestNodeEnabledJSFiles(t *testing.T) {
func TestNodeEnabledTsFiles(t *testing.T) { func TestNodeEnabledTsFiles(t *testing.T) {
expected := "1.14" expected := "1.14"
args := &nodeArgs{ args := &nodeArgs{
enabled: true, enabled: true,
nodeVersion: expected, nodeVersion: expected,
hasTS: true, hasTS: true,
displayVersion: true,
} }
node := bootStrapNodeTest(args) node := bootStrapNodeTest(args)
assert.True(t, node.enabled()) assert.True(t, node.enabled())
@ -68,12 +77,39 @@ func TestNodeEnabledTsFiles(t *testing.T) {
func TestNodeEnabledJsAndTsFiles(t *testing.T) { func TestNodeEnabledJsAndTsFiles(t *testing.T) {
expected := "1.14" expected := "1.14"
args := &nodeArgs{ args := &nodeArgs{
enabled: true, enabled: true,
nodeVersion: expected, nodeVersion: expected,
hasJS: true, hasJS: true,
hasTS: true, hasTS: true,
displayVersion: true,
} }
node := bootStrapNodeTest(args) node := bootStrapNodeTest(args)
assert.True(t, node.enabled()) assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "node is available and JS and TS files are found") assert.Equal(t, expected, node.string(), "node is available and JS and TS files are found")
} }
func TestNodeEnabledNoVersion(t *testing.T) {
expected := ""
args := &nodeArgs{
enabled: true,
nodeVersion: "1.14",
hasJS: true,
displayVersion: false,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "we don't expect a version")
}
func TestNodeEnabledNodeVersion(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
assert.Equal(t, expected, node.string(), "we expect a version")
}

View file

@ -4,42 +4,43 @@
"type": "prompt", "type": "prompt",
"alignment": "left", "alignment": "left",
"segments": [ "segments": [
{
"type": "root",
"style": "plain",
"foreground": "#E06C75",
"properties": {
"root_icon": "root",
"prefix": "",
"postfix": " <#ffffff>in</> "
}
},
{ {
"type": "path", "type": "path",
"style": "plain", "style": "plain",
"foreground": "#ffffff", "foreground": "#55B9C4",
"properties": { "properties": {
"prefix": "",
"home_icon": "~", "home_icon": "~",
"style": "short", "style": "folder",
"postfix": " on" "prefix": ""
} }
}, },
{ {
"type": "git", "type": "git",
"style": "plain", "style": "plain",
"foreground": "#F3C267", "foreground": "#C678DD",
"properties": { "properties": {
"branch_icon": "", "prefix": "<#ffffff>on</> ",
"display_status": false, "branch_icon": "",
"postfix": " <#C49EE9>[?!]</>" "display_status": true
} }
}, },
{ {
"type": "command", "type": "node",
"style": "plain", "style": "plain",
"foreground": "#C49EE9", "foreground": "#98C379",
"properties": { "properties": {
"shell": "bash", "display_version": true,
"command": "find . -name package.json -depth 1 -exec echo \" <#ffffff>via node</>\" \\;" "prefix": "<#ffffff>via</> \uE781 "
}
},
{
"type": "root",
"style": "plain",
"foreground": "#B5B50D",
"properties": {
"root_icon": "⚡"
} }
}, },
{ {
@ -47,7 +48,8 @@
"style": "plain", "style": "plain",
"foreground": "#C94A16", "foreground": "#C94A16",
"properties": { "properties": {
"prefix": "x" "prefix": "x",
"display_exit_code": false
} }
} }
] ]