Skip to content

Commit

Permalink
Make progress show a name of current operation (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Mar 21, 2020
1 parent 9b3e6e7 commit 7da0159
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
30 changes: 17 additions & 13 deletions plugin/utils/progress_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class BaseProgressStatus(object):
"""A base class for progress status."""

MSG_TAG = '000_ECC'
MSG_MASK = 'ECC: [{}]'
MSG_MASK = ' | {msg} |'
PROGRESS_MASK = 'ECC: [{progress}]'
FULL_MASK = PROGRESS_MASK + MSG_MASK

def __init__(self):
"""Initialize progress status."""
Expand All @@ -39,14 +41,14 @@ def erase_status(self):
view = sublime.active_window().active_view()
view.erase_status(BaseProgressStatus.MSG_TAG)

def show_ready_message(self):
"""Show ready message."""
def show_as_ready(self):
"""Show ready state."""
if not self.showing:
return
BaseProgressStatus.set_status(
BaseProgressStatus.MSG_MASK.format(self.msg_ready))
BaseProgressStatus.PROGRESS_MASK.format(progress=self.msg_ready))

def show_next_message(self):
def update_progress(self, message=''):
"""Abstract method. Generate next message."""
raise NotImplementedError("abstract method is called")

Expand All @@ -61,15 +63,16 @@ def __init__(self):
self.msg_chars = MSG_CHARS_MOON
self.msg_ready = MSG_READY_MOON

def show_next_message(self):
"""Show next moon phase message."""
def update_progress(self, message):
"""Show next moon phase and a custom message."""
if not self.showing:
return
chars = self.msg_chars
mod = len(chars)
self.idx = (self.idx + 1) % mod
BaseProgressStatus.set_status(
BaseProgressStatus.MSG_MASK.format(chars[self.idx]))
BaseProgressStatus.FULL_MASK.format(
progress=chars[self.idx], msg=message))


class ColorSublimeProgressStatus(BaseProgressStatus):
Expand All @@ -81,15 +84,16 @@ def __init__(self):
self.msg_chars = MSG_CHARS_COLOR_SUBLIME
self.msg_ready = MSG_READY_COLOR_SUBLIME

def show_next_message(self):
"""Show next random progress message."""
def update_progress(self, message):
"""Show next random progress indicator and a custom message."""
if not self.showing:
return
from random import sample
mod = len(self.msg_chars)
rands = [self.msg_chars[x % mod] for x in sample(range(100), 10)]
BaseProgressStatus.set_status(
BaseProgressStatus.MSG_MASK.format(''.join(rands)))
BaseProgressStatus.FULL_MASK.format(
progress=''.join(rands), msg=message))


class NoneSublimeProgressStatus(BaseProgressStatus):
Expand All @@ -100,10 +104,10 @@ def __init__(self):
super().__init__()
self.showing = False

def show_ready_message(self):
def show_as_ready(self):
"""Empty implementation."""
pass

def show_next_message(self):
def update_progress(self, message):
"""Empty implementation."""
pass
7 changes: 5 additions & 2 deletions plugin/utils/singleton_thread_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, max_workers=1):
self.__progress_lock = Lock()

self.__show_animation = False
self.__current_operation_name = ''

self.__progress_update_delay = 0.1
self.__progress_idle_delay = 0.3
Expand Down Expand Up @@ -91,6 +92,7 @@ def new_job(self, job):
job.future = future # Set the future for this job.
with self.__lock:
self.__active_jobs.append(job)
self.__current_operation_name = job.name
self.__show_animation = True

def __on_job_done(self, future):
Expand All @@ -111,10 +113,11 @@ def __animate_progress(self):
if not self.__progress_status:
sleep_time = self.__progress_idle_delay
elif self.__show_animation:
self.__progress_status.show_next_message()
self.__progress_status.update_progress(
self.__current_operation_name)
sleep_time = self.__progress_update_delay
else:
self.__progress_status.show_ready_message()
self.__progress_status.show_as_ready()
sleep_time = self.__progress_idle_delay
# Allow some time for progress status to be updated.
time.sleep(sleep_time)
12 changes: 6 additions & 6 deletions plugin/utils/thread_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class ThreadJob:
args (object[]): Sequence of additional arguments for `function`.
"""

UPDATE_TAG = "update"
CLEAR_TAG = "clear"
COMPLETE_TAG = "complete"
COMPLETE_INCLUDES_TAG = "complete_includes"
GENERATE_DB_TAG = "generate_db"
INFO_TAG = "info"
UPDATE_TAG = "Updating translation unit"
CLEAR_TAG = "Clearing"
COMPLETE_TAG = "Completing"
COMPLETE_INCLUDES_TAG = "Competing includes"
GENERATE_DB_TAG = "Generating compilation database"
INFO_TAG = "Showing info"

def __init__(self, name, callback, function, args):
"""Initialize a job.
Expand Down

0 comments on commit 7da0159

Please sign in to comment.