def _transform_line(self, ti): if len(list(ti.fragments)) == 0: return Transformation(ti.fragments) style, text = list(ti.fragments)[0] item = self._items[ti.lineno] s = self._style # cursor indent = '' prefix = '' if item.focusable: indent += ' ' * self._option_indent if ti.lineno == self._pos: prefix += '{} '.format(self._cursor) style = s.highlight_style else: prefix += ' ' * (len(self._cursor) + 1 + 1 * self._dedent_selection) style = s.option_style else: if item.indent: indent += ' ' * (self._header_indent + len(self._cursor) + 1) style = s.header_style items = [(s if s else style, t) for s, t in ti.fragments] prefix = self._transform_prefix(item, ti.lineno, prefix) return Transformation([('', indent), (style, prefix)] + items)
def apply_transformation(self, ti): try: fragments = to_formatted_text( HTML(fragment_list_to_text(ti.fragments))) return Transformation(fragments) except Exception: return Transformation(ti.fragments)
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): if (lineno < self._lines_before or lineno >= self._lines_before + len(self.history_mapping.selected_lines)): text = token_list_to_text(tokens) return Transformation(tokens=[(Token.History.ExistingInput, text)]) else: return Transformation(tokens=tokens)
def apply_transformation(self, transformation_input): lineno = transformation_input.lineno fragments = transformation_input.fragments if (lineno < self._lines_before or lineno >= self._lines_before + len(self.history_mapping.selected_lines)): text = fragment_list_to_text(fragments) return Transformation(fragments=[('class:history.existing-input', text)]) else: return Transformation(fragments=fragments)
def apply_transformation(self, ti): try: fragments = to_formatted_text( HTML(fragment_list_to_text(ti.fragments))) except Exception as ex: # xml.parsers.expat.ExpatError # not well-formed (invalid token): line 1, column 138 logger.error('FormatText: {} {}'.format(type(ex), str(ex))) #return Transformation([('', ' ')]) return Transformation([]) return Transformation(fragments)
def apply_transformation(self, ti: TransformationInput) -> Transformation: # last line and cursor at end if ti.lineno == ti.document.line_count - 1 and ti.document.is_cursor_at_the_end: buffer = ti.buffer_control.buffer if not buffer.suggestion: input_ = ti.document.text suggestions = self.command_manager.suggest_command( input_, ConsoleSuggestionCommandSource()) if suggestions.complete_hint is not None: return Transformation( fragments=ti.fragments + [('class:auto-suggestion', suggestions.complete_hint)]) return Transformation(fragments=ti.fragments)
def apply_transformation(self, cli, document, tokens): if self._len_before or self._len_after: tokens = explode_tokens(tokens) pos_after = len(tokens) - self._len_after text_before = ''.join(t[1] for t in tokens[:self._len_before]) text_after = ''.join(t[1] for t in tokens[pos_after:]) return Transformation( document=document, tokens=explode_tokens([(Token.History.ExistingInput, text_before)] + tokens[self._len_before:pos_after] + [(Token.History.ExistingInput, text_after)])) else: return Transformation(document, tokens)
def apply_transformation( self, ti: TransformationInput) -> Transformation: if len(ti.document.text) == 0: session.has_complete_this_line = False if buff.complete_state is not None: session.has_complete_this_line = True return Transformation(fragments=ti.fragments)
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): if lineno == 0: return super(Prompt, self).apply_transformation(cli, document, lineno, source_to_display, tokens) return Transformation(tokens)
def apply_transformation(self, transformation_input): ( buffer_control, document, lineno, source_to_display, fragments, _, _, ) = transformation_input.unpack() if self.selected_entries and not get_app().is_done: # For each search match, replace the style string. line_text = fragment_list_to_text(fragments) fragments = explode_text_fragments(fragments) pattern = "|".join(re.escape(key) for key in self.selected_entries) matches = re.finditer(pattern, line_text, flags=re.RegexFlag(0)) for match in matches: for i in range(match.start(), match.end()): old_fragment, text, *_ = fragments[i] fragments[i] = ( old_fragment + self.match_fragment, fragments[i][1], ) return Transformation(fragments)
def apply_transformation(self, transformation_input): tokens = list(transformation_input.fragments) row = transformation_input.lineno + 1 if row in self.variables: tokens.append( ("class:title", " // {}".format(self.variables[row]))) return Transformation(tokens)
def apply_transformation(self, cli, document, tokens): tabstop = self.editor.tabstop # Create separator for tabs. if self.editor.display_unprintable_characters: dots = '\u2508' separator = dots * tabstop token = Token.Tab else: separator = ' ' * tabstop token = None # Don't replace the token. # Remember the positions where we replace the tab. positions = set() # Replace tab by separator. for i, value in enumerate(tokens): if value[1] == '\t': positions.add(i-1) tokens[i] = (token or tokens[i][0], separator) def source_to_display(from_position): """ Maps original cursor position to the new one. """ count = len(list(p for p in positions if p < from_position -1)) return from_position + count * (tabstop - 1) def display_to_source(display_pos): return display_pos # XXX return Transformation( document, tokens, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): if self.mask is not None: tokens = [(token, self.mask * len(text)) for token, text in tokens] else: tokens = [(Token.Hidden, '[input is hidden]')] return Transformation(tokens)
def apply_transformation(self, cli, document, tokens): if self.editor_buffer.report_errors: for error in self.editor_buffer.report_errors: for i in range(error.start_index, error.end_index): if i < len(tokens): tokens[i] = (Token.FlakesError, tokens[i][1]) return Transformation(document, tokens)
def apply_transformation(self, ti: TransformationInput) -> Transformation: input_text = ti.document.text default_transformation = Transformation(ti.fragments) try: command, _ = split_command_args(input_text) except (InvalidArguments, AmbiguousCommand): return default_transformation if command.upper() != "AUTH": return default_transformation fragments = [] for style, text, *handler in ti.fragments: if style == "class:password": fragments.append((style, self.char * len(text), *handler)) else: fragments.append((style, text, *handler)) return Transformation(fragments)
def apply_transformation(self, transformation_input): formatted_lines = transformation_input.buffer_control.formatted_lines lineno = transformation_input.lineno max_lineno = len(formatted_lines) - 1 if lineno > max_lineno: line = "" else: line = formatted_lines[lineno] return Transformation(to_formatted_text(line))
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): transformed = [] for token, text in tokens: token = Token.Prompt.Transformed text = self.transformer(text) if isinstance(text, (list, tuple)): token, text = text transformed.append((token, text)) return Transformation(transformed)
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): if self.editor_buffer.report_errors: for error in self.editor_buffer.report_errors: if error.lineno == lineno: tokens = explode_tokens(tokens) for i in range(error.start_column, error.end_column): if i < len(tokens): tokens[i] = (Token.FlakesError, tokens[i][1]) return Transformation(tokens)
def apply_transformation( self, transformation_input: TransformationInput) -> Transformation: input_text = transformation_input.document.text try: command, _ = split_command_args(input_text) except (InvalidArguments, AmbiguousCommand): self.command_holder.command = None else: self.command_holder.command = command.upper() return Transformation(transformation_input.fragments)
def apply_transformation(self, transformation_input): fragments = transformation_input.fragments if self.editor_buffer.report_errors: for error in self.editor_buffer.report_errors: if error.lineno == transformation_input.lineno: fragments = explode_text_fragments(fragments) for i in range(error.start_column, error.end_column): if i < len(fragments): fragments[i] = ('class:flakeserror', fragments[i][1]) return Transformation(fragments)
def apply_transformation( self, transformation_input: TransformationInput) -> Transformation: input_text = transformation_input.document.text if input_text != self.last_text: try: command, _ = split_command_args(input_text, all_commands) except InvalidArguments: self.command_holder.command = None else: self.command_holder.command = command.upper() self.last_text = input_text return Transformation(transformation_input.fragments)
def apply_transformation(self, transformation_input): formatted_lines = transformation_input.buffer_control.formatted_lines lineno = transformation_input.lineno max_lineno = len(formatted_lines) - 1 if lineno > max_lineno: log.warning( "Index error when parsing document. max_lineno=%s lineno=%s", max_lineno, lineno, ) lineno = max_lineno line = formatted_lines[lineno] return Transformation(to_formatted_text(line))
def apply_transformation(self, cli, document, lineno, source_to_display, tokens): if callable(self.hint): before = self.hint(cli) else: before = [ (Token.Prompt.Hint, '%s' % self.hint), (Token.Space, ' '), ] shift_position = token_list_len(before) return Transformation( tokens=before + tokens, source_to_display=lambda i: i + shift_position, display_to_source=lambda i: i - shift_position, )
def apply_transformation( self, transformation_input: TransformationInput ) -> Transformation: input_text = transformation_input.document.text if input_text != self.last_text: logger.debug(f"[Processor] {transformation_input.document}") try: command, _ = split_command_args(input_text, all_commands) except InvalidArguments: logger.debug(f"[Processor] Redis command not recongnised!") self.command_holder.command = None else: logger.debug(f"[Processor] Redis command: {command}") self.command_holder.command = command.upper() self.last_text = input_text return Transformation(transformation_input.fragments)
def apply_transformation(self, ti): len_frag = fragment_list_len(ti.fragments) if len_frag >= 2: fragments_before = to_formatted_text(ti.fragments[0][1][:2], self.style) fragments = fragments_before fragments += [(ti.fragments[0][0], ti.fragments[0][1][2:])] fragments += ti.fragments[1:] else: fragments = ti.fragments source_to_display = lambda i: i display_to_source = lambda i: i return Transformation(fragments, source_to_display=source_to_display, display_to_source=display_to_source)
def apply_transformation( self, transformation_input: TransformationInput) -> Transformation: input_text = transformation_input.document.text try: command, _ = split_command_args(input_text, all_commands) except InvalidArguments: self.command_holder.command = None self.session.completer = default_completer self.session.lexer = default_lexer else: self.command_holder.command = command.upper() # compile grammar for this command grammar = get_command_grammar(command) lexer = GrammarLexer(grammar, lexers=lexers_mapping) completer = GrammarCompleter(grammar, completer_mapping) self.session.completer = completer self.session.lexer = lexer return Transformation(transformation_input.fragments)
def apply_transformation(self, document, lineno, source_to_display, tokens): return Transformation(tokens)
def apply_transformation(self, ti): fragments = to_formatted_text(ANSI(fragment_list_to_text(ti.fragments))) return Transformation(fragments)
def apply_transformation(self, transformation_input): try: line = self.terminal.styled_lines[transformation_input.lineno] except IndexError: line = [] return Transformation(line)
def apply_transformation(self, cli, document, tokens): return Transformation(document, self.arrangement_pane.copy_token_list[:])