Home

Awesome

Go-i3barjson

Go-i3barjson is a Go library that implements the i3bar JSON input protocol.

Get

Go-i3barjson requires Go version 1.7+.

Fetch and build Go-i3barjson:

go get github.com/davidscholberg/go-i3barjson

Usage

Here's a simple example for using Go-i3barjson:

package main

import (
	"fmt"
	"github.com/davidscholberg/go-i3barjson"
	"os"
	"time"
)

func main() {
	h := i3barjson.Header{Version: 1}
	err := i3barjson.Init(os.Stdout, nil, h, false)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s", err)
		return
	}

	countBlock := i3barjson.Block{}
	timeBlock := i3barjson.Block{}
	status := i3barjson.StatusLine{&countBlock, &timeBlock}

	for i := 0; i < 10; i++ {
		countBlock.FullText = fmt.Sprintf("%d", i)
		timeBlock.FullText = time.Now().Format("2006-01-02 15:04:05")
		err = i3barjson.Update(status)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s", err)
			break
		}
		time.Sleep(time.Second)
	}
}

Caveats

TODO