Esempio n. 1
0
 def on_hover(self, point, hover_zone):
     if hover_zone == sublime.HOVER_TEXT:
         delim = self.view.settings().get('rainbow_delim')
         policy = self.view.settings().get('rainbow_policy')
         if delim is None:
             return
         # lnum and cnum are 0-based
         lnum, cnum = self.view.rowcol(point)
         line_text = self.view.substr(self.view.line(point))
         hover_record, warning = rainbow_utils.smart_split(line_text, delim, policy, True)
         field_num = rainbow_utils.get_field_by_line_position(hover_record, cnum)
         header = get_document_header(self.view, delim, policy)
         ui_text = 'Col# {}'.format(field_num + 1)
         if field_num < len(header):
             column_name = header[field_num]
             max_header_len = 30
             if len(column_name) > max_header_len:
                 column_name = column_name[:max_header_len] + '...'
             ui_text += ', Header: "{}"'.format(column_name)
         if len(header) != len(hover_record):
             ui_text += '; WARN: num of fields in Header and this line differs'
         if warning:
             ui_text += '; This line has quoting error'
         ui_hex_color = rainbow_utils.color_entries[field_num % 10][1]
         self.view.show_popup('<span style="color:{}">{}</span>'.format(ui_hex_color, ui_text), sublime.HIDE_ON_MOUSE_MOVE_AWAY, point, on_hide=hover_hide_cb, max_width=1000)
Esempio n. 2
0
def is_delimited_table(sampled_lines, delim, policy):
    if len(sampled_lines) < 2:
        return False
    num_fields = None
    for sl in sampled_lines:
        fields, warning = rainbow_utils.smart_split(sl, delim, policy, True)
        if warning or len(fields) < 2:
            return False
        if num_fields is None:
            num_fields = len(fields)
        if num_fields != len(fields):
            return False
    return True
Esempio n. 3
0
def show_names_for_line(view, delim, policy, line_region):
    point = line_region.a
    line_text = view.substr(line_region)
    fields, warning = rainbow_utils.smart_split(line_text, delim, policy, True)
    tab_stop = view.settings().get('tab_size', 4) if delim == '\t' else 1
    layout_width_dip = view.layout_extent()[0]
    font_char_width_dip = view.em_width()
    dip_reserve = 10
    char_reserve = 2
    max_status_width = layout_width_dip - dip_reserve
    max_available_chars = max_status_width // font_char_width_dip - char_reserve

    status_labels = rainbow_utils.generate_tab_statusline(tab_stop, fields, max_available_chars)
    if not len(status_labels):
        return
    num_fields = len(status_labels) // 2
    html_text = ''
    for i in range(num_fields):
        hex_color = rainbow_utils.color_entries[i % 10][1]
        column_name = status_labels[i * 2]
        space_filling = status_labels[i * 2 + 1].replace(' ', '&nbsp;')
        html_text += '<span style="color:{}">{}{}</span>'.format(hex_color, column_name, space_filling)
    view.show_popup(html_text, location=point, max_width=max_status_width, max_height=100)
Esempio n. 4
0
def get_document_header(view, delim, policy):
    header_line = get_line_text(view, 0)
    return rainbow_utils.smart_split(header_line, delim, policy, False)[0]