Skip to content

Commit e1cd821

Browse files
madsmtmpyfisch
authored andcommitted
Add #[doc(alias = ...)] attributes
For certain keys and codes where it makes sense, including those we already have alternatives for when parsing.
1 parent 7ca56e7 commit e1cd821

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

convert.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,60 @@ def parse(text):
4646

4747
comment = re.sub(r"[ \t][ \t]+", "\n", typical_usage.decode_contents())
4848

49-
display.append([name, comment, deprecated, []])
49+
display.append([name, comment, deprecated, [], []])
5050
return display
5151

5252

5353
def emit_enum_entries(display, file):
54-
for [key, doc_comment, deprecated, alternatives] in display:
54+
for [key, doc_comment, deprecated, alternatives, aliases] in display:
5555
for line in doc_comment.split('\n'):
5656
line = line.strip()
5757
if len(line) == 0:
5858
continue
5959
print(f" /// {line}", file=file)
6060
if deprecated:
6161
print(" #[deprecated = \"marked as legacy in the spec, use Meta instead\"]", file=file)
62+
for alias in aliases:
63+
print(f" #[doc(alias = \"{alias}\")]", file=file)
6264
print(f" {key},", file=file)
6365

6466

6567
def print_display_entries(display, file):
66-
for [key, doc_comment, deprecated, alternatives] in display:
68+
for [key, doc_comment, deprecated, alternatives, aliases] in display:
6769
print(" {0} => f.write_str(\"{0}\"),".format(
6870
key), file=file)
6971

7072

7173
def print_from_str_entries(display, file):
72-
for [key, doc_comment, deprecated, alternatives] in display:
74+
for [key, doc_comment, deprecated, alternatives, aliases] in display:
7375
print(" \"{0}\"".format(key), file=file, end='')
7476
for alternative in alternatives:
7577
print(" | \"{0}\"".format(alternative), file=file, end='')
7678
print(" => Ok({0}),".format(key), file=file)
7779

7880

7981
def add_comment_to(display, key, comment):
80-
for (i, [found_key, doc_comment, deprecated, alternatives]) in enumerate(display):
82+
for (i, [found_key, doc_comment, deprecated, alternatives, aliases]) in enumerate(display):
8183
if found_key != key:
8284
continue
8385
doc_comment = doc_comment + "\n" + comment
84-
display[i] = [found_key, doc_comment, deprecated, alternatives]
86+
display[i] = [found_key, doc_comment, deprecated, alternatives, aliases]
87+
88+
89+
def add_alias_for(display, key, alias):
90+
for [found_key, doc_comment, deprecated, alternatives, aliases] in display:
91+
if found_key != key:
92+
continue
93+
aliases.append(alias)
8594

8695

8796
def add_alternative_for(display, key, alternative):
88-
for [found_key, doc_comment, deprecated, alternatives] in display:
97+
for [found_key, doc_comment, deprecated, alternatives, aliases] in display:
8998
if found_key != key:
9099
continue
91100
alternatives.append(alternative)
101+
# Alternatives are also listed as aliases
102+
aliases.append(alternative)
92103

93104

94105
def convert_key(text, file):
@@ -118,11 +129,15 @@ def convert_key(text, file):
118129
'F{}'.format(i),
119130
'The F{0} key, a general purpose function key, as index {0}.'.format(i),
120131
False,
121-
[]
132+
[],
133+
[],
122134
])
123135

124136
add_comment_to(display, 'Meta', 'In Linux (XKB) terminology, this is often referred to as "Super".')
125137

138+
add_alias_for(display, 'Meta', 'Super')
139+
add_alias_for(display, 'Enter', 'Return')
140+
126141
emit_enum_entries(display, file)
127142
print("}", file=file)
128143

@@ -196,7 +211,8 @@ def convert_code(text, file):
196211
'F{}'.format(i),
197212
'<kbd>F{}</kbd>'.format(i),
198213
False,
199-
[]
214+
[],
215+
[],
200216
])
201217

202218
chromium_key_codes = [
@@ -228,14 +244,22 @@ def convert_code(text, file):
228244
chromium_only,
229245
'Non-standard code value supported by Chromium.',
230246
False,
231-
[]
247+
[],
248+
[],
232249
])
233250

234251
add_comment_to(display, 'Backquote', 'This is also called a backtick or grave.')
235252
add_comment_to(display, 'Quote', 'This is also called an apostrophe.')
236253
add_comment_to(display, 'MetaLeft', 'In Linux (XKB) terminology, this is often referred to as the left "Super".')
237254
add_comment_to(display, 'MetaRight', 'In Linux (XKB) terminology, this is often referred to as the right "Super".')
238255

256+
add_alias_for(display, 'Backquote', 'Backtick')
257+
add_alias_for(display, 'Backquote', 'Grave')
258+
add_alias_for(display, 'Quote', 'Apostrophe')
259+
add_alias_for(display, 'MetaLeft', 'SuperLeft')
260+
add_alias_for(display, 'MetaRight', 'SuperRight')
261+
add_alias_for(display, 'Enter', 'Return')
262+
239263
add_alternative_for(display, 'MetaLeft', 'OSLeft')
240264
add_alternative_for(display, 'MetaRight', 'OSRight')
241265
add_alternative_for(display, 'AudioVolumeDown', 'VolumeDown')

src/code.rs

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use std::error::Error;
2323
pub enum Code {
2424
/// <kbd>`~</kbd> on a US keyboard. This is the <kbd>半角/全角/漢字</kbd> (<span class="unicode">hankaku/zenkaku/kanji</span>) key on Japanese keyboards
2525
/// This is also called a backtick or grave.
26+
#[doc(alias = "Backtick")]
27+
#[doc(alias = "Grave")]
2628
Backquote,
2729
/// Used for both the US <kbd>\|</kbd> (on the 101-key layout) and also for the key
2830
/// located between the <kbd>"</kbd> and <kbd>Enter</kbd> keys on row C of the 102-,
@@ -131,6 +133,7 @@ pub enum Code {
131133
Period,
132134
/// <kbd>'"</kbd> on a US keyboard.
133135
/// This is also called an apostrophe.
136+
#[doc(alias = "Apostrophe")]
134137
Quote,
135138
/// <kbd>;:</kbd> on a US keyboard.
136139
Semicolon,
@@ -153,12 +156,17 @@ pub enum Code {
153156
/// <kbd>Control</kbd> or <kbd>⌃</kbd>
154157
ControlRight,
155158
/// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labelled <kbd>Return</kbd> on Apple keyboards.
159+
#[doc(alias = "Return")]
156160
Enter,
157161
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd> or other OS symbol key.
158162
/// In Linux (XKB) terminology, this is often referred to as the left "Super".
163+
#[doc(alias = "SuperLeft")]
164+
#[doc(alias = "OSLeft")]
159165
MetaLeft,
160166
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd> or other OS symbol key.
161167
/// In Linux (XKB) terminology, this is often referred to as the right "Super".
168+
#[doc(alias = "SuperRight")]
169+
#[doc(alias = "OSRight")]
162170
MetaRight,
163171
/// <kbd>Shift</kbd> or <kbd>⇧</kbd>
164172
ShiftLeft,
@@ -313,6 +321,7 @@ pub enum Code {
313321
LaunchApp2,
314322
LaunchMail,
315323
MediaPlayPause,
324+
#[doc(alias = "LaunchMediaPlayer")]
316325
MediaSelect,
317326
MediaStop,
318327
MediaTrackNext,
@@ -321,8 +330,11 @@ pub enum Code {
321330
/// replacing the <kbd>Eject</kbd> key.
322331
Power,
323332
Sleep,
333+
#[doc(alias = "VolumeDown")]
324334
AudioVolumeDown,
335+
#[doc(alias = "VolumeMute")]
325336
AudioVolumeMute,
337+
#[doc(alias = "VolumeUp")]
326338
AudioVolumeUp,
327339
WakeUp,
328340
#[deprecated = "marked as legacy in the spec, use Meta instead"]

src/named_key.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub enum NamedKey {
4242
/// The <kbd>Meta</kbd> key, to enable meta modifier function for interpreting concurrent or subsequent keyboard input.
4343
/// This key value is used for the <q>Windows Logo</q> key and the Apple <kbd>Command</kbd> or <kbd>⌘</kbd> key.
4444
/// In Linux (XKB) terminology, this is often referred to as "Super".
45+
#[doc(alias = "Super")]
4546
Meta,
4647
/// The <kbd>NumLock</kbd> or Number Lock key, to toggle numpad mode function for interpreting subsequent keyboard input.
4748
NumLock,
@@ -60,6 +61,7 @@ pub enum NamedKey {
6061
#[deprecated = "marked as legacy in the spec, use Meta instead"]
6162
Super,
6263
/// The <kbd>Enter</kbd> or <kbd>↵</kbd> key, to activate current selection or accept current input.<br/> This key value is also used for the <kbd>Return</kbd> (Macintosh numpad) key.<br/> This key value is also used for the Android <code class="android">KEYCODE_DPAD_CENTER</code>.
64+
#[doc(alias = "Return")]
6365
Enter,
6466
/// The Horizontal Tabulation <kbd>Tab</kbd> key.
6567
Tab,

0 commit comments

Comments
 (0)