module Cura
  # Helpers for dealing with keyboard keys.
  module Key
    NAMES = { # Name => Character
      ac_back: nil,
      ac_bookmarks: nil,
      ac_forward: nil,
      ac_home: nil,
      ac_refresh: nil,
      ac_search: nil,
      ac_stop: nil,
      again: nil,
      alterase: nil,
      ampersand: "&",
      apostrophe: nil,
      application: nil,
      asterisk: "*",
      at: "@",
      audio_mute: nil,
      audio_next: nil,
      audio_play: nil,
      audio_prev: nil,
      audio_previous: nil,
      audio_stop: nil,
      backquote: "`",
      backslash: '\\',
      backspace: nil,
      binary: nil,
      brightness_down: nil,
      brightness_up: nil,
      calculator: nil,
      cancel: nil,
      capslock: nil,
      caret: "^",
      clear: nil,
      clear_again: nil,
      clear_entry: nil,
      colon: ":",
      comma: ",",
      computer: nil,
      copy: nil,
      crsel: nil, # TODO: Clear selection?
      currency_subunit: nil,
      currency_unit: nil,
      cut: nil,
      decimal: nil, # See: hexadecimal
      decimal_separator: nil,
      delete: nil,
      display_switch: nil,
      divide: "%",
      dollar: "$", # TODO: i18n?
      double_ampersand: nil,
      double_quote: '"',
      double_vertical_bar: nil,
      down: nil,
      eject: nil,
      end: nil,
      enter: nil,
      equals: "=",
      equalsas400: nil,
      escape: nil,
      exclamation: "!",
      execute: nil,
      exsel: nil,
      f1: nil,
      f10: nil,
      f11: nil,
      f12: nil,
      f13: nil,
      f14: nil,
      f15: nil,
      f16: nil,
      f17: nil,
      f18: nil,
      f19: nil,
      f2: nil,
      f20: nil,
      f21: nil,
      f22: nil,
      f23: nil,
      f24: nil,
      f3: nil,
      f4: nil,
      f5: nil,
      f6: nil,
      f7: nil,
      f8: nil,
      f9: nil,
      find: nil,
      grave: nil,
      greater: ">",
      hash: "#",
      help: nil,
      hexadecimal: nil,
      home: nil,
      insert: nil,
      international_1: nil,
      international_2: nil,
      international_3: nil,
      international_4: nil,
      international_5: nil,
      international_6: nil,
      international_7: nil,
      international_8: nil,
      international_9: nil,
      kbdillum_down: nil,
      kbdillum_toggle: nil,
      kbdillum_up: nil,
      language_1: nil,
      language_2: nil,
      language_3: nil,
      language_4: nil,
      language_5: nil,
      language_6: nil,
      language_7: nil,
      language_8: nil,
      language_9: nil,
      left: nil,
      left_alt: nil,
      left_brace: "{",
      left_bracket: "[",
      left_control: nil,
      left_ctrl: nil,
      left_gui: nil,
      left_parenthesis: "(",
      left_race: nil,
      left_shift: nil,
      less: "<",
      a: "a",
      b: "b",
      c: "c",
      d: "d",
      e: "e",
      f: "f",
      g: "g",
      h: "h",
      i: "i",
      j: "j",
      k: "k",
      l: "l",
      m: "m",
      n: "n",
      o: "o",
      p: "p",
      q: "q",
      r: "r",
      s: "s",
      t: "t",
      u: "u",
      v: "v",
      w: "w",
      x: "x",
      y: "y",
      z: "z",
      A: "A",
      B: "B",
      C: "C",
      D: "D",
      E: "E",
      F: "F",
      G: "G",
      H: "H",
      I: "I",
      J: "J",
      K: "K",
      L: "L",
      M: "M",
      N: "N",
      O: "O",
      P: "P",
      Q: "Q",
      R: "R",
      S: "S",
      T: "T",
      U: "U",
      V: "V",
      W: "W",
      X: "X",
      Y: "Y",
      Z: "Z",
      locking_capslock: nil,
      locking_numlock: nil,
      locking_scrolllock: nil,
      mail: nil,
      media_select: nil,
      mem_add: nil,
      mem_clear: nil,
      mem_divide: nil,
      mem_multiply: nil,
      mem_recall: nil,
      mem_store: nil,
      mem_subtract: nil,
      menu: nil,
      minus: "-",
      mode: nil,
      multiply: "*",
      mute: nil,
      non_us_backslash: nil,
      non_us_hash: nil,
      "0".to_sym => "0",
      "00".to_sym => "00",
      "000".to_sym => "000",
      "1".to_sym => "1",
      "2".to_sym => "2",
      "3".to_sym => "3",
      "4".to_sym => "4",
      "5".to_sym => "5",
      "6".to_sym => "6",
      "7".to_sym => "7",
      "8".to_sym => "8",
      "9".to_sym => "9",
      numlock_clear: nil,
      numpad_0: "0",
      numpad_1: "1",
      numpad_2: "2",
      numpad_3: "3",
      numpad_4: "4",
      numpad_5: "5",
      numpad_6: "6",
      numpad_7: "7",
      numpad_8: "8",
      numpad_9: "9",
      numpad_equals: "=",
      numpad_slash: "/",
      numpad_asterisk: "*",
      numpad_minus: "-",
      numpad_plus: "+",
      numpad_enter: nil,
      numpad_period: ".",
      octal: nil,
      oper: nil,
      out: nil,
      page_down: nil,
      page_up: nil,
      paste: nil,
      pause: nil,
      percent: "%",
      period: ".",
      plus: "+",
      plus_minus: nil,
      power: nil,
      print_screen: nil,
      prior: nil,
      question: "?",
      quote: '\'',
      return: nil,
      right: nil,
      right_alt: nil,
      right_brace: "}",
      right_bracket: "]",
      right_control: nil,
      right_ctrl: nil,
      right_gui: nil,
      right_parenthesis: ")",
      right_shift: nil,
      scrolllock: nil,
      select: nil,
      semicolon: ";",
      separator: nil,
      slash: "/",
      sleep: nil,
      space: nil,
      stop: nil,
      sysreq: nil,
      tab: nil,
      thousands_separator: nil,
      tilde: "~",
      underscore: "_",
      undo: nil,
      unknown: nil,
      up: nil,
      vertical_bar: "|",
      volume_down: nil,
      volume_up: nil,
      www: nil,
      xor: nil
    }

    class << self
      # Check if the given name is valid.
      #
      # @param [#to_sym] value
      # @return [Boolean]
      def valid_name?(value)
        NAMES.key?(value.to_sym)
      end

      # Check if the given name is printable.
      #
      # @param [#to_sym] value
      # @return [Boolean]
      def name_is_printable?(value)
        !NAMES[value.to_sym].nil?
      end

      def name_from_character(value)
        value = value.to_s[0]

        NAMES.key(value)
      end

      def character_from_name(value)
        NAMES[value.to_sym]
      end
    end
  end
end
