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
return strings.Replace(pwd, "c:", "C:", 1)
}
if *env.args.PWD != "" {
if env.args.PWD != nil && *env.args.PWD != "" {
return correctPath(*env.args.PWD)
}
dir, err := os.Getwd()

View file

@ -6,8 +6,16 @@ type node struct {
nodeVersion string
}
const (
//DisplayVersion show the version number or not
DisplayVersion Property = "display_version"
)
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) {

View file

@ -7,10 +7,11 @@ import (
)
type nodeArgs struct {
enabled bool
nodeVersion string
hasJS bool
hasTS bool
enabled bool
nodeVersion string
hasJS bool
hasTS bool
displayVersion bool
}
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("hasFiles", "*.js").Return(args.hasJS)
env.On("hasFiles", "*.ts").Return(args.hasTS)
props := &properties{
values: map[Property]interface{}{
DisplayVersion: args.displayVersion,
},
}
n := &node{
env: env,
env: env,
props: props,
}
return n
}
@ -44,9 +51,10 @@ func TestNodeWriterDisabledNoJSorTSFiles(t *testing.T) {
func TestNodeEnabledJSFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
enabled: true,
nodeVersion: expected,
hasJS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
@ -56,9 +64,10 @@ func TestNodeEnabledJSFiles(t *testing.T) {
func TestNodeEnabledTsFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasTS: true,
enabled: true,
nodeVersion: expected,
hasTS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
@ -68,12 +77,39 @@ func TestNodeEnabledTsFiles(t *testing.T) {
func TestNodeEnabledJsAndTsFiles(t *testing.T) {
expected := "1.14"
args := &nodeArgs{
enabled: true,
nodeVersion: expected,
hasJS: true,
hasTS: true,
enabled: true,
nodeVersion: expected,
hasJS: true,
hasTS: true,
displayVersion: true,
}
node := bootStrapNodeTest(args)
assert.True(t, node.enabled())
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",
"alignment": "left",
"segments": [
{
"type": "root",
"style": "plain",
"foreground": "#E06C75",
"properties": {
"root_icon": "root",
"prefix": "",
"postfix": " <#ffffff>in</> "
}
},
{
"type": "path",
"style": "plain",
"foreground": "#ffffff",
"foreground": "#55B9C4",
"properties": {
"prefix": "",
"home_icon": "~",
"style": "short",
"postfix": " on"
"style": "folder",
"prefix": ""
}
},
{
"type": "git",
"style": "plain",
"foreground": "#F3C267",
"foreground": "#C678DD",
"properties": {
"branch_icon": "",
"display_status": false,
"postfix": " <#C49EE9>[?!]</>"
"prefix": "<#ffffff>on</> ",
"branch_icon": "",
"display_status": true
}
},
{
"type": "command",
"type": "node",
"style": "plain",
"foreground": "#C49EE9",
"foreground": "#98C379",
"properties": {
"shell": "bash",
"command": "find . -name package.json -depth 1 -exec echo \" <#ffffff>via node</>\" \\;"
}
},
{
"type": "root",
"style": "plain",
"foreground": "#B5B50D",
"properties": {
"root_icon": "⚡"
"display_version": true,
"prefix": "<#ffffff>via</> \uE781 "
}
},
{
@ -47,7 +48,8 @@
"style": "plain",
"foreground": "#C94A16",
"properties": {
"prefix": "x"
"prefix": "x",
"display_exit_code": false
}
}
]