1 2 # Classes responsible for drawing signs in the Vim user interface. 3 4 import vim 5 6 class VimSign(object): 7 SIGN_TEXT_BREAKPOINT_RESOLVED = "B>" 8 SIGN_TEXT_BREAKPOINT_UNRESOLVED = "b>" 9 SIGN_TEXT_PC = "->" 10 SIGN_HIGHLIGHT_COLOUR_PC = 'darkblue' 11 12 # unique sign id (for ':[sign/highlight] define) 13 sign_id = 1 14 15 # unique name id (for ':sign place') 16 name_id = 1 17 18 # Map of {(sign_text, highlight_colour) --> sign_name} 19 defined_signs = {} 20 21 def __init__(self, sign_text, buffer, line_number, highlight_colour=None): 22 """ Define the sign and highlight (if applicable) and show the sign. """ 23 24 # Get the sign name, either by defining it, or looking it up in the map of defined signs 25 key = (sign_text, highlight_colour) 26 if not key in VimSign.defined_signs: 27 name = self.define(sign_text, highlight_colour) 28 else: 29 name = VimSign.defined_signs[key] 30 31 self.show(name, buffer.number, line_number) 32 pass 33 34 def define(self, sign_text, highlight_colour): 35 """ Defines sign and highlight (if highlight_colour is not None). """ 36 sign_name = "sign%d" % VimSign.name_id 37 if highlight_colour is None: 38 vim.command("sign define %s text=%s" % (sign_name, sign_text)) 39 else: 40 self.highlight_name = "highlight%d" % VimSign.name_id 41 vim.command("highlight %s ctermbg=%s guibg=%s" % (self.highlight_name, 42 highlight_colour, 43 highlight_colour)) 44 vim.command("sign define %s text=%s linehl=%s texthl=%s" % (sign_name, 45 sign_text, 46 self.highlight_name, 47 self.highlight_name)) 48 VimSign.defined_signs[(sign_text, highlight_colour)] = sign_name 49 VimSign.name_id += 1 50 return sign_name 51 52 53 def show(self, name, buffer_number, line_number): 54 self.id = VimSign.sign_id 55 VimSign.sign_id += 1 56 vim.command("sign place %d name=%s line=%d buffer=%s" % (self.id, name, line_number, buffer_number)) 57 pass 58 59 def hide(self): 60 vim.command("sign unplace %d" % self.id) 61 pass 62 63 class BreakpointSign(VimSign): 64 def __init__(self, buffer, line_number, is_resolved): 65 txt = VimSign.SIGN_TEXT_BREAKPOINT_RESOLVED if is_resolved else VimSign.SIGN_TEXT_BREAKPOINT_UNRESOLVED 66 super(BreakpointSign, self).__init__(txt, buffer, line_number) 67 68 class PCSign(VimSign): 69 def __init__(self, buffer, line_number, is_selected_thread): 70 super(PCSign, self).__init__(VimSign.SIGN_TEXT_PC, 71 buffer, 72 line_number, 73 VimSign.SIGN_HIGHLIGHT_COLOUR_PC if is_selected_thread else None) 74