Top Level Namespace
Defined Under Namespace
Classes: AnsiBackend, BitmapWindow, Controller, EscapeParser, RubyTerm, Term, TermBuffer, TrackChanges, UTF8Decoder, Window, WindowAdapter
Constant Summary collapse
- SPECIALS =
{ "+" => :"ctrl_+", "-" => :"ctrl_-" }
- KEYMAP =
Map X key events to escapes
{ :enter => "\r", :backspace => "\x7F", :tab => "\t", :XK_Escape => "\e", :f1 => "\e[11~", :f2 => "\e[12~", :f3 => "\e[13~", :f4 => "\e[14~", :f5 => "\e[15~", :f6 => "\e[16~", :f7 => "\e[17~", :f8 => "\e[18~", :f9 => "\e[19~", :f10 => "\e[20~", :f11 => "\e[21~", :f12 => "\e[22~", :shift_up => "\e[1;2A", :shift_down => "\e[1;2B", :shift_tab => "\e[Z", :XK_Left => "\e[D", :XK_Right => "\e[C", :XK_Down => "\e[B", :XK_ISO_Left_Tab => "\t", :XK_Up => "\e[A", :XK_Delete => "\e[P", :XK_Page_Up => "\x1b[5~", :XK_Page_Down => "\x1b[6~", }
- PALETTE_BASIC =
[ 0x000000, 0xd73737, 0x60ac39, 0xae9513, 0x6684e1, 0xb854d4, 0x1fad83, 0xcccccc, 0x7d7a68, 0xff3737, 0x80dc39, 0xfff013, 0x6694ff, 0xd854ff, 0x1fdda3, 0xffffff]
- PALETTE256 =
PALETTE_BASIC + [0,0x5f, 0x87, 0xaf, 0xd7, 0xff].repeated_permutation(3).sort.map{|ary| (ary[0]<<16)+(ary[1]<<8)+ary[2]}+ (8..244).step(10).map{|n| (n<<16)+(n<<8)+n}
- FG =
Default foreground/background, stored as basic-palette indices (strings; Term resolves them to colours). Defined here so the library is self-contained; guarded so callers that pre-define them (tests, harness) don’t clash.
"7"- BG =
"0"- DefaultCharset =
FIXME: This is the start of defining character sets as per the vt102/vt200 specs
They should be wrapped in modules and split out with other relevant data in a separate gem.
These objects are expected to act as a Hash, and provide a value for anything passed in, translating only those keys that are different
Hash.new{|_,k| k }.freeze
- GraphicsCharset =
{ 0x5f => "\u00A0", 0x60 => "\u25c6", 0x61 => "\u2592", 0x62 => "\u2409", 0x63 => "\u240C", 0x64 => "\u240d", 0x65 => "\u240A", 0x66 => "\u00B0", 0x67 => "\u00B1", 0x68 => "\u2424", 0x69 => "\u240B", 0x6A => "\u2518", 0x6B => "\u2510", 0x6C => "\u250C", 0x6D => "\u2514", 0x6E => "\u253C", 0x6f => "\u23BA", 0x70 => "\u23BB", 0x71 => "\u2500", 0x72 => "\u23BC", 0x73 => "\u23BD", 0x74 => "\u251c", 0x75 => "\u2524", 0x76 => "\u2534", 0x77 => "\u252c", 0x78 => "\u2502", 0x79 => "\u2264", 0x7A => "\u2265", 0x7B => "\u03C0", 0x7C => "\u2260", 0x7D => "\u00A3", 0x7E => "\u00b7", }
- BOLD =
0x002- FAINT =
0x004- ITALICS =
0x008- UNDERLINE =
0x010- BLINK =
0x020- RAPID_BLINK =
0x040- INVERSE =
0x080- INVISIBLE =
0x100- CROSSED_OUT =
0x200- DBL_UNDERLINE =
0x400- OVERLINE =
0x800
Instance Method Summary collapse
- #keysym_to_vt102(ks) ⇒ Object
- #lookup_keysym(dpy, event) ⇒ Object
- #lookup_string(dpy, event) ⇒ Object
- #update_keymap(dpy) ⇒ Object
Instance Method Details
#keysym_to_vt102(ks) ⇒ Object
110 111 112 |
# File 'lib/keymap.rb', line 110 def keysym_to_vt102(ks) KEYMAP[ks] end |
#lookup_keysym(dpy, event) ⇒ Object
34 35 36 37 |
# File 'lib/keymap.rb', line 34 def lookup_keysym(dpy, event) update_keymap(dpy) if !$kmap $kmap[event.detail-dpy.display_info.min_keycode] rescue nil end |
#lookup_string(dpy, event) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/keymap.rb', line 44 def lookup_string(dpy, event) ks = Array(lookup_keysym(dpy, event)) str = "" shift = event.state.anybits?(0x01) = event.state.anybits?(0x08) ctrl = event.state.anybits?(0x04) i = shift && ks[1] ? 1 : 0 return SPECIALS[ks[i]] if ctrl && SPECIALS[ks[i]] if shift case ks[i] # FIXME: This is messed up. when :XK_ISO_Left_Tab then return :shift_tab, nil when :XK_Down; then return :shift_down, nil when :XK_Up; then return :shift_up, nil when :XK_Page_Up; then return :shift_page_up, nil when :XK_Page_Down; then return :shift_page_down, nil end end if ks[i].is_a?(String) if ctrl str = (ks[i][0].ord & 0x9f).chr # Strip 0x60 elsif str = "\e#{ks[i]}" else str = ks[i] end end return ks[i], str end |
#update_keymap(dpy) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/keymap.rb', line 4 def update_keymap(dpy) reply = dpy.get_keyboard_mapping if reply $kmap = reply.keysyms.map do |c| if c == 0 nil elsif X11::KeySyms[c] X11::KeySyms[c] elsif c < 0x100 c.chr(Encoding::ISO_8859_1) elsif c.between?(0xffb0, 0xffb9) "KP_#{c-0xffb0}".to_sym elsif c.between?(0xffbe, 0xffe0) "f#{c-0xffbe+1}".to_sym elsif c.between?(0xff08, 0xffff) # FIXME: raise "keyboard_#{c.to_s(16)}".to_s elsif c.between?(0x01000100, 0x0110FFFF) (c-0x01000100). chr(Encoding::UTF_32) rescue c.to_s(16) else STDERR.puts "keymap: unknown_#{c.to_s(16)}" end end.each_slice(reply.keysyms_per_keycode).to_a #ks = ks.map {|s| s.compact.sort_by{|x| x.to_s}.uniq }.to_a # This is for testing/ease of reading only end end |