Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sumblime Text Plugin: Remove ANSI escape sequence from selected text
#######################################
# Sublime Text Plugin
# Remove ANSI Escape sequence from text
# Written by Giuseppe Mastrangelo
#
# select text and from console execute:
# view.run_command("remove_ansi_escape")
#######################################
import sublime
import sublime_plugin
import re
class RemoveAnsiEscapeCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
for region in selection:
region_text = self.view.substr(region)
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
cleaned_text = ansi_escape.sub('', region_text)
self.view.replace(edit, region, cleaned_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.