oh-my-posh/src/segments/connection.go

43 lines
902 B
Go
Raw Normal View History

package segments
import (
"strings"
2022-12-28 08:30:48 -08:00
"github.com/jandedobbeleer/oh-my-posh/platform"
"github.com/jandedobbeleer/oh-my-posh/properties"
)
type Connection struct {
props properties.Properties
2022-11-09 11:27:54 -08:00
env platform.Environment
2022-11-09 11:27:54 -08:00
platform.Connection
}
const (
Type properties.Property = "type"
)
func (c *Connection) Template() string {
return " {{ if eq .Type \"wifi\"}}\uf1eb{{ else if eq .Type \"ethernet\"}}\uf6ff{{ end }} "
}
func (c *Connection) Enabled() bool {
types := c.props.GetString(Type, "wifi|ethernet")
connectionTypes := strings.Split(types, "|")
for _, connectionType := range connectionTypes {
2022-11-09 11:27:54 -08:00
network, err := c.env.Connection(platform.ConnectionType(connectionType))
if err != nil {
continue
}
c.Connection = *network
return true
}
return false
}
2022-11-09 11:27:54 -08:00
func (c *Connection) Init(props properties.Properties, env platform.Environment) {
c.props = props
c.env = env
}