Skip to content

Commit

Permalink
refactor: rename session properties for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Oct 5, 2020
1 parent 10e42db commit 1a52aa9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Themes/darkblood.json
Expand Up @@ -10,7 +10,7 @@
"foreground": "#ffffff",
"properties": {
"user_info_separator": "",
"display_computer": false,
"display_host": false,
"prefix": "<#CB4B16>┏[</>",
"postfix": "<#CB4B16>]</>"
}
Expand Down
2 changes: 1 addition & 1 deletion Themes/honukai.json
Expand Up @@ -12,7 +12,7 @@
"user_info_separator": " <#ffffff>in</> ",
"prefix": "<#0377C8># </>",
"user_color": "#0377C8",
"computer_color": "#4A9207"
"host_color": "#4A9207"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Themes/zash.json
Expand Up @@ -10,7 +10,7 @@
"foreground": "#E36464",
"properties": {
"user_info_separator": "",
"display_computer": false,
"display_host": false,
"prefix": "@"
}
},
Expand Down
10 changes: 5 additions & 5 deletions properties_test.go
Expand Up @@ -68,11 +68,11 @@ func TestDefaultColorWithUnavailableProperty(t *testing.T) {

func TestGetBool(t *testing.T) {
expected := true
values := map[Property]interface{}{DisplayComputer: expected}
values := map[Property]interface{}{DisplayHost: expected}
properties := properties{
values: values,
}
value := properties.getBool(DisplayComputer, false)
value := properties.getBool(DisplayHost, false)
assert.True(t, value)
}

Expand All @@ -81,15 +81,15 @@ func TestGetBoolPropertyNotInMap(t *testing.T) {
properties := properties{
values: values,
}
value := properties.getBool(DisplayComputer, false)
value := properties.getBool(DisplayHost, false)
assert.False(t, value)
}

func TestGetBoolInvalidProperty(t *testing.T) {
values := map[Property]interface{}{DisplayComputer: "borked"}
values := map[Property]interface{}{DisplayHost: "borked"}
properties := properties{
values: values,
}
value := properties.getBool(DisplayComputer, false)
value := properties.getBool(DisplayHost, false)
assert.False(t, value)
}
12 changes: 6 additions & 6 deletions segment_session.go
Expand Up @@ -15,10 +15,10 @@ const (
UserInfoSeparator Property = "user_info_separator"
//UserColor if set, is used to color the user name
UserColor Property = "user_color"
//ComputerColor if set, is used to color the computer name
ComputerColor Property = "computer_color"
//DisplayComputer hides or show the computer name
DisplayComputer Property = "display_computer"
//HostColor if set, is used to color the computer name
HostColor Property = "host_color"
//DisplayHost hides or show the computer name
DisplayHost Property = "display_host"
//DisplayUser hides or shows the user name
DisplayUser Property = "display_user"
)
Expand All @@ -39,11 +39,11 @@ func (s *session) init(props *properties, env environmentInfo) {
func (s *session) getFormattedText() string {
username := s.getUserName()
computername := s.getComputerName()
return fmt.Sprintf("<%s>%s</>%s<%s>%s</>", s.props.getColor(UserColor, s.props.foreground), username, s.props.getString(UserInfoSeparator, "@"), s.props.getColor(ComputerColor, s.props.foreground), computername)
return fmt.Sprintf("<%s>%s</>%s<%s>%s</>", s.props.getColor(UserColor, s.props.foreground), username, s.props.getString(UserInfoSeparator, "@"), s.props.getColor(HostColor, s.props.foreground), computername)
}

func (s *session) getComputerName() string {
if !s.props.getBool(DisplayComputer, true) {
if !s.props.getBool(DisplayHost, true) {
return ""
}
computername, err := s.env.getHostName()
Expand Down

0 comments on commit 1a52aa9

Please sign in to comment.