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::HOOKS

Instance Method Summary collapse

Methods inherited from InputMethod

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

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!, 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, 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.



30
31
32
33
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 30

def initialize
  super
  @input_buffer = +""
end

Instance Method Details

#flush(s) ⇒ Object



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

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



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

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



35
36
37
# File 'lib/textbringer/input_methods/hiragana_input_method.rb', line 35

def status
  ""
end