SublimeANSI
SublimeANSI copied to clipboard
File change on disk causes jumbled content and unfixable state
First thanks for the plugin! :+1: I really appreciate being able to read colored log files in the same workflow as my regular editing/etc.
In my current use, I frequently leave a tab open with a log file at all times. But when the file changes on the disk and gets reloaded, the changes jumble up the content and get it into an invalid state that can't be fixed by toggling in/out of ANSI mode. (Closing and reopening the tab works, of course)
Is there an event you can tie into before a reload to revert the style? That's the first solution that comes to my mind, but I know from my limited plugin development that the Sublime API can leave a lot to be desired... If you can't detect reloads, this is way more challenging and probably not worth it, haha.
Hi, excellent job indeed, using it everyday! Witnessing the same bug here with the same conditions (log file always open in background)
@tdhsmith @nchaverou Are you guys still able to reproduce this issue?
To reproduce it:
- Open "ansi_test_file.txt" in sublime
- Set ANSI sytax
- Open the same file in other editor, add some spaces and save
I couldn't find how to detect file reloading. Any idea?
This is a horribly broken hack, but it was the best I could come up with for detecting a file reload:
class AnsiEventListener(sublime_plugin.EventListener):
def on_activated(self, view):
if view.settings().has("ansi_enabled"):
if view.is_loading():
sublime.message_dialog("Shit just hit the fan!")
Maybe someone else can come up with something better.
Another hack, this time based on trying to detect a change in the file's size:
class AnsiEventListener(sublime_plugin.EventListener):
def on_activated(self, view):
if view.settings().has("ansi_enabled"):
if view.settings().get("ansi_size") != view.size():
view.settings().set("ansi_size", view.size())
sublime.message_dialog("Shit just hit the fan!")
This could be a possible solution for log files.
on_activated
works only if view is in focus. I just finished patch for this issue using periodic callbacks and checking if there are any ansi codes in view.
I just find out, that reloading file fires view.settings()
on_change, however it doesn't find new ansi codes immediately after.
We can add sublime.set_timeout_async
and then look for ANSI codes. What do you think?
Hey, that's not a bad idea! You should probably also use view.is_loaded()
in combination with the sublime.set_timeout_async
callback. I did like you solution with the periodic callback function, but this would be a much better solution.