typioca icon indicating copy to clipboard operation
typioca copied to clipboard

Layout generation

Open DanWlker opened this issue 7 months ago • 0 comments

Layouts are currently generated with this script. Currently thinking if there is a way to automate it. The script as pasted below currently should generate the Dvorak Layout.

Steps to add a new layout:

  1. Add the layout json file into the layouts folder and push
  2. Add a new defaultLayoutFile into cmd/config.go
  3. Update currentConfigVersion in cmd/config.go

Can refer https://github.com/bloznelis/typioca/tree/master/words for example of where to put the generation code so it lives alongside the repo but is not included in the binary

type Layout struct {
	Name     string        `json:"name"`
	Mappings map[rune]rune `json:"mappings"`
}

func FWriteStructToYaml[T any](stuff T) error {
	f, err := os.OpenFile(fileLocation, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
	defer f.Close()
	if err != nil {
		panic(err)
	}
	enc := json.NewEncoder(f)
	if err := enc.Encode(stuff); err != nil {
		panic(err)
	}

	return nil
}

func main() {

	thing := Layout{
		Name: "Dvorak",
		Mappings: map[rune]rune{

			'q': '\'',
			'w': ',',
			'e': '.',
			'r': 'p',
			't': 'y',
			'y': 'f',
			'u': 'g',
			'i': 'c',
			'o': 'r',
			'p': 'l',
			'[': '/',
			']': '=',

			'a':  'a',
			's':  'o',
			'd':  'e',
			'f':  'u',
			'g':  'i',
			'h':  'd',
			'j':  'h',
			'k':  't',
			'l':  'n',
			';':  's',
			'\'': '-',

			'z': ';',
			'x': 'q',
			'c': 'j',
			'v': 'k',
			'b': 'x',
			'n': 'b',
			'm': 'm',
			',': 'w',
			'.': 'v',
			'/': 'z',
		},
	}

	FWriteStructToYaml(thing)
}

DanWlker avatar Jul 17 '24 17:07 DanWlker