-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unite key bindings, key mapping and multibyte buffer
- Loading branch information
Showing
19 changed files
with
291 additions
and
452 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
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,15 +1,36 @@ | ||
class Reline::KeyActor::Base | ||
MAPPING = Array.new(256) | ||
def initialize | ||
@matching_bytes = {} | ||
@key_bindings = {} | ||
end | ||
|
||
def get_method(key) | ||
self.class::MAPPING[key] | ||
def add_mappings(mappings) | ||
add([27], :ed_ignore) | ||
128.times do |key| | ||
func = mappings[key] | ||
meta_func = mappings[key | 0b10000000] | ||
add([key], func) unless func == :ed_unassigned | ||
add([27, key], meta_func) unless meta_func == :ed_unassigned | ||
end | ||
end | ||
|
||
def initialize | ||
@default_key_bindings = {} | ||
def add(key, func) | ||
(1...key.size).each do |size| | ||
@matching_bytes[key.take(size)] = true | ||
end | ||
@key_bindings[key] = func | ||
end | ||
|
||
def matching?(key) | ||
@matching_bytes[key] | ||
end | ||
|
||
def get(key) | ||
@key_bindings[key] | ||
end | ||
|
||
def default_key_bindings | ||
@default_key_bindings | ||
def clear | ||
@matching_bytes.clear | ||
@key_bindings.clear | ||
end | ||
end |
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,17 @@ | ||
class Reline::KeyActor::Composite | ||
def initialize(key_actors) | ||
@key_actors = key_actors | ||
end | ||
|
||
def matching?(key) | ||
@key_actors.any? { |key_actor| key_actor.matching?(key) } | ||
end | ||
|
||
def get(key) | ||
@key_actors.each do |key_actor| | ||
func = key_actor.get(key) | ||
return func if func | ||
end | ||
nil | ||
end | ||
end |
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
Oops, something went wrong.