Skip to content

Commit

Permalink
prep for optional variables for status_bar text
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminalFi committed Jun 22, 2024
1 parent 8e2e468 commit 0cbb74d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,22 @@ def is_valid_for_view(self, view: sublime.View) -> bool:
session = self.weaksession()
return bool(session and session.session_view_for_view_async(view))

def update_status_bar_text(self) -> None:
def update_status_bar_text(self, variables: dict[str, Any] | None = None) -> None:
if not (session := self.weaksession()):
return

variables: dict[str, Any] = {
resolved_variables: dict[str, Any] = {
"server_version": self.server_version,
"server_version_gh": self.server_version_gh,
}

if variables:
resolved_variables.update(variables)

rendered_text = ""
if template_text := str(session.config.settings.get("status_text") or ""):
try:
rendered_text = render_template(template_text, variables)
rendered_text = render_template(template_text, resolved_variables)
except Exception as e:
log_warning(f'Invalid "status_text" template: {e}')
session.set_config_status_async(rendered_text)
Expand Down

0 comments on commit 0cbb74d

Please sign in to comment.