src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

light.go (535B)


      1 package light
      2 
      3 import (
      4 	"context"
      5 	"fmt"
      6 	"os/exec"
      7 	"strings"
      8 )
      9 
     10 type Block struct{}
     11 
     12 func New() *Block {
     13 	return &Block{}
     14 }
     15 
     16 func (b *Block) Name() string {
     17 	return "light"
     18 }
     19 
     20 func (b *Block) Render(ctx context.Context) (string, error) {
     21 	out, err := exec.CommandContext(ctx, "brightnessctl", "-m").Output()
     22 	if err != nil {
     23 		return "", fmt.Errorf("failed to exec: %v", err)
     24 	}
     25 
     26 	if fields := strings.Split(string(out), ","); len(fields) >= 4 {
     27 		return fmt.Sprintf(" %s", fields[3]), nil
     28 	} else {
     29 		return " ", nil
     30 	}
     31 }