Skip to content

Commit

Permalink
Add --layout option (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
yskoht authored Dec 30, 2021
1 parent 23efd74 commit 9e67351
Show file tree
Hide file tree
Showing 37 changed files with 154 additions and 80 deletions.
23 changes: 17 additions & 6 deletions keymapviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@


class Keymapviz():
def __init__(self, keyboard, keymap_c, legends = None):
def __init__(self, keyboard, keymap_c, layout = None, legends = None):
self.__keymap_c = keymap_c.read()
self.keyboard = KEYBOARDS[keyboard]
self.keymaps = self.__parse_keymap_c()
self.layout = layout if layout else 'default'
self.legends = legends if legends else {}


Expand Down Expand Up @@ -108,13 +109,22 @@ def __get_final_ascii_art(self, ascii_art):
self.__ascii_art = [aa.format(*self.__legends(_)) for _ in self.keymaps]
return self.__ascii_art

def ascii_art(self):
return self.__get_final_ascii_art(self.keyboard.ascii_art)

def __get_layout(self, format, layout):
try:
return format[layout]
except KeyError:
print('The keyboard dose not have the layout `{}`.'.format(layout), file=sys.stderr)
sys.exit(1)

def ascii_art(self):
aa = self.__get_layout(self.keyboard.ascii_art, self.layout)
return self.__get_final_ascii_art(aa)

def layout_editor_json(self):
path_ = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path_, self.keyboard.layout_editor_json)) as f:
json_file = self.__get_layout(self.keyboard.layout_editor_json, self.layout)
with open(os.path.join(path_, json_file)) as f:
json_ = json.load(f)
return [self.__json_format(json_, _) for _ in self.keymaps]

Expand Down Expand Up @@ -153,8 +163,9 @@ def __get_box_drawing(self, left, down, up, right, center):
def fancy_art(self):
if hasattr(self.keyboard, 'fancy_ascii_art'):
# There already exists a man-made fancy ascii art for this keyboard.
return self.__get_final_ascii_art(self.keyboard.fancy_ascii_art)
aa = self.keyboard.ascii_art
faa = self.__get_layout(self.keyboard.fancy_ascii_art, self.layout)
return self.__get_final_ascii_art(faa)
aa = self.__get_layout(self.keyboard.ascii_art, self.layout)
keymapviz_signature_pattern = r'[A-Za-z ]*\[keymapviz\].*\*/\s*$'
# If the keymapviz signature is adjacent to certain outline characters,
# self.__get_box_drawing will incorrectly interpret the characters composing the signature
Expand Down
11 changes: 7 additions & 4 deletions keymapviz/keyboards/crkbd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT|LAYOUT_kc|LAYOUT_split_3x6_3)'
layout_editor_json = 'keyboards/crkbd/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/crkbd/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -14,5 +17,5 @@
* |{ }|{ }|{ }| |{ }|{ }|{ }|
* `--------------------' `--------------------'
* generated by [keymapviz] */
'''

''',
}
16 changes: 11 additions & 5 deletions keymapviz/keyboards/dactyl_manuform5x6/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:KEYMAP|LAYOUT_5x6)'
layout_editor_json = 'keyboards/dactyl_manuform5x6/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/dactyl_manuform5x6/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-------------------------------. ,-------------------------------.
* ,---------------|{ 2 }|{ 3 }|{ 4 }|{ 5 }| |{ 6 }|{ 7 }|{ 8 }|{ 9 }|--------------.
* |{ 0 }|{ 1 }|-------+-------+-------+-------| |-------+-------+-------+-------|{ 10 }|{ 11 }|
Expand All @@ -22,9 +25,11 @@
* |-------+-------| |-------+-------|
* |{ 60 }|{ 61 }| |{ 62 }|{ 63 }|
* `---------------' `---------------' generated by [keymapviz] */
'''
''',
}

