def get_with_variable_text( self, context: Context, variable_text: str, candidate: Candidate ) -> typing.Tuple[str, Highlights]: text = variable_text highlights = [] if not context.with_highlights: text += (self._directory_marker if candidate['is_directory'] and not candidate['is_root'] else self._file_marker) if context.with_highlights and candidate['is_directory']: if candidate['is_root']: root_len = len_bytes(candidate['root_marker']) highlights = [ (f'{self.highlight_name}_root_marker', self.start, root_len), (f'{self.highlight_name}_root', self.start + root_len, len_bytes(candidate['word']) - root_len), ] else: highlights = [(f'{self.highlight_name}_directory', self.start, len_bytes(candidate['word']))] text += candidate['word'] return (self._truncate(text), highlights)
def get_with_highlights( self, context: Context, candidate: Candidate ) -> typing.Tuple[str, Highlights]: if candidate['is_selected']: return (str(self.vars['selected_icon']), [(f'{self.highlight_name}_selected', self.start, len_bytes(self.vars['selected_icon']))]) elif not os.access(str(candidate['action__path']), os.W_OK): return (str(self.vars['readonly_icon']), [(f'{self.highlight_name}_readonly', self.start, len_bytes(self.vars['readonly_icon']))]) return (' ' * self.vars['length'], [])
def get_with_highlights( self, context: Context, candidate: Candidate) -> typing.Tuple[str, Highlights]: candidate_path = candidate['action__path'] if candidate['is_selected']: return (str(self.vars['selected_icon']), [(f'{self.highlight_name}_selected', self.start, len_bytes(self.vars['selected_icon']))]) elif (candidate['is_root'] and not candidate_path.is_dir()): return (str(self.vars['readonly_icon']), [(f'{self.highlight_name}_readonly', self.start, len_bytes(self.vars['readonly_icon']))]) return (' ' * self.vars['length'], [])
def item_hl(self, name, hi_group) -> None: icon = format(self.icons[name], f'<{self.settings["column_length"]}') self.highlights[name] = ( icon, hi_group, len_bytes(icon) )
def get_with_highlights( self, context: Context, candidate: Candidate) -> typing.Tuple[str, Highlights]: if candidate['is_opened_tree']: return (self.vars['opened_icon'], [(f'{self.highlight_name}_opened_icon', self.start, len_bytes(self.vars['opened_icon']))]) elif candidate['is_root']: return (self.vars['root_icon'], [(f'{self.highlight_name}_root_icon', self.start, len_bytes(self.vars['root_icon']))]) elif candidate['is_directory']: return (self.vars['directory_icon'], [(f'{self.highlight_name}_directory_icon', self.start, len_bytes(self.vars['directory_icon']))]) return (' ', [])
def list_hl(self, list_name) -> None: self.highlights[list_name] = {} for name, opts in self.icons[list_name].items(): text = re.sub('[^A-Za-z]', '', name) icon = format(opts['icon'], f'<{self.settings["column_length"]}') self.highlights[list_name][name] = ( icon, text, len_bytes(icon) )
def get_with_highlights( self, context: Context, candidate: Candidate) -> typing.Tuple[str, Highlights]: for t in self.vars['types']: for glob in t['globs']: if not candidate['action__path'].match(glob): continue return (str(t['icon']), [(f"{self.highlight_name}_{t['name']}", self.start, len_bytes(t['icon']))]) return (' ' * self._length, [])
def _get_columns_text( self, context: Context, candidate: Candidate) -> typing.Tuple[str, Highlights]: texts: typing.List[str] = [] variable_texts: typing.List[str] = [] ret_highlights: typing.List[typing.Tuple[str, int, int]] = [] start = 0 for column in self._columns: if self._ns > 0: column.start = start if column.is_stop_variable: if variable_texts: variable_texts.append('') (text, highlights) = column.get_with_variable_text( context, ' '.join(variable_texts), candidate) texts.append(text) ret_highlights += highlights variable_texts = [] else: if column.has_get_with_highlights: (text, highlights) = column.get_with_highlights( context, candidate) ret_highlights += highlights else: # Note: For old columns compatibility text = column.get(context, candidate) if column.is_start_variable or column.is_within_variable: if text: variable_texts.append(text) else: texts.append(text) start = len_bytes(' '.join(texts)) if texts: start += 1 if variable_texts: start += len_bytes(' '.join(variable_texts)) + 1 return (' '.join(texts), ret_highlights)
def format(self, column: str, indicator_name) -> str: icon = format(column, f'<{self.column_length}') return (icon, [(f'{self.highlight_name}_{indicator_name}', self.start, len_bytes(icon))])