refactor: rename session properties for clarity

This commit is contained in:
Jan De Dobbeleer 2020-10-03 20:11:44 +02:00 committed by Jan De Dobbeleer
parent 10e42db42c
commit 1a52aa9b04
5 changed files with 14 additions and 14 deletions

View file

@ -10,7 +10,7 @@
"foreground": "#ffffff",
"properties": {
"user_info_separator": "",
"display_computer": false,
"display_host": false,
"prefix": "<#CB4B16>┏[</>",
"postfix": "<#CB4B16>]</>"
}

View file

@ -12,7 +12,7 @@
"user_info_separator": " <#ffffff>in</> ",
"prefix": "<#0377C8># </>",
"user_color": "#0377C8",
"computer_color": "#4A9207"
"host_color": "#4A9207"
}
},
{

View file

@ -10,7 +10,7 @@
"foreground": "#E36464",
"properties": {
"user_info_separator": "",
"display_computer": false,
"display_host": false,
"prefix": "@"
}
},

View file

@ -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)
}
@ -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)
}

View file

@ -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"
)
@ -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()