aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/enablement.go
blob: f3e74e0fdf83a7e4de5b05ea371dc871127c2efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package system

import (
	"fmt"
	"strings"
)

// Enablement represents optional system resources.
type Enablement byte

const (
	EWayland Enablement = 1 << iota
	EX11
	EDBus
	EPulse

	EM
)

func (e Enablement) String() string {
	switch e {
	case 0:
		return "(no enablements)"
	case EWayland:
		return "wayland"
	case EX11:
		return "x11"
	case EDBus:
		return "dbus"
	case EPulse:
		return "pulseaudio"
	default:
		buf := new(strings.Builder)
		buf.Grow(32)

		for i := Enablement(1); i < EM; i <<= 1 {
			if e&i != 0 {
				buf.WriteString(", " + i.String())
			}
		}

		if buf.Len() == 0 {
			return fmt.Sprintf("e%x", byte(e))
		}
		return strings.TrimPrefix(buf.String(), ", ")
	}
}