Skip to content

Commit

Permalink
Fix compatibility with ST 3170
Browse files Browse the repository at this point in the history
It looks like the "data" parameter in the new "exec.py" is always a string in ST 3170.
  • Loading branch information
jfcherng committed May 9, 2018
1 parent fd29e06 commit d5ac09d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,17 @@ def clear_build_settings(self, settings):
self.process_trigger = None

def on_data_process(self, proc, data):
needDataCodec = True if int(sublime.version()) < 3170 else False

view = self.output_view
if not view.settings().get("syntax") == "Packages/ANSIescape/ANSI.tmLanguage":
super(AnsiColorBuildCommand, self).on_data(proc, data)
return

str_data = data.decode(self.encoding)
str_data = data

if needDataCodec:
str_data = str_data.decode(self.encoding)

# replace unsupported ansi escape codes before going forward: 2m 4m 5m 7m 8m
unsupported_pattern = r'\x1b\[(0;)?[24578]m'
Expand Down Expand Up @@ -399,8 +404,11 @@ def on_data_process(self, proc, data):
region.shift(shift_val)
json_ansi_regions.update(region.jsonable())

if needDataCodec:
out_data = out_data.encode(self.encoding)

# send on_data without ansi codes
super(AnsiColorBuildCommand, self).on_data(proc, out_data.encode(self.encoding))
super(AnsiColorBuildCommand, self).on_data(proc, out_data)

# send ansi command
view.run_command('ansi', args={"regions": json_ansi_regions})
Expand Down

0 comments on commit d5ac09d

Please sign in to comment.