Class: Textbringer::HiraganaInputMethod

Inherits:
InputMethod show all
Defined in:
lib/textbringer/input_methods/hiragana_input_method.rb

Constant Summary collapse

HIRAGANA_TABLE =
{
  "a" => "あ", "i" => "い", "u" => "う", "e" => "え", "o" => "お",
  "ka" => "か", "ki" => "き", "ku" => "く", "ke" => "け", "ko" => "こ",
  "ga" => "が", "gi" => "ぎ", "gu" => "ぐ", "ge" => "げ", "go" => "ご",
  "sa" => "さ", "si" => "し", "su" => "す", "se" => "せ", "so" => "そ",
  "za" => "ざ", "zi" => "じ", "zu" => "ず", "ze" => "ぜ", "zo" => "ぞ",
  "sha" => "しゃ", "shi" => "し", "shu" => "しゅ", "she" => "しぇ", "sho" => "しょ",
  "ja" => "じゃ", "ji" => "じ", "ju" => "じゅ", "je" => "じぇ", "jo" => "じょ",
  "ta" => "た", "ti" => "ち", "tu" => "つ", "te" => "て", "to" => "と",
  "da" => "だ", "di" => "ぢ", "du" => "づ", "de" => "で", "do" => "ど",
  "cha" => "ちゃ", "chi" => "ち", "chu" => "ちゅ", "che" => "ちぇ", "cho" => "ちょ",
  "na" => "な", "ni" => "に", "nu" => "ぬ", "ne" => "ね", "no" => "の",
  "ha" => "は", "hi" => "ひ", "hu" => "ふ", "he" => "へ", "ho" => "ほ",
  "ba" => "ば", "bi" => "び", "bu" => "ぶ", "be" => "べ", "bo" => "ぼ",
  "pa" => "ぱ", "pi" => "ぴ", "pu" => "ぷ", "pe" => "ぺ", "po" => "ぽ",
  "ma" => "ま", "mi" => "み", "mu" => "む", "me" => "め", "mo" => "も",
  "ya" => "や", "yi" => "い", "yu" => "ゆ", "ye" => "いぇ", "yo" => "よ",
  "ra" => "ら", "ri" => "り", "ru" => "る", "re" => "れ", "ro" => "ろ",
  "wa" => "わ", "wi" => "ゐ", "wu" => "う", "we" => "ゑ", "wo" => "を",
  "nn" => "ん"
}
HIRAGANA_PREFIXES =
HIRAGANA_TABLE.keys.flat_map { |s|
  (s.size - 1).times.map { |i| s[0, i + 1] }
}.uniq

Constants included from Commands

Commands::CLIPBOARD_AVAILABLE, Commands::CTAGS, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::KEYBOARD_MACROS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS

Constants included from Utils

Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS

Instance Method Summary collapse

Methods inherited from InputMethod

#disable, #enabled?, #filter_event, find, inherited, list, #toggle, #with_target_buffer

Methods included from Commands

[], #command_help, command_table, #current_prefix_arg, define_command, #execute_keyboard_macro, #get_tags, #isearch_done, #isearch_mode, #isearch_mode?, #isearch_pre_command_hook, #isearch_prompt, #isearch_repeat, #isearch_repeat_backward, #isearch_repeat_forward, #isearch_search, #keymap_bindings, list, #match_beginning, #match_end, #match_string, #number_prefix_arg, #prefix_numeric_value, #read_input_method_name, #read_keyboard_macro, #read_register, #replace_match, undefine_command, #universal_argument_mode

Methods included from Utils

add_hook, background, complete_for_minibuffer, foreground, foreground!, get_hooks, message, read_buffer, read_char, read_command_name, read_encoding, read_event, read_expression, read_file_name, read_from_minibuffer, read_key_sequence, read_object, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, run_hooks_in, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, y_or_n?, yes_or_no?

Constructor Details

#initializeHiraganaInputMethod

Returns a new instance of HiraganaInputMethod.



28
29
30
31
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 28

def initialize
  super
  @input_buffer = +""
end

Instance Method Details

#flush(s) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 55

def flush(s)
  if !@input_buffer.empty?
    @input_buffer = +""
  end
  if s.size == 1
    s
  else
    Buffer.current.insert(s)
    Window.redisplay
    nil
  end
end

#handle_event(event) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 37

def handle_event(event)
  if !event.is_a?(String)
    if !@input_buffer.empty?
      @input_buffer = +""
    end
    return event
  end
  @input_buffer << event
  s = HIRAGANA_TABLE[@input_buffer]
  if s
    return flush(s)
  end
  if HIRAGANA_PREFIXES.include?(@input_buffer)
    return nil
  end
  flush(@input_buffer)
end

#statusObject



33
34
35
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 33

def status
  "あ"
end