Skip to content

Commit

Permalink
fix layerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalBlueberry committed Dec 8, 2020
1 parent d1b726a commit 5db030a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
22 changes: 13 additions & 9 deletions cmd/chkb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package main

import (
"MetalBlueberry/cheap-keyboard/pkg/chkb"
"MetalBlueberry/cheap-keyboard/pkg/deliverers/layerFile"
"MetalBlueberry/cheap-keyboard/pkg/deliverers/vkb"
"flag"
"fmt"
"os"
"os/user"
"path/filepath"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/afero"

"github.com/bendahl/uinput"
evdev "github.com/gvalkov/golang-evdev"
Expand Down Expand Up @@ -54,16 +58,16 @@ func main() {
}
kb := chkb.NewKeyboard(book, "base")

// usr, err := user.Current()
// if err != nil {
// log.Fatal(err)
// }
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}

// lf, err := layerFile.NewLayerFile(afero.NewOsFs(), kb.Mapper, filepath.Join(usr.HomeDir, ".chkb_layout"))
// if err != nil {
// log.Fatal(err)
// }
// kb.AddDeliverer(lf)
lf, err := layerFile.NewLayerFile(afero.NewOsFs(), kb, filepath.Join(usr.HomeDir, ".chkb_layout"))
if err != nil {
log.Fatal(err)
}
kb.AddDeliverer(lf)

defer dev.Release()
err = dev.Grab()
Expand Down
12 changes: 6 additions & 6 deletions pkg/deliverers/layerFile/layerFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

type LayerFile struct {
mapper *chkb.Mapper
mapper *chkb.Keyboard

afero.File
}

func NewLayerFile(fs afero.Fs, kb *chkb.Mapper, fileName string) (*LayerFile, error) {
func NewLayerFile(fs afero.Fs, kb *chkb.Keyboard, fileName string) (*LayerFile, error) {
lf := &LayerFile{
mapper: kb,
}
Expand All @@ -39,11 +39,11 @@ func (lf *LayerFile) Deliver(event chkb.MapEvent) (handled bool, err error) {
return false, nil
}

func layerString(kb *chkb.Mapper) string {
func layerString(kb *chkb.Keyboard) string {
builder := strings.Builder{}
for i := range kb.Layers {
for name := range kb.LayerBook {
if kb.Layers[i] == kb.LayerBook[name] {
for i := range kb.Mapper.Layers {
for name := range kb.Config.Layers {
if kb.Mapper.Layers[i] == kb.Config.Layers[name] {
builder.WriteString(name)
builder.WriteString(" > ")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/deliverers/layerFile/layerFile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestLayerFile_Deliver(t *testing.T) {
},
fields: fields{
File: func() *LayerFile {
f, err := NewLayerFile(mfs, chkb.NewMapper(book, "l0"), "file")
f, err := NewLayerFile(mfs, chkb.NewKeyboard(book, "l0"), "file")
if err != nil {
panic(err)
}
Expand All @@ -64,7 +64,7 @@ func TestLayerFile_Deliver(t *testing.T) {
},
fields: fields{
File: func() *LayerFile {
f, err := NewLayerFile(mfs, chkb.NewMapper(book, "l0"), "file")
f, err := NewLayerFile(mfs, chkb.NewKeyboard(book, "l0"), "file")
if err != nil {
panic(err)
}
Expand All @@ -87,7 +87,7 @@ func TestLayerFile_Deliver(t *testing.T) {
},
fields: fields{
File: func() *LayerFile {
f, err := NewLayerFile(mfs, chkb.NewMapper(book, "l0"), "file")
f, err := NewLayerFile(mfs, chkb.NewKeyboard(book, "l0"), "file")
if err != nil {
panic(err)
}
Expand All @@ -110,7 +110,7 @@ func TestLayerFile_Deliver(t *testing.T) {
},
fields: fields{
File: func() *LayerFile {
f, err := NewLayerFile(mfs, chkb.NewMapper(book, "l0"), "file")
f, err := NewLayerFile(mfs, chkb.NewKeyboard(book, "l0"), "file")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 5db030a

Please sign in to comment.