i3barjson

package module
v0.0.0-...-b537b5b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2016 License: BSD-2-Clause Imports: 3 Imported by: 12

README

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

  • The Update function is not thread-safe, so it must always be called from the same thread.
  • The i3bar JSON protocol spec allows the min_width field to be either a string or an int. It's not easy to parse a field that can have two different types in Go's JSON library, so Go-i3barjson only supports a single type for min_width: the string type. The reason the string type was chosen over the int type is that min_width's string type (which specifies character-width) seems more generally useful than its int type (which specifies pixel-width).

TODO

  • Implement stdin handling to read mouse events from i3bar.

Documentation

Overview

Package i3barjson provides a Go library for i3bar JSON protocol support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(w io.Writer, r io.Reader, h Header, pretty bool) error

Init initializes the i3bar io. w is the io.Writer to write to (usually os.Stdout). r is the io.Reader to from (usually os.Stdin) (TODO: implement). h is the Header object to send as the first line to i3bar. pretty controls whether or not json output will be pretty printed.

func Update

func Update(s StatusLine) error

Update sends a new StatusLine to i3bar. NOTE: this function is not thread safe. Only call it from a single thread.

Types

type Block

type Block struct {
	FullText            string `json:"full_text"`
	ShortText           string `json:"short_text,omitempty"`
	Color               string `json:"color,omitempty"`
	MinWidth            string `json:"min_width,omitempty"`
	Align               string `json:"align,omitempty"`
	Name                string `json:"name,omitempty"`
	Instance            string `json:"instance,omitempty"`
	Urgent              bool   `json:"urgent,omitempty"`
	Separator           bool   `json:"separator"`
	SeparatorBlockWidth int    `json:"separator_block_width,omitempty"`
	Markup              string `json:"markup,omitempty"`
}

Block represents a single block of an i3bar message.

func (Block) String

func (d Block) String() string

String pretty prints Block objects.

type Click

type Click struct {
	Name     string `json:"name"`
	Instance string `json:"instance"`
	X        int    `json:"x"`
	Y        int    `json:"y"`
	Button   int    `json:"button"`
}

Click represents an i3bar click event.

func (Click) String

func (d Click) String() string

String pretty prints Click objects.

type Header struct {
	Version     int  `json:"version"`
	StopSignal  int  `json:"stop_signal,omitempty"`
	ContSignal  int  `json:"cont_signal,omitempty"`
	ClickEvents bool `json:"click_events,omitempty"`
}

Header represents the header of an i3bar message.

func (Header) String

func (d Header) String() string

String pretty prints Header objects.

type StatusLine

type StatusLine []*Block

StatusLine represents a full i3bar status line.

func (StatusLine) String

func (d StatusLine) String() string

String pretty prints StatusLine objects.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL