keyremac 0.0.1 → 0.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.md +100 -0
- data/README.md +83 -15
- data/keyremac.gemspec +0 -1
- data/lib/keyremac.rb +1 -0
- data/lib/keyremac/base.rb +41 -36
- data/lib/keyremac/constants.rb +49 -0
- data/lib/keyremac/dump.rb +19 -15
- data/lib/keyremac/key.rb +16 -57
- data/lib/keyremac/version.rb +1 -1
- data/samples/sample.rb +11 -1
- data/spec/dump_spec.rb +92 -95
- data/spec/keyremac_spec.rb +95 -97
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e396e7b7adb1000fc741d5c0e9523d4f85c2770c
|
4
|
+
data.tar.gz: 8a6a3dbc853f7e6e6610dd5aa83845f0b24d25a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b2966dc0dc2d735ff6dbeb17870c24464503493872d02a09278b15ada32812fa8703df1c2239f3d0d6c3f678ce330e1add475fb64bdce5a5aaedd57e892255
|
7
|
+
data.tar.gz: c08e1f5d867974e8f11cdea777aad2b7051884da4b3b999c1258f1f7d5029f6bf717b8a0c2eb2f6769add8f4f3718852f0e5530424f9cd44642b11a5f52da700
|
data/README.ja.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Keyremac
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/keqh/keyremac.png?branch=master)](https://travis-ci.org/keqh/keyremac)
|
4
|
+
|
5
|
+
*Keyremac*はRubyでKeyRemap4MacBookの設定を行うgemです。
|
6
|
+
- 大量のcheckboxを扱うのが苦手な方や
|
7
|
+
- XMLを手で編集するのが好きではない方向けに
|
8
|
+
KeyRemap4MacBookの設定を行うDSLを提供します。
|
9
|
+
|
10
|
+
## dependency
|
11
|
+
|
12
|
+
- KeyRemap4MacBook v7.0.0+
|
13
|
+
- https://pqrs.org/macosx/keyremap4macbook/
|
14
|
+
- ruby v2.0.0+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
$ gem install keyremac --source http://github.com/keqh/keyremac/raw/master
|
19
|
+
|
20
|
+
## Getting Started
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ cat > private.rb
|
24
|
+
require 'keyremac'
|
25
|
+
:SPACE .to :TAB
|
26
|
+
|
27
|
+
$ ruby private.rb --dump
|
28
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
29
|
+
<root>
|
30
|
+
<item>
|
31
|
+
<name>root_item</name>
|
32
|
+
<identifier>private.root_item</identifier>
|
33
|
+
<autogen>__KeyToKey__ KeyCode::SPACE, KeyCode::TAB</autogen>
|
34
|
+
<autogen>__KeyToKey__ KeyCode::TAB, KeyCode::SPACE</autogen>
|
35
|
+
<autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::ESCAPE</autogen>
|
36
|
+
</item>
|
37
|
+
</root>
|
38
|
+
|
39
|
+
$ ruby private.rb --reload
|
40
|
+
```
|
41
|
+
|
42
|
+
## Examples
|
43
|
+
|
44
|
+
### simple KeyToKey
|
45
|
+
|
46
|
+
```rb
|
47
|
+
:SPACE .to :TAB
|
48
|
+
```
|
49
|
+
|
50
|
+
### mods (cmd, ctrl, opt, shift, none)
|
51
|
+
|
52
|
+
```rb
|
53
|
+
:m.cmd .to :VK_NONE
|
54
|
+
:j.ctrl .to :JIS_KANA
|
55
|
+
```
|
56
|
+
|
57
|
+
### key to keys
|
58
|
+
|
59
|
+
```rb
|
60
|
+
:n.ctrl.cmd .to :JIS_EISUU, '['.cmd.shift
|
61
|
+
:p.ctrl.cmd .to :JIS_EISUU, ']'.cmd.shift
|
62
|
+
```
|
63
|
+
|
64
|
+
### app_only
|
65
|
+
|
66
|
+
```rb
|
67
|
+
app "CHROME" do
|
68
|
+
:m.cmd.none .to :VK_NONE
|
69
|
+
end
|
70
|
+
|
71
|
+
# or
|
72
|
+
|
73
|
+
item app: "CHORME" do
|
74
|
+
...
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### inputsource_only
|
79
|
+
|
80
|
+
```
|
81
|
+
item inputsource: "JAPANESE" do
|
82
|
+
:l .to :JIS_EISUU
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### raw
|
87
|
+
|
88
|
+
```
|
89
|
+
item_ do
|
90
|
+
name_ 'jis_to_us'
|
91
|
+
identifier_ 'private.jis_to_us'
|
92
|
+
autogen_ "__SetKeyboardType__ KeyboardType::MACBOOK"
|
93
|
+
:JIS_YEN .to :BACKQUOTE
|
94
|
+
:JIS_UNDERSCORE .to :BACKQUOTE
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
- more examples: https://github.com/keqh/keyremac/tree/master/samples
|
99
|
+
- and specs: https://github.com/keqh/keyremac/tree/master/spec
|
100
|
+
|
data/README.md
CHANGED
@@ -1,29 +1,97 @@
|
|
1
1
|
# Keyremac
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/keqh/keyremac.png?branch=master)](https://travis-ci.org/keqh/keyremac)
|
4
|
+
|
5
|
+
Keyremac is KeyRemap4MacBook settings generator.
|
6
|
+
|
7
|
+
## dependency
|
8
|
+
|
9
|
+
- KeyRemap4MacBook v7.0.0+
|
10
|
+
- https://pqrs.org/macosx/keyremap4macbook/
|
11
|
+
- ruby v2.0.0+
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
7
|
-
|
15
|
+
$ gem install keyremac
|
8
16
|
|
9
|
-
|
17
|
+
## Getting Started
|
10
18
|
|
11
|
-
|
19
|
+
```bash
|
20
|
+
$ cat > private.rb
|
21
|
+
require 'keyremac'
|
22
|
+
:SPACE .to :TAB
|
12
23
|
|
13
|
-
|
24
|
+
$ ruby private.rb --dump
|
25
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
<root>
|
27
|
+
<item>
|
28
|
+
<name>root_item</name>
|
29
|
+
<identifier>private.root_item</identifier>
|
30
|
+
<autogen>__KeyToKey__ KeyCode::SPACE, KeyCode::TAB</autogen>
|
31
|
+
<autogen>__KeyToKey__ KeyCode::TAB, KeyCode::SPACE</autogen>
|
32
|
+
<autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::ESCAPE</autogen>
|
33
|
+
</item>
|
34
|
+
</root>
|
14
35
|
|
15
|
-
|
36
|
+
$ ruby private.rb --reload
|
37
|
+
```
|
16
38
|
|
17
|
-
|
39
|
+
## Examples
|
40
|
+
|
41
|
+
### simple KeyToKey
|
42
|
+
|
43
|
+
```rb
|
44
|
+
:SPACE .to :TAB
|
45
|
+
```
|
46
|
+
|
47
|
+
### mods (cmd, ctrl, opt, shift, none)
|
48
|
+
|
49
|
+
```rb
|
50
|
+
:m.cmd .to :VK_NONE
|
51
|
+
:j.ctrl .to :JIS_KANA
|
52
|
+
```
|
53
|
+
|
54
|
+
### key to keys
|
55
|
+
|
56
|
+
```rb
|
57
|
+
:n.ctrl.cmd .to :JIS_EISUU, '['.cmd.shift
|
58
|
+
:p.ctrl.cmd .to :JIS_EISUU, ']'.cmd.shift
|
59
|
+
```
|
60
|
+
|
61
|
+
### app_only
|
62
|
+
|
63
|
+
```rb
|
64
|
+
app "CHROME" do
|
65
|
+
:m.cmd.none .to :VK_NONE
|
66
|
+
end
|
67
|
+
|
68
|
+
# or
|
69
|
+
|
70
|
+
item app: "CHORME" do
|
71
|
+
...
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
### inputsource_only
|
76
|
+
|
77
|
+
```
|
78
|
+
item inputsource: "JAPANESE" do
|
79
|
+
:l .to :JIS_EISUU
|
80
|
+
end
|
81
|
+
```
|
18
82
|
|
19
|
-
|
83
|
+
### raw
|
20
84
|
|
21
|
-
|
85
|
+
```
|
86
|
+
item_ do
|
87
|
+
name_ 'jis_to_us'
|
88
|
+
identifier_ 'private.jis_to_us'
|
89
|
+
autogen_ "__SetKeyboardType__ KeyboardType::MACBOOK"
|
90
|
+
:JIS_YEN .to :BACKQUOTE
|
91
|
+
:JIS_UNDERSCORE .to :BACKQUOTE
|
92
|
+
end
|
93
|
+
```
|
22
94
|
|
23
|
-
|
95
|
+
- more examples: https://github.com/keqh/keyremac/tree/master/samples
|
96
|
+
- and specs: https://github.com/keqh/keyremac/tree/master/spec
|
24
97
|
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/keyremac.gemspec
CHANGED
data/lib/keyremac.rb
CHANGED
@@ -37,6 +37,7 @@ module Keyremac
|
|
37
37
|
op.on('--dump', 'dump private.xml') { Keyremac::dump }
|
38
38
|
op.on('--reload', 'reload private.xml') { Keyremac::reload }
|
39
39
|
op.on('--ids', 'collect identifiers') { puts Keyremac::collect_identifiers }
|
40
|
+
op.on('--test', 'test') { `touch ~/test.txt` }
|
40
41
|
}.parse!(ARGV.dup)
|
41
42
|
end
|
42
43
|
end
|
data/lib/keyremac/base.rb
CHANGED
@@ -1,47 +1,45 @@
|
|
1
|
-
require 'awesome_print'
|
2
1
|
require 'builder'
|
3
2
|
|
4
3
|
require 'keyremac/key'
|
5
4
|
|
6
5
|
module Keyremac
|
7
|
-
|
8
|
-
|
6
|
+
module Focus
|
7
|
+
@@focus = []
|
9
8
|
|
10
|
-
|
9
|
+
def self.add(rule)
|
10
|
+
@@focus.last.add rule
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def self.focus
|
14
|
+
@@focus
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
yield
|
22
|
-
@@focus.pop
|
17
|
+
def self.set_focus(container, &block)
|
18
|
+
@@focus.push container
|
19
|
+
yield
|
20
|
+
@@focus.pop
|
21
|
+
end
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@repeat = repeat
|
37
|
-
end
|
24
|
+
module Autogen
|
25
|
+
class KeyToKey < Struct.new(:from, :to); end
|
26
|
+
class KeyToConsumer < Struct.new(:from, :to); end
|
27
|
+
class KeyOverlaidModifier
|
28
|
+
attr_reader :key, :mod, :keys, :repeat
|
29
|
+
def initialize(key, mod, keys: [], repeat: false)
|
30
|
+
@key = key
|
31
|
+
@mod = mod
|
32
|
+
@keys = keys == [] ? [key] : keys
|
33
|
+
@repeat = repeat
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
36
|
+
def repeat?
|
37
|
+
@repeat
|
38
|
+
end
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
# container
|
42
|
+
# @group container
|
45
43
|
# ====================================
|
46
44
|
|
47
45
|
module Container
|
@@ -56,7 +54,7 @@ module Keyremac
|
|
56
54
|
if method_name[-1] == '_'
|
57
55
|
raw = Raw.new method_name.chomp('_')
|
58
56
|
if block
|
59
|
-
Keyremac.set_focus raw do
|
57
|
+
Keyremac::Focus.set_focus raw do
|
60
58
|
raw.instance_eval(&block)
|
61
59
|
end
|
62
60
|
else
|
@@ -103,22 +101,29 @@ module Keyremac
|
|
103
101
|
|
104
102
|
def initialize
|
105
103
|
@root_item = Item.new 'root_item'
|
106
|
-
Keyremac.focus.clear
|
107
|
-
Keyremac.focus << @root_item
|
104
|
+
Keyremac::Focus.focus.clear
|
105
|
+
Keyremac::Focus.focus << @root_item
|
108
106
|
@children = []
|
109
107
|
end
|
110
108
|
|
109
|
+
# @param [String] app only tag
|
110
|
+
# @param [String] inputsource inputsource_only tag
|
111
|
+
# yield [] children
|
112
|
+
# @return [Item]
|
111
113
|
def item(app: nil, inputsource: nil, &block)
|
112
114
|
Item.new.tap { |item|
|
113
115
|
item.only_ app if app
|
114
116
|
item.inputsource_only_ inputsource if inputsource
|
115
117
|
@children << item
|
116
|
-
Keyremac.set_focus item do
|
118
|
+
Keyremac::Focus.set_focus item do
|
117
119
|
item.instance_eval(&block)
|
118
120
|
end
|
119
121
|
}
|
120
122
|
end
|
121
123
|
|
124
|
+
# @param [String] only
|
125
|
+
# @option options same as item method
|
126
|
+
# @return [Item]
|
122
127
|
def app(only, **options, &block)
|
123
128
|
options[:app] = only
|
124
129
|
item(**options, &block)
|
@@ -135,8 +140,8 @@ module Keyremac
|
|
135
140
|
@@root
|
136
141
|
end
|
137
142
|
|
138
|
-
def method_missing(
|
139
|
-
@@root.send(
|
143
|
+
def method_missing(*args, &block)
|
144
|
+
@@root.send(*args, &block)
|
140
145
|
end
|
141
146
|
end
|
142
147
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Keyremac
|
2
|
+
CONSUMER_KEYS = [
|
3
|
+
'BRIGHTNESS_DOWN',
|
4
|
+
'BRIGHTNESS_UP',
|
5
|
+
'KEYBOARDLIGHT_OFF',
|
6
|
+
'KEYBOARDLIGHT_LOW',
|
7
|
+
'KEYBOARDLIGHT_HIGH',
|
8
|
+
'MUSIC_PREV',
|
9
|
+
'MUSIC_PLAY',
|
10
|
+
'MUSIC_NEXT',
|
11
|
+
'MUSIC_PREV_18',
|
12
|
+
'MUSIC_NEXT_17',
|
13
|
+
'VOLUME_MUTE',
|
14
|
+
'VOLUME_DOWN',
|
15
|
+
'VOLUME_UP',
|
16
|
+
'EJECT',
|
17
|
+
'POWER',
|
18
|
+
'NUMLOCK',
|
19
|
+
'VIDEO_MIRROR',
|
20
|
+
]
|
21
|
+
|
22
|
+
SYMBOL_TABLE = {
|
23
|
+
'`' => 'BACKQUOTE',
|
24
|
+
'\\' => 'BACKSLASH',
|
25
|
+
'[' => 'BRACKET_LEFT',
|
26
|
+
']' => 'BRACKET_RIGHT',
|
27
|
+
',' => 'COMMA',
|
28
|
+
'.' => 'DOT',
|
29
|
+
'=' => 'EQUAL',
|
30
|
+
'-' => 'MINUS',
|
31
|
+
'\'' => 'QUOTE',
|
32
|
+
';' => 'SEMICOLON',
|
33
|
+
'0' => 'KEY_0',
|
34
|
+
'1' => 'KEY_1',
|
35
|
+
'2' => 'KEY_2',
|
36
|
+
'3' => 'KEY_3',
|
37
|
+
'4' => 'KEY_4',
|
38
|
+
'5' => 'KEY_5',
|
39
|
+
'6' => 'KEY_6',
|
40
|
+
'7' => 'KEY_7',
|
41
|
+
'8' => 'KEY_8',
|
42
|
+
'9' => 'KEY_9',
|
43
|
+
}
|
44
|
+
|
45
|
+
SHIFT_TABLE = Hash[
|
46
|
+
%q[!@#$%^&*()_+~QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?~].each_char.to_a.zip(
|
47
|
+
%q(1234567890-=`qwertyuiop[]asdfghjkl;'\zxcvbnm,./`).each_char.to_a
|
48
|
+
)]
|
49
|
+
end
|
data/lib/keyremac/dump.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
module Keyremac
|
2
1
|
|
2
|
+
require 'keyremac/base'
|
3
|
+
|
4
|
+
module Keyremac
|
3
5
|
# key
|
4
6
|
# ===========================
|
5
7
|
|
@@ -32,24 +34,26 @@ module Keyremac
|
|
32
34
|
# autogen
|
33
35
|
# ===========================
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
module Autogen
|
38
|
+
class KeyToKey
|
39
|
+
def dump(xml)
|
40
|
+
seqs = [from, *to].map{ |k| k.dump(xml) }.join(', ')
|
41
|
+
xml.autogen "__KeyToKey__ #{seqs}"
|
42
|
+
end
|
39
43
|
end
|
40
|
-
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
class KeyToConsumer
|
46
|
+
def dump(xml)
|
47
|
+
xml.autogen "__KeyToConsumer__ #{from.dump(xml)}, #{to.dump(xml)}"
|
48
|
+
end
|
45
49
|
end
|
46
|
-
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
class KeyOverlaidModifier
|
52
|
+
def dump(xml)
|
53
|
+
seqs = [key, mod, *keys].map { |k| k.dump(xml) }.join(', ')
|
54
|
+
autogen = repeat ? '__KeyOverlaidModifierWithRepeat__' : '__KeyOverlaidModifier__'
|
55
|
+
xml.autogen "#{autogen} #{seqs}"
|
56
|
+
end
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
data/lib/keyremac/key.rb
CHANGED
@@ -1,58 +1,10 @@
|
|
1
1
|
|
2
2
|
require 'keyremac/base'
|
3
|
+
require 'keyremac/constants'
|
3
4
|
|
4
5
|
require 'set'
|
5
6
|
|
6
7
|
module Keyremac
|
7
|
-
|
8
|
-
CONSUMER_KEYS = [
|
9
|
-
'BRIGHTNESS_DOWN',
|
10
|
-
'BRIGHTNESS_UP',
|
11
|
-
'KEYBOARDLIGHT_OFF',
|
12
|
-
'KEYBOARDLIGHT_LOW',
|
13
|
-
'KEYBOARDLIGHT_HIGH',
|
14
|
-
'MUSIC_PREV',
|
15
|
-
'MUSIC_PLAY',
|
16
|
-
'MUSIC_NEXT',
|
17
|
-
'MUSIC_PREV_18',
|
18
|
-
'MUSIC_NEXT_17',
|
19
|
-
'VOLUME_MUTE',
|
20
|
-
'VOLUME_DOWN',
|
21
|
-
'VOLUME_UP',
|
22
|
-
'EJECT',
|
23
|
-
'POWER',
|
24
|
-
'NUMLOCK',
|
25
|
-
'VIDEO_MIRROR',
|
26
|
-
]
|
27
|
-
|
28
|
-
SYMBOL_TABLE = {
|
29
|
-
'`' => 'BACKQUOTE',
|
30
|
-
'\\' => 'BACKSLASH',
|
31
|
-
'[' => 'BRACKET_LEFT',
|
32
|
-
']' => 'BRACKET_RIGHT',
|
33
|
-
',' => 'COMMA',
|
34
|
-
'.' => 'DOT',
|
35
|
-
'=' => 'EQUAL',
|
36
|
-
'-' => 'MINUS',
|
37
|
-
'\'' => 'QUOTE',
|
38
|
-
';' => 'SEMICOLON',
|
39
|
-
'0' => 'KEY_0',
|
40
|
-
'1' => 'KEY_1',
|
41
|
-
'2' => 'KEY_2',
|
42
|
-
'3' => 'KEY_3',
|
43
|
-
'4' => 'KEY_4',
|
44
|
-
'5' => 'KEY_5',
|
45
|
-
'6' => 'KEY_6',
|
46
|
-
'7' => 'KEY_7',
|
47
|
-
'8' => 'KEY_8',
|
48
|
-
'9' => 'KEY_9',
|
49
|
-
}
|
50
|
-
|
51
|
-
SHIFT_TABLE = Hash[
|
52
|
-
%q[!@#$%^&*()_+~QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?~].each_char.to_a.zip(
|
53
|
-
%q(1234567890-=`qwertyuiop[]asdfghjkl;'\zxcvbnm,./`).each_char.to_a
|
54
|
-
)]
|
55
|
-
|
56
8
|
module Keyable
|
57
9
|
{
|
58
10
|
ctrl: :VK_CONTROL,
|
@@ -66,21 +18,28 @@ module Keyremac
|
|
66
18
|
define_method("#{k}?", -> { self.to_key.mods.include? v })
|
67
19
|
}
|
68
20
|
|
21
|
+
def add_rule(autogen)
|
22
|
+
Keyremac::Focus.add autogen
|
23
|
+
autogen
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [Array<Keyable>] keys
|
27
|
+
# @return [KeyToKey]
|
28
|
+
# @return [KeyToConsumer]
|
69
29
|
def to(*keys)
|
70
30
|
key = keys.first.to_key
|
71
|
-
|
72
|
-
|
31
|
+
if key.consumer_key?
|
32
|
+
add_rule Autogen::KeyToConsumer.new(self.to_key, key)
|
73
33
|
else
|
74
|
-
|
34
|
+
add_rule Autogen::KeyToKey.new(self.to_key, keys.map(&:to_key))
|
75
35
|
end
|
76
|
-
Keyremac.get_focus.add autogen
|
77
|
-
autogen
|
78
36
|
end
|
79
37
|
|
38
|
+
# @param [Keyable] mod
|
39
|
+
# @options [Keyable] mod
|
40
|
+
# @return [KeyToOverlaidModifier]
|
80
41
|
def overlaid(mod, keys: [], repeat: false)
|
81
|
-
|
82
|
-
Keyremac.get_focus.add autogen
|
83
|
-
autogen
|
42
|
+
add_rule Autogen::KeyOverlaidModifier.new(self.to_key, mod.to_key, keys: keys.map(&:to_key), repeat: repeat)
|
84
43
|
end
|
85
44
|
|
86
45
|
def consumer_key?
|
data/lib/keyremac/version.rb
CHANGED
data/samples/sample.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby -I ../lib -I lib
|
2
2
|
require 'keyremac'
|
3
3
|
|
4
4
|
item_ do
|
@@ -65,3 +65,13 @@ end
|
|
65
65
|
app 'SUBLIME', inputsource: 'JAPANESE' do
|
66
66
|
:TAB .to :i.ctrl
|
67
67
|
end
|
68
|
+
|
69
|
+
# item do
|
70
|
+
# autogen_ "__KeyToKey__ KeyCode::Q, KeyCode::VK_OPEN_URL_SCRIPT_test"
|
71
|
+
# end
|
72
|
+
|
73
|
+
# vkopenurldef_ do
|
74
|
+
# name_ "KeyCode::VK_OPEN_URL_SCRIPT_test"
|
75
|
+
# url_ "file:///Users/keqh/Dropbox/personal/projects/KEYnoe/keyremac/samples/sample.rb --test"
|
76
|
+
# end
|
77
|
+
|
data/spec/dump_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
|
2
2
|
require 'minitest/autorun'
|
3
|
-
require 'keyremac/base'
|
4
3
|
require 'keyremac/dump'
|
5
4
|
|
6
5
|
module MiniTest::Assertions
|
@@ -9,17 +8,42 @@ module MiniTest::Assertions
|
|
9
8
|
actual = rule.dump(xml)
|
10
9
|
assert actual == expected, message { diff expected, actual }
|
11
10
|
end
|
11
|
+
|
12
|
+
def assert_item(expected, rule)
|
13
|
+
expected = <<-EOI
|
14
|
+
<item>
|
15
|
+
<name>a</name>
|
16
|
+
<identifier>private.a</identifier>
|
17
|
+
#{expected}
|
18
|
+
</item>
|
19
|
+
EOI
|
20
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
21
|
+
actual = rule.dump(xml)
|
22
|
+
assert actual == expected, message { diff expected, actual }
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_autogen(expected, rule)
|
26
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
27
|
+
actual = rule.dump(xml)
|
28
|
+
assert_match("autogen", actual)
|
29
|
+
assert_match(expected, actual)
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_tag(expected, rule)
|
33
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
34
|
+
actual = rule.dump(xml)
|
35
|
+
assert_match(expected, actual)
|
36
|
+
end
|
12
37
|
end
|
13
38
|
Object.infect_an_assertion :assert_xml, :must_be_xml
|
39
|
+
Object.infect_an_assertion :assert_item, :must_be_item
|
40
|
+
Object.infect_an_assertion :assert_autogen, :must_be_autogen
|
41
|
+
Object.infect_an_assertion :assert_tag, :must_contain_tag
|
14
42
|
|
15
|
-
describe '
|
16
|
-
|
17
|
-
@root = Keyremac::Root.new
|
18
|
-
@xml = Builder::XmlMarkup.new(indent: 2)
|
19
|
-
Keyremac::Item.reset_identifier
|
20
|
-
end
|
43
|
+
describe 'root' do
|
44
|
+
let(:root) { Keyremac::Root.new }
|
21
45
|
|
22
|
-
it 'root
|
46
|
+
it 'generates root tag' do
|
23
47
|
expected = <<-EOR
|
24
48
|
<?xml version="1.0" encoding="UTF-8"?>
|
25
49
|
<root>
|
@@ -29,68 +53,30 @@ describe 'dump' do
|
|
29
53
|
</item>
|
30
54
|
</root>
|
31
55
|
EOR
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
it '任意のtagを書くことができる' do
|
36
|
-
expected = "<hoge>\n</hoge>\n"
|
37
|
-
@root.hoge_ {}.must_be_xml expected
|
56
|
+
root.must_be_xml expected
|
38
57
|
end
|
58
|
+
end
|
39
59
|
|
40
|
-
|
41
|
-
|
42
|
-
<item>
|
43
|
-
<name>a</name>
|
44
|
-
<identifier>private.a</identifier>
|
45
|
-
%s
|
46
|
-
</item>
|
47
|
-
EOI
|
48
|
-
|
49
|
-
it 'blank' do
|
50
|
-
expected = <<-EOI
|
51
|
-
<item>
|
52
|
-
<name>a</name>
|
53
|
-
<identifier>private.a</identifier>
|
54
|
-
</item>
|
55
|
-
EOI
|
56
|
-
@root.item {}.must_be_xml expected
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'raw' do
|
60
|
-
expected = ITEM % "<autogen>__KeyToKey__ KeyCode::J, KeyCode::K</autogen>"
|
61
|
-
@root.item {
|
62
|
-
autogen_ '__KeyToKey__ KeyCode::J, KeyCode::K'
|
63
|
-
}.must_be_xml expected
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'app' do
|
67
|
-
expected = ITEM % "<only>TERMINAL</only>"
|
68
|
-
@root.item(app: 'TERMINAL') {}.must_be_xml expected
|
69
|
-
end
|
60
|
+
describe 'raw' do
|
61
|
+
let(:root) { Keyremac::Root.new }
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
63
|
+
it 'can write any tags' do
|
64
|
+
root.hoge_ {}.must_contain_tag "hoge"
|
65
|
+
root.fuga_("").must_contain_tag "fuga"
|
75
66
|
end
|
67
|
+
end
|
76
68
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
describe Keyremac::Key do
|
70
|
+
describe '#to' do
|
71
|
+
it { (:j .to :k).must_be_autogen "KeyToKey" }
|
72
|
+
it { (:j .to :k, :l).must_be_autogen "KeyToKey" }
|
73
|
+
it { (:F7.to:MUSIC_PREV).must_be_autogen "KeyToConsumer" }
|
82
74
|
end
|
75
|
+
end
|
83
76
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
(:j .to :k).must_be_xml expected
|
88
|
-
end
|
89
|
-
|
90
|
-
it '複数' do
|
91
|
-
expected = "<autogen>__KeyToKey__ KeyCode::J, KeyCode::K, KeyCode::L</autogen>\n"
|
92
|
-
(:j .to :k, :l).must_be_xml expected
|
93
|
-
end
|
77
|
+
describe 'root' do
|
78
|
+
before do
|
79
|
+
@root = Keyremac::Root.new
|
94
80
|
end
|
95
81
|
|
96
82
|
ROOT2 = <<-EOR
|
@@ -104,57 +90,68 @@ describe 'dump' do
|
|
104
90
|
</root>
|
105
91
|
EOR
|
106
92
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
@root.dump.must_equal expected
|
112
|
-
end
|
93
|
+
it 'can write toplevel key definition' do
|
94
|
+
:j .to :k
|
95
|
+
expected = ROOT2 % "<autogen>__KeyToKey__ KeyCode::J, KeyCode::K</autogen>"
|
96
|
+
@root.must_be_xml expected
|
113
97
|
end
|
98
|
+
end
|
114
99
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
100
|
+
describe 'dump' do
|
101
|
+
before do
|
102
|
+
@root = Keyremac::Root.new
|
103
|
+
Keyremac::Item.reset_identifier
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'item' do
|
107
|
+
it 'generates item tag' do
|
108
|
+
contents = '__KeyToKey__ KeyCode::J, KeyCode::K'
|
109
|
+
@root.item { autogen_ contents }.must_be_item "<autogen>#{contents}</autogen>"
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'generates item tag with only tag' do
|
113
|
+
@root.item(app: 'TERMINAL') {}.must_be_item "<only>TERMINAL</only>"
|
119
114
|
end
|
120
115
|
|
121
|
-
it '
|
122
|
-
|
123
|
-
:j.none.must_be_xml expected
|
116
|
+
it 'generates item tag with inputsource_only tag' do
|
117
|
+
@root.item(inputsource: 'JAPANESE') {}.must_be_item "<inputsource_only>JAPANESE</inputsource_only>"
|
124
118
|
end
|
125
119
|
|
126
|
-
it '
|
127
|
-
|
128
|
-
:j.ctrl.cmd.must_be_xml expected
|
120
|
+
it 'generates item tag with only tag' do
|
121
|
+
@root.app('TERMINAL') {}.must_be_item "<only>TERMINAL</only>"
|
129
122
|
end
|
130
123
|
end
|
131
124
|
|
132
|
-
describe '
|
133
|
-
it '
|
134
|
-
|
135
|
-
|
125
|
+
describe 'mods' do
|
126
|
+
it 'trails mod key' do
|
127
|
+
:j.ctrl.must_be_xml "KeyCode::J, VK_CONTROL"
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'trails none flag' do
|
131
|
+
:j.none.must_be_xml "KeyCode::J, ModifierFlag::NONE"
|
136
132
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
133
|
+
|
134
|
+
it 'trails mod keys' do
|
135
|
+
:j.ctrl.cmd.must_be_xml "KeyCode::J, VK_CONTROL | VK_COMMAND"
|
140
136
|
end
|
141
137
|
end
|
142
138
|
|
143
139
|
describe 'key_overlaid_modifier' do
|
144
|
-
it '
|
145
|
-
expected = "
|
146
|
-
(:JIS_EISUU.overlaid:COMMAND_L).
|
140
|
+
it 'generates KeyOverlaidModifier' do
|
141
|
+
expected = "__KeyOverlaidModifier__ KeyCode::JIS_EISUU, KeyCode::COMMAND_L, KeyCode::JIS_EISUU"
|
142
|
+
(:JIS_EISUU.overlaid:COMMAND_L).must_be_autogen expected
|
147
143
|
end
|
148
|
-
|
149
|
-
|
144
|
+
|
145
|
+
it 'generates KeyOverlaidModifier with keys' do
|
146
|
+
expected = "__KeyOverlaidModifier__ KeyCode::CONTROL_L, KeyCode::CONTROL_L, KeyCode::JIS_EISUU, KeyCode::ESCAPE"
|
150
147
|
autogen = :CONTROL_L .overlaid :CONTROL_L, keys: [:JIS_EISUU, :ESCAPE]
|
151
|
-
autogen.
|
148
|
+
autogen.must_be_autogen expected
|
152
149
|
end
|
153
150
|
|
154
|
-
it '
|
155
|
-
expected = "
|
151
|
+
it 'generates KeyOverlaidModifierWithRepeat' do
|
152
|
+
expected = "__KeyOverlaidModifierWithRepeat__ KeyCode::SPACE, KeyCode::SHIFT_L, KeyCode::SPACE"
|
156
153
|
autogen = :SPACE .overlaid :SHIFT_L, repeat: true
|
157
|
-
autogen.
|
154
|
+
autogen.must_be_autogen expected
|
158
155
|
end
|
159
156
|
end
|
160
157
|
end
|
data/spec/keyremac_spec.rb
CHANGED
@@ -2,138 +2,136 @@
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'keyremac/base'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module MiniTest::Assertions
|
6
|
+
def assert_add_child(rule)
|
7
|
+
expected = 1
|
8
|
+
actual = rule.children.length
|
9
|
+
assert expected == actual, message { diff expected, actual }
|
8
10
|
end
|
11
|
+
end
|
12
|
+
Object.infect_an_assertion :assert_add_child, :must_add_child, :unary
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
+
module Keyremac
|
15
|
+
describe Root do
|
16
|
+
let(:root) { Root.new }
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
@root.children.length.must_equal 1
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'item' do
|
23
|
-
it '' do
|
24
|
-
@root.item {}
|
25
|
-
@root.children.length.must_equal 1
|
18
|
+
it 'includes any tags' do
|
19
|
+
root.item_('hoge')
|
20
|
+
root.must_add_child
|
26
21
|
end
|
27
22
|
|
28
|
-
it '
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
@root.children.length.must_equal 1
|
23
|
+
it 'includes any tags' do
|
24
|
+
root.item_ { name_ 'hoge' }
|
25
|
+
root.must_add_child
|
33
26
|
end
|
34
27
|
|
35
|
-
it '
|
36
|
-
|
37
|
-
|
28
|
+
it 'includes item' do
|
29
|
+
root.item {}
|
30
|
+
root.must_add_child
|
38
31
|
end
|
39
32
|
|
40
|
-
it '
|
41
|
-
|
42
|
-
|
33
|
+
it 'includes app' do
|
34
|
+
root.app('dummy') { }
|
35
|
+
root.must_add_child
|
43
36
|
end
|
44
37
|
end
|
45
38
|
|
46
|
-
describe '
|
47
|
-
|
48
|
-
container = @root.app('dummy') { }
|
49
|
-
container.class.must_equal Keyremac::Item
|
50
|
-
container.children.length.must_equal 1
|
51
|
-
end
|
52
|
-
end
|
39
|
+
describe 'container' do
|
40
|
+
let(:root) { Root.new }
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
item.children.length.must_equal 1
|
60
|
-
end
|
42
|
+
describe 'item' do
|
43
|
+
it 'can use item container' do
|
44
|
+
root.item { autogen_ '__KeyToKey__ KeyCode::J, KeyCode::K' }
|
45
|
+
root.must_add_child
|
46
|
+
end
|
61
47
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
48
|
+
it 'can use item container with app_only' do
|
49
|
+
root.item(app: 'TERMINAL') { }
|
50
|
+
root.must_add_child
|
51
|
+
end
|
66
52
|
|
67
|
-
|
68
|
-
|
69
|
-
|
53
|
+
it 'can use item container with inputsource_only' do
|
54
|
+
root.item(inputsource: 'JAPANESE') { }
|
55
|
+
root.must_add_child
|
56
|
+
end
|
70
57
|
end
|
71
|
-
end
|
72
58
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
item.children.length.must_equal 1
|
59
|
+
describe 'app' do
|
60
|
+
it 'is the same as item container with app_only' do
|
61
|
+
container = root.app('dummy') { }
|
62
|
+
container.must_be_instance_of Item
|
63
|
+
end
|
79
64
|
end
|
65
|
+
end
|
80
66
|
|
81
|
-
|
82
|
-
|
83
|
-
end
|
67
|
+
describe 'autogen' do
|
68
|
+
let(:root) { Root.new }
|
84
69
|
|
85
|
-
|
86
|
-
|
87
|
-
|
70
|
+
describe 'to' do
|
71
|
+
it { root.item { :j .to :k }.must_add_child }
|
72
|
+
it { (:j .to :k).must_be_instance_of Autogen::KeyToKey }
|
73
|
+
it { (:a .to :b, :c).must_be_instance_of Autogen::KeyToKey }
|
88
74
|
end
|
89
75
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
76
|
+
describe 'overlaid' do
|
77
|
+
it 'generates KeyOverlaidModifier' do
|
78
|
+
(:JIS_EISUU .overlaid :COMMAND_L).must_be_instance_of Autogen::KeyOverlaidModifier
|
79
|
+
end
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
81
|
+
it 'generates KeyOverlaidModifier with keys' do
|
82
|
+
autogen = :CONTROL_L .overlaid :CONTROL_L, keys: [:JIS_EISUU, :ESCAPE]
|
83
|
+
autogen.class.must_equal Autogen::KeyOverlaidModifier
|
84
|
+
end
|
100
85
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
:j.send(mod).send("#{mod}?").must_equal true
|
86
|
+
it 'has repeat: false by default' do
|
87
|
+
autogen = :CONTROL_L .overlaid :CONTROL_L
|
88
|
+
autogen.wont_be :repeat?
|
105
89
|
end
|
106
|
-
}
|
107
|
-
end
|
108
90
|
|
109
|
-
|
110
|
-
|
111
|
-
|
91
|
+
it 'enables repeat flag' do
|
92
|
+
autogen = :CONTROL_L .overlaid :CONTROL_L, repeat: true
|
93
|
+
autogen.must_be :repeat?
|
94
|
+
end
|
112
95
|
end
|
113
96
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
key.shift?.must_equal true
|
97
|
+
describe 'autogen' do
|
98
|
+
it { (:j .to :k).must_be_instance_of Autogen::KeyToKey }
|
99
|
+
it { (:F7 .to :MUSIC_PREV).must_be_instance_of Autogen::KeyToConsumer }
|
118
100
|
end
|
119
101
|
|
120
|
-
|
121
|
-
'
|
102
|
+
describe 'overlaid' do
|
103
|
+
it 'can contain KeyOverlaidModifier' do
|
104
|
+
root.item { :JIS_EISUU .overlaid :COMMAND_L }.must_add_child
|
105
|
+
end
|
122
106
|
end
|
123
107
|
end
|
124
108
|
|
125
|
-
describe '
|
126
|
-
|
127
|
-
:
|
109
|
+
describe 'primitive' do
|
110
|
+
describe 'key' do
|
111
|
+
it { :a.to_key.must_be_kind_of Keyable }
|
112
|
+
it { 'a'.to_key.must_be_kind_of Keyable }
|
113
|
+
|
114
|
+
it 'decodes key + shift' do
|
115
|
+
key = :J.to_key
|
116
|
+
key.code.must_equal 'j'
|
117
|
+
key.must_be :shift?
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'converts KEY_*' do
|
121
|
+
'1'.to_key.code.must_equal 'KEY_1'
|
122
|
+
end
|
128
123
|
end
|
129
|
-
end
|
130
124
|
|
131
|
-
|
132
|
-
|
133
|
-
(:j .to :k).class.must_equal Keyremac::KeyToKey
|
125
|
+
describe 'consumer_key' do
|
126
|
+
it { :MUSIC_PREV.to_key.must_be_instance_of ConsumerKey }
|
134
127
|
end
|
135
|
-
|
136
|
-
|
128
|
+
|
129
|
+
describe 'mods' do
|
130
|
+
[:ctrl, :shift, :opt, :cmd, :extra1, :none].each { |mod|
|
131
|
+
it "adds #{mod} flag" do
|
132
|
+
:j.send(mod).must_be :"#{mod}?"
|
133
|
+
end
|
134
|
+
}
|
137
135
|
end
|
138
136
|
end
|
139
|
-
end
|
137
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keyremac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- keqh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: awesome_print
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: builder
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,11 +63,13 @@ files:
|
|
77
63
|
- .travis.yml
|
78
64
|
- Gemfile
|
79
65
|
- LICENSE.txt
|
66
|
+
- README.ja.md
|
80
67
|
- README.md
|
81
68
|
- Rakefile
|
82
69
|
- keyremac.gemspec
|
83
70
|
- lib/keyremac.rb
|
84
71
|
- lib/keyremac/base.rb
|
72
|
+
- lib/keyremac/constants.rb
|
85
73
|
- lib/keyremac/dump.rb
|
86
74
|
- lib/keyremac/key.rb
|
87
75
|
- lib/keyremac/version.rb
|
@@ -115,3 +103,4 @@ summary: KeyRemap4MacBook private.xml generator
|
|
115
103
|
test_files:
|
116
104
|
- spec/dump_spec.rb
|
117
105
|
- spec/keyremac_spec.rb
|
106
|
+
has_rdoc:
|