Class: Canis::DefaultKeyHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/canis/core/widgets/textpad.rb

Overview

It takes care of catching numbers so that vim’s movement can use numeric args. That is taken care of by multiplier. Other than that it has the key_map process the key.

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ DefaultKeyHandler

—- {{{



1611
1612
1613
# File 'lib/canis/core/widgets/textpad.rb', line 1611

def initialize source
  @source = source
end

Instance Method Details

#handle_key(ch) ⇒ Object



1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
# File 'lib/canis/core/widgets/textpad.rb', line 1615

def handle_key ch
  begin
    case ch
    when ?0.getbyte(0)..?9.getbyte(0)
      if ch == ?0.getbyte(0) && $multiplier == 0
        @source.cursor_bol
        @source.bounds_check
        return 0
      end
      # storing digits entered so we can multiply motion actions
      $multiplier *= 10 ; $multiplier += (ch-48)
      return 0
    when ?\C-c.getbyte(0)
      $multiplier = 0
      return 0
    else
      # check for bindings, these cannot override above keys since placed at end
      begin
        ret = @source.process_key ch, self
        $multiplier = 0
        @source.bounds_check
        ## If i press C-x > i get an alert from rwidgets which blacks the screen
        # if i put a padrefresh here it becomes okay but only for one pad,
        # i still need to do it for all pads.
      rescue => err
        $log.error " TEXTPAD ERROR handle_key #{err} "
        $log.debug(err.backtrace.join("\n"))
        alert "#{err}"
        #textdialog ["Error in TextPad: #{err} ", *err.backtrace], :title => "Exception"
      end
      # --- NOTE ABOUT BLACK RECT LEFT on SCREEN {{{
      ## NOTE if textpad does not handle the event and it goes to form which pops
      # up a messagebox, then padrefresh does not happen, since control does not
      # come back here, so a black rect is left on screen
      # please note that a bounds check will not happen for stuff that
      # is triggered by form, so you'll have to to it yourself or
      # call setrowcol explicity if the cursor is not updated
      # --- }}}

      return :UNHANDLED if ret == :UNHANDLED
    end
  rescue => err
    $log.error " TEXTPAD ERROR 591 #{err} "
    $log.debug( err) if err
    $log.debug(err.backtrace.join("\n")) if err
    # NOTE: textdialog itself is based on this class.
    alert "#{err}"
    #textdialog ["Error in TextPad: #{err} ", *err.backtrace], :title => "Exception"
    $error_message.value = ""
  ensure
    # this means that even unhandled will trigger a refresh
    @source.padrefresh
    Ncurses::Panel.update_panels
  end
  return 0
end