Commit fa8b3168 authored by Sli's avatar Sli

Minimal support for AZERTY, usable for UIDs

parent db59f96f
Pipeline #1756 failed with stages
......@@ -42,6 +42,7 @@ There are options for application that should be specified as flags.
- '-reverse' (boolean) - UID output in reverse order
- '-end-char' (string) - character at the end of UID. Options: 'hyphen', 'enter', 'semicolon', 'colon', 'comma', 'none', 'space', 'tab', (default "none")
- '-in-char' (string) - character between bytes of UID. Options: 'hyphen', 'enter', 'semicolon', 'colon', 'comma', 'none', 'space', 'tab', (default "none")
- '-layout' (string) - layout of the keyboard. Options: 'en', 'fr', (default 'en')
Run with '-h' flag to check usage
```
......
......@@ -11,6 +11,8 @@ const (
CharFlagSemiColon
CharFlagColon
CharFlagComma
LayoutFlagEN
LayoutFlagFR
)
type CharFlagDef struct {
......@@ -18,6 +20,11 @@ type CharFlagDef struct {
output string
}
var layoutFlagStrings = map[CharFlag]CharFlagDef{
LayoutFlagEN: CharFlagDef{"en", "en"},
LayoutFlagFR: CharFlagDef{"fr", "fr"},
}
var charFlagStrings = map[CharFlag]CharFlagDef{
CharFlagNone: CharFlagDef{"none", ""},
CharFlagSpace: CharFlagDef{"space", " "},
......@@ -29,6 +36,15 @@ var charFlagStrings = map[CharFlag]CharFlagDef{
CharFlagComma: CharFlagDef{"comma", ","},
}
func StringToLayoutFlag(s string) (string, bool) {
for _, v := range layoutFlagStrings {
if v.name == s {
return v.name, true
}
}
return "", false
}
func StringToCharFlag(s string) (CharFlag, bool) {
for k, v := range charFlagStrings {
if v.name == s {
......@@ -46,10 +62,18 @@ func (charFlag CharFlag) Output() string {
return charFlagStrings[charFlag].output
}
func CharFlagOptions() string {
func flagOptions(flags map[CharFlag]CharFlagDef) string {
var s string
for _, v := range charFlagStrings {
for _, v := range flags {
s = s + "'" + v.name + "', "
}
return s
}
func LayoutFlagOptions() string {
return flagOptions(layoutFlagStrings)
}
func CharFlagOptions() string {
return flagOptions(charFlagStrings)
}
......@@ -7,11 +7,12 @@ import (
func main() {
var appFlags Flags
var endChar, inChar string
var endChar, inChar, layout string
var ok bool
//Read application flags
flag.StringVar(&endChar, "end-char", "none", "Character at the end of UID. Options: "+CharFlagOptions())
flag.StringVar(&inChar, "in-char", "none", "Сharacter between bytes of UID. Options: "+CharFlagOptions())
flag.StringVar(&layout, "layout", "en", "Keyboard layout to use. Options: "+LayoutFlagOptions())
flag.BoolVar(&appFlags.CapsLock, "caps-lock", false, "UID with Caps Lock")
flag.BoolVar(&appFlags.Reverse, "reverse", false, "UID reverse order")
flag.BoolVar(&appFlags.Decimal, "decimal", false, "UID in decimal format")
......@@ -29,6 +30,11 @@ func main() {
errorExit(errors.New("Unknown in character flag. Run with '-h' flag to check options"))
return
}
appFlags.Layout, ok = StringToLayoutFlag(layout)
if !ok {
errorExit(errors.New("Unknown in character flag. Run with '-h' flag to check options"))
return
}
service := NewService(appFlags)
service.Start()
......
......@@ -10,8 +10,8 @@ import (
"strconv"
"strings"
"ae-dev.utbm.fr/sli/string2keyboard"
"github.com/ebfe/scard"
"github.com/taglme/string2keyboard"
)
type Service interface {
......@@ -29,6 +29,7 @@ type Flags struct {
Decimal bool
EndChar CharFlag
InChar CharFlag
Layout string
Device int
}
......@@ -140,7 +141,7 @@ func (s *service) Start() {
uidBytes := rsp[0 : len(rsp)-2]
fmt.Printf("UID is: % x\n", uidBytes)
fmt.Printf("Writting as keyboard input...")
err = string2keyboard.KeyboardWrite(s.formatOutput(uidBytes))
err = string2keyboard.KeyboardWrite(s.formatOutput(uidBytes), s.flags.Layout)
if err != nil {
fmt.Printf("Could write as keyboard output. Error: %s\n", err.Error())
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment