kcalign

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 4 Imported by: 0

README

koron-go/kcalign

PkgGoDev GoDoc Actions/Go Go Report Card

Key code alignment library. Designed to use with QMK keymap.json.

keymapfmt - A tool to format QMK's keymap.json

kcalign includes a tool called keymapfmt. it formats "layers" property in QMK keymap.json with layout which affected its physical key alignments.

Samples:

keymapfmt: How to install
$ go install github.com/koron-go/kcalign/cmd/keymapfmt
keymapfmt: How to use

Most simple usage is reading from STDIN, writing to STDOUT.

keymapfmt [-format {format}] < in.json > out.json

Where {format} accepts two types. First type is file name, it read formatter.json from the file. See formatter.schema.json and kcalign code for details of its schema.

Second type is pre-defined formats. It is form of @{name} or @{name}:{param}. Currently, keymapfmt includes these pre-defined formats:

  • @crkbd - crkbd. no parameter support.

Extended usage is reading from file.

keymapfmt [-format {format}] [-inplace] {files...}

In this form, keymapfmt read JSON from {files...} and write all to STDOUT.

When -inplace option given, keymapfmt replaces contents of each {files...} in place.

Documentation

Overview

Package kcalign provides key code alignment formatter

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	// Desc is description of this formatter.
	Desc string `json:"desc,omitempty"`

	// Width is width of a column. Quote characters are included in count.
	// Valid minimal is 3, default/fall back is 10.
	Width int `json:"width"`

	// Span is number of white spaces between columns. Minimal is 0.
	Span int `json:"span,omitempty"`

	// Quote is quote type for each data.
	Quote QuoteType `json:"quote,omitempty"`

	// Align is default alignment.
	Align RowAlign `json:"align"`

	// ExAligns is exceptional alignments per rows.
	ExAligns map[int]RowAlign `json:"ex_aligns,omitempty"`
}

Formatter provides format strign array, with alignment like key board.

func (*Formatter) Format

func (f *Formatter) Format(w io.Writer, data []string) error

Format writes formatted data by defined alignment.

func (*Formatter) FormatIndent

func (f *Formatter) FormatIndent(w io.Writer, indent int, data []string) error

FormatIndent writes formatted data by defined alignment with indent.

type QuoteType

type QuoteType int

QuoteType specifies runes to quote each items.

const (
	// Double uses dobule quote (`"`).
	Double QuoteType = iota + 1
	// NoQuote doesn't use quote runes, write each items as is.
	NoQuote
)

func (QuoteType) MarshalJSON

func (qt QuoteType) MarshalJSON() ([]byte, error)

MarshalJSON provides json.Marshaler.

func (*QuoteType) UnmarshalJSON

func (qt *QuoteType) UnmarshalJSON(b []byte) error

UnmarshalJSON provides json.Unmarshaler.

type RowAlign

type RowAlign struct {
	// Number of columns.
	Num int `json:"num"`

	// Indent is left indent.
	Indent int `json:"indent,omitempty"`

	// TextAlign is default alignment of coloumn.
	TextAlign TextAlign `json:"text_align,omitempty"`

	// ExMargins extends merge between columns.
	ExMargins map[int]int `json:"ex_margins,omitempty"`

	// ExWidths extends column width by position.
	ExWidths map[int]int `json:"ex_widths,omitempty"`

	// ExTextAligns extedns text alignment of columns.
	ExTextAligns map[int]TextAlign `json:"ex_text_aligns,omitempty"`
}

RowAlign defines alignment property for each rows.

type TextAlign

type TextAlign int

TextAlign specifies text alignment in column.

const (
	// Left is left alignment.
	Left TextAlign = iota + 1
	// Right is right alignment.
	Right
	// Center is center alignment.
	Center
)

func (TextAlign) MarshalJSON

func (ta TextAlign) MarshalJSON() ([]byte, error)

MarshalJSON provides json.Marshaler.

func (*TextAlign) UnmarshalJSON

func (ta *TextAlign) UnmarshalJSON(b []byte) error

UnmarshalJSON provides json.Unmarshaler.

Directories

Path Synopsis
cmd
keymapfmt command
internal
qmkjson
Package qmkjson provides structs for QMK JSON.
Package qmkjson provides structs for QMK JSON.

Jump to

Keyboard shortcuts

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