Skip to content
Snippets Groups Projects
Select Git revision
  • v1.20151229
  • master default protected
  • commit-alias
  • editor-modeline
  • commit-abbreviation
  • make-hooks-work-as-advertised
  • lyda-home-version
  • feature-aliases
  • git-version-bsd-fix
  • hook-changes
  • v1.20151229-1
  • v1.20150502-1
  • v1.20150502
  • v1.20141026-manpage-static
  • v1.20141026-1
  • v1.20141026
  • v1.20141025-1
  • v1.20141025
  • v1.20141009-manpage-static
  • v1.20141009-1
  • v1.20141009
  • v1.20140508-1-bpo70+1
  • v1.20140508-1
  • v1.20140508-manpage-static
  • v1.20140508
  • v1.20140507
  • v1.20140313
  • v1.20131229-homebrew
  • v1.20131229-1-bpo60+1
29 results

.mailmap

Blame
  • run.go 1.44 KiB
    // Package bar handles the main program for i3going-on.
    // Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
    package bar
    
    import (
    	"bufio"
    	"fmt"
    	"os"
    	"strings"
    	"time"
    
    	"github.com/spf13/cobra"
    	"github.com/spf13/viper"
    	"gitlab.ie.suberic.net/kevin/i3going-on/config"
    	"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) {
    	viper.BindPFlags(cmd.Flags())
    	cfg, err := config.ReadConfig(viper.GetString("config"))
    	if err != nil {
    		// TODO Make a better default
    		cfg, err = config.ReadConfigStr(`---
    modules:
      - module: text
        name: post
        params:
          text: "post"
          color: "#11ff11"
        on-click: xdg-open https://mastodon.ie/
      - module: date
        params:
          format: 06-05-04 15:02
        on-click: xdg-open https://calendar.google.com/
    `)
    		cobra.CheckErr(err)
    	}
    	go handleCommands()
    
    	fmt.Printf(`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`+"\n",
    		unix.SignalNum("SIGSTOP"), unix.SignalNum("SIGCONT"))
    	separator := "["
    	for {
    		line := make([]string, 0, 5)
    		for _, module := range cfg.Modules {
    			line = append(line, module.Render())
    		}
    		fmt.Printf("%s\n[%s]", separator, strings.Join(line, ","))
    		separator = ","
    		time.Sleep(5 * time.Second)
    	}
    }