fancy_ascii_art = '''
fancy_ascii_art = {
'default': '''
/* ┌───────┬───────┬───────┬───────┐ ┌───────┬───────┬───────┬───────┐
* ┌───────┬───────┤{ 2 }│{ 3 }│{ 4 }│{ 5 }│ │{ 6 }│{ 7 }│{ 8 }│{ 9 }├───────┬──────┐
* │{ 0 }│{ 1 }├───────┼───────┼───────┼───────┤ ├───────┼───────┼───────┼───────┤{ 10 }│{ 11 }│
Expand All @@ -43,4 +48,5 @@
* ├───────╄━━━━━━━┩ ┡━━━━━━━╃───────┤
* │{ 60 }│{ 61 }│ │{ 62 }│{ 63 }│
* └───────┴───────┘ └───────┴───────┘ generated by [keymapviz] */
'''
''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/ergo42/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/ergo42/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/ergo42/layout_editor/default.json'
}

ascii_art = '''
ascii_art = {
'default': '''
/*
* ,------------------------------------------------. ,------------------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|{ }|
Expand All @@ -16,5 +19,5 @@
* | | | | | | | | | | | | | | | |
* `------------------------------------------------' `------------------------------------------------'
* generated by [keymapviz] */
'''

''',
}
15 changes: 9 additions & 6 deletions keymapviz/keyboards/ergodash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/ergodash/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/ergodash/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------------. ,-----------------------------------------------.
* |{ 0 }|{ 1 }|{ 2 }|{ 3 }|{ 4 }|{ 5 }|-------. ,-------|{ 8 }|{ 9 }|{ 10 }|{ 11 }|{ 12 }|{ 13 }|
* |-------+-------+-------+-------+-------+-------|{ 6 }| |{ 7 }|-------+-------+-------+-------+-------+-------|
Expand All @@ -15,9 +18,9 @@
* |-------+-------+-------+-------+---------------' `---------------+-------+-------+-------+-------|
* |{ 56 }|{ 57 }|{ 58 }|{ 59 }| ,---------------. ,---------------. |{ 66 }|{ 67 }|{ 68 }|{ 69 }|
* `-------------------------------' |{ 48 }| | | |{ 49 }| ,-------------------------------'
* ,-------+-------|{ 62 }| |{ 63 }|-------+-------.
* |{ 60 }|{ 61 }| | | |{ 64 }|{ 65 }|
* ,-------+-------|{ 62 }| |{ 63 }|-------+-------.
* |{ 60 }|{ 61 }| | | |{ 64 }|{ 65 }|
* `-----------------------' `-----------------------'
* generated by [keymapviz] */
'''

''',
}
14 changes: 9 additions & 5 deletions keymapviz/keyboards/ergodash_2u_inner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:KEYMAP|LAYOUT_4key_2u_inner)'
layout_editor_json = 'keyboards/ergodash_2u_inner/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/ergodash_2u_inner/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------------. ,-----------------------------------------------.
* |{ 0 }|{ 1 }|{ 2 }|{ 3 }|{ 4 }|{ 5 }|-------. ,-------|{ 8 }|{ 9 }|{ 10 }|{ 11 }|{ 12 }|{ 13 }|
* |-------+-------+-------+-------+-------+-------|{ 6 }| |{ 7 }|-------+-------+-------+-------+-------+-------|
Expand All @@ -15,8 +18,9 @@
* |-------+-------+-------+-------+---------------' `---------------+-------+-------+-------+-------|
* |{ 56 }|{ 57 }|{ 58 }|{ 59 }| ,---------------. ,---------------. |{ 66 }|{ 67 }|{ 68 }|{ 69 }|
* `-------------------------------' | |{ 48 }| |{ 49 }| | ,-------------------------------'
* ,-------|{ 61 }|-------| |-------|{ 64 }|-------.
* |{ 60 }| |{ 62 }| |{ 63 }| |{ 65 }|
* ,-------|{ 61 }|-------| |-------|{ 64 }|-------.
* |{ 60 }| |{ 62 }| |{ 63 }| |{ 65 }|
* `-----------------------' `-----------------------'
* generated by [keymapviz] */
'''
''',
}
10 changes: 7 additions & 3 deletions keymapviz/keyboards/ergodox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT_ergodox|KEYMAP|KEYMAP_80|LAYOUT_ergodox_pretty|KEYMAP_TKG)'
layout_editor_json = 'keyboards/ergodox/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/ergodox/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* .---------------------------------------------. .---------------------------------------------.
* |{0 }|{1 }|{2 }|{3 }|{4 }|{5 }|{6 }| !{7 }|{8 }|{9 }|{10 }|{11 }|{12 }|{13 }|
* !-------+-----+-----+-----+-----+-------------! !-------+-----+-----+-----+-----+-----+-------!
Expand All @@ -23,4 +26,5 @@
* | | |{72 }| !{73 }| | |
* '-----------------------' '-----------------------'
* generated by [keymapviz] */
'''
''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/fortitude60/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/fortitude60/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/fortitude60/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -16,5 +19,5 @@
* |{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|
* `----------------------------------' `----------------------------------'
* generated by [keymapviz] */
'''

''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/helix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:KEYMAP|LAYOUT)'
layout_editor_json = 'keyboards/helix/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/helix/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -16,5 +19,5 @@
* |{ }|{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|{ }|
* `------------------------------------------------' `------------------------------------------------'
* generated by [keymapviz] */
'''

''',
}
12 changes: 8 additions & 4 deletions keymapviz/keyboards/kaishi65/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
keymap_keyword = '(?:LAYOUT_65_ansi)'
layout_editor_json = 'keyboards/kaishi65/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/kaishi65/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/*,----------------------------------------------------------------.
*|{} | {}| {}| {}| {}| {}| {}| {}| {}| {}| {}| {}| {}| {} | {} |
*|----------------------------------------------------------------|
Expand All @@ -12,7 +15,8 @@
*| {} | {}| {}| {}| {}| {}| {}| {}| {}| {}| {}| {} | {}| {} |
*|----------------------------------------------------------------|
*| {} | {} | {} | {} | {}| {}| {} | {}| {}| {} |
*`----------------------------------------------------------------'
*`----------------------------------------------------------------'
* generated by [keymapviz]
*/
'''
''',
}
10 changes: 7 additions & 3 deletions keymapviz/keyboards/kinesis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/kinesis/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/kinesis/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,---------------------------------------------------------------------------------------------------------------------------------.
* |{0 } |{1 }|{2 }|{3 }|{4 }|{5 }|{6 }|{7 }|{8 }|{43 }|{44 }|{45 }|{46 }|{47 }|{48 }|{49 }|{50 }|{51 } |
* |--------+------+------+------+------+------+-----------------------------------------+------+------+------+------+------+--------|
Expand All @@ -25,4 +28,5 @@
* | | |{42 }| |{85 }| | |
* `--------------------' `--------------------'
* generated by [keymapviz] */
'''
''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/kyria/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/kyria/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/kyria/layout_editor/default.json'
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -15,5 +18,5 @@
* | | | | | | | | | | | |
* `----------------------------------' `----------------------------------'
* generated by [keymapviz] */
'''

''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/lets_split/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:KEYMAP|LAYOUT|LAYOUT_ortho_4x12)'
layout_editor_json = 'keyboards/lets_split/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/lets_split/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -14,5 +17,5 @@
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* `-----------------------------------------' `-----------------------------------------'
* generated by [keymapviz] */
'''

''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/lily58/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/lily58/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/lily58/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/* ,-----------------------------------------. ,-----------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* |------+------+------+------+------+------| |------+------+------+------+------+------|
Expand All @@ -17,5 +20,5 @@
* | | | |/ / \ \ | | | |
* `----------------------------' '-------''--------------------'
* generated by [keymapviz] */
'''

''',
}
11 changes: 7 additions & 4 deletions keymapviz/keyboards/mint60/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-

keymap_keyword = '(?:LAYOUT)'
layout_editor_json = 'keyboards/mint60/layout_editor.json'
layout_editor_json = {
'default': 'keyboards/mint60/layout_editor/default.json',
}

ascii_art = '''
ascii_art = {
'default': '''
/*
* ,-----------------------------------------. --------------------------------------------------------.
* |{ }|{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|{ }|{ }|
Expand All @@ -17,5 +20,5 @@
* |{ }|{ }|{ }|{ }|{ }| |{ }|{ }|{ }|{ }|{ }|{ }|
* `-----------------------------------------' `-------------------------------------------------------'
* generated by [keymapviz] */
'''

''',
}
Loading

0 comments on commit 9e67351

Please sign in to comment.