Skip to content
Snippets Groups Projects
Select Git revision
  • 154747428c53450aa7fd011cd06715b597778e97
  • main default protected
2 results

run.go

Blame
  • run.go 921 B
    // Package bar handles the main program for i3going-on.
    // Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
    package bar
    
    import (
    	"bufio"
    	"fmt"
    	"os"
    	"time"
    
    	"github.com/spf13/cobra"
    	"golang.org/x/sys/unix"
    )
    
    func handleCommands() {
    	logger, err := os.Create("/tmp/i3going-on.log")
    	if err != nil {
    		panic(err)
    	}
    	scanner := bufio.NewScanner(os.Stdin)
    	for scanner.Scan() {
    		logger.WriteString(scanner.Text())
    	}
    }
    
    // Run is essentially the main program.
    func Run(cmd *cobra.Command, args []string) {
    	go handleCommands()
    
    	fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n",
    		unix.SignalNum("SIGSTOP"), unix.SignalNum("SIGCONT"))
    	fmt.Println("[")
    	for {
    		fmt.Printf(`  [
        {
          "name": "color",
          "full_text": "RED",
          "color": "#11ff11"
        },
        {
          "name": "bland",
          "full_text": "default"
        }
       ],
    `)
    		time.Sleep(5 * time.Second)
    	}
    }