-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from semilin/v1.2.0
V1.2.0
- Loading branch information
Showing
19 changed files
with
675 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/hjson/hjson-go" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
func ReadWeights() { | ||
b, err := ioutil.ReadFile("weights.hjson") | ||
func fileExists(path string) bool { | ||
if _, err := os.Stat(path); err == nil { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func findConfig() string { | ||
if fileExists("./config.toml") { | ||
return "config.toml" | ||
} | ||
config_dir := os.Getenv("XDG_CONFIG_DIR") | ||
path := filepath.Join(config_dir, "genkey", "config.toml") | ||
if fileExists(path) { | ||
return path | ||
} | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
fmt.Printf("There was an issue reading the weights file.\nPlease make sure there is a 'weights.json' in this directory.") | ||
panic(err) | ||
} | ||
path = filepath.Join(home, ".config", "genkey", "config.toml") | ||
if fileExists(path) { | ||
return path | ||
} | ||
|
||
var dat map[string]interface{} | ||
println("Couldn't find config.toml in any of local directory, $XDG_CONFIG_DIR/genkey/config.toml, or ~/.config/genkey/config.toml.") | ||
os.Exit(1) | ||
return "" | ||
} | ||
|
||
err = hjson.Unmarshal(b, &dat) | ||
func ReadWeights() { | ||
path := findConfig() | ||
b, err := os.ReadFile(path) | ||
if err != nil { | ||
fmt.Printf("There was an issue reading the config file.") | ||
panic(err) | ||
} | ||
|
||
_, err = toml.Decode(string(b), &Config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
j, _ := json.Marshal(dat) | ||
json.Unmarshal(j, &Weight) | ||
if !fileExists(filepath.Join(Config.Paths.Corpora, Config.Corpus) + ".json") { | ||
fmt.Printf("Invalid config: Corpus [%s] does not exist.\n", Config.Corpus) | ||
os.Exit(1) | ||
} | ||
|
||
if Config.Generation.Selection > Config.Generation.InitialPopulation { | ||
fmt.Println("Invalid config: Generation.Selection cannot be greater than Generation.InitialPopulation.") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
Corpus = "shai-iweb" | ||
|
||
[Output] | ||
# Enables heatmap output after layout generation. | ||
Generation.Heatmap = true | ||
|
||
# Char to fill the space in the rank display. | ||
Rank.Spacer = ' ' | ||
|
||
# The number of most frequent ngrams to display in `genkey analysis`. | ||
Analysis.TopNgrams = 8 | ||
|
||
# The number of most frequent ngrams to display by default in commands | ||
# like `genkey sfbs`. | ||
Misc.TopNgrams = 20 | ||
|
||
[Paths] | ||
# The paths that genkey should operate using. Useful if running genkey | ||
# as a standalone executable rather than using a dedicated directory. | ||
|
||
Layouts = "./layouts" | ||
Corpora = "./corpora" | ||
Heatmap = "./heatmap.png" | ||
|
||
[Weights] | ||
Dist.Lateral = 1.4 # Lateral movement multiplier | ||
|
||
# Set to true to measure distances for row-stagger keyboard. | ||
# Otherwise measures based on ortholinear distances. | ||
# Can be overriden using the -stagger flag. | ||
Stagger = false | ||
|
||
[Weights.Fspeed] | ||
SFB = 1.0 # Weight of sfbs | ||
DSFB = 0.5 # Weight of dsfbs | ||
KeyTravel = 0.01 # How much baseline distance there is per keypress | ||
|
||
# Keys per second, or how dexterous each finger is | ||
KPS = [ | ||
1.5, # lp | ||
3.6, # lr | ||
4.8, # lm | ||
5.5, # li | ||
5.5, # ri | ||
4.8, # rm | ||
3.6, # rr | ||
1.5, # rp | ||
] | ||
|
||
[Weights.Score] | ||
Fspeed = 3 # Weight of fspeed | ||
IndexBalance = 0.3 # Weight of difference in usage between index fingers | ||
Lsb = 1 # Weight of lsb frequency | ||
|
||
[Weights.Score.Trigrams] | ||
# No trigrams will be calculated if enabled = false | ||
Enabled = false | ||
|
||
# Number of most frequent trigrams to analyze. | ||
# Set to 0 to analyze all trigrams (will slow down analysis a lot). | ||
Precision = 100 | ||
|
||
LeftInwardRoll = 0 | ||
LeftOutwardRoll = 0 | ||
RightInwardRoll = 0 | ||
RightOutwardRoll = 0 | ||
|
||
Alternate = 0 | ||
Redirect = 0 | ||
Onehand = 0 | ||
|
||
[Generation] | ||
# The characters that generated layouts will consist of. | ||
GeneratedLayoutChars = "abcdefghijklmnopqrstuvwxyz,./'" | ||
# The number of random layouts to be optimized at start of generation. | ||
InitialPopulation = 1000 | ||
# The number of best layouts out of the initial population to run full | ||
# improvement on. Must be less than InitialPopulation. | ||
Selection = 100 | ||
|
||
[CorpusProcessing] | ||
# Describes how to process new corpora with `genkey load`. Doesn't | ||
# apply to already processed corpora. | ||
|
||
# The chars which are allowed to be included in ngrams. | ||
ValidChars = "abcdefghijklmnopqrstuvwxyz,./?;:-_'\"" | ||
# Shift pairs which are to be treated as the same character. | ||
CharSubstitutions = [["?", "/"], | ||
[":", ";"], | ||
["_", "-"], | ||
["\"", "'"]] | ||
# The largest size of skipgram to be used for DSFB calculation. | ||
MaxSkipgramSize = 10 | ||
# Set to false to include skipgrams which skip over chars not in ValidChars. | ||
SkipgramsMustSpanValidChars = true |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
module github.com/semilin/genkey | ||
|
||
go 1.16 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/buger/goterm v1.0.1 | ||
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807 | ||
github.com/BurntSushi/toml v1.3.2 | ||
github.com/buger/goterm v1.0.4 | ||
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 | ||
github.com/fogleman/gg v1.3.0 | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect | ||
github.com/hjson/hjson-go v3.1.0+incompatible | ||
github.com/wayneashleyberry/truecolor v1.0.1 | ||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect | ||
golang.org/x/image v0.15.0 // indirect | ||
golang.org/x/sys v0.17.0 // indirect | ||
) |
Oops, something went wrong.