1
0
mirror of https://github.com/jiriks74/presence.nvim synced 2024-11-23 20:37:50 +01:00

Support functions in text formatting options

This commit is contained in:
Andrew Kwon 2021-02-28 20:32:10 -08:00
parent a15aed569a
commit f3e79afaa6

@ -12,7 +12,6 @@ function Presence:setup(options)
-- Initialize logger -- Initialize logger
self:set_option("log_level", "warn", false) self:set_option("log_level", "warn", false)
self.log = log:init({ level = options.log_level }) self.log = log:init({ level = options.log_level })
self:check_dup_options("log_level")
-- Use the default or user-defined client id if provided -- Use the default or user-defined client id if provided
if options.client_id then if options.client_id then
@ -338,8 +337,13 @@ function Presence:update_for_buffer(buffer)
small_text = use_file_as_main_image and neovim_image_text or file_text, small_text = use_file_as_main_image and neovim_image_text or file_text,
} }
local editing_text = self.options.editing_text
editing_text = type(editing_text) == "function"
and editing_text(filename, buffer)
or string.format(editing_text, filename)
local activity = { local activity = {
state = string.format(self.options.editing_text, filename), state = editing_text,
assets = assets, assets = assets,
timestamps = { timestamps = {
start = started_at start = started_at
@ -350,7 +354,12 @@ function Presence:update_for_buffer(buffer)
local project_name = self:get_project_name(parent_dirpath) local project_name = self:get_project_name(parent_dirpath)
if project_name then if project_name then
self.log:debug(string.format("Detected project: %s", project_name)) self.log:debug(string.format("Detected project: %s", project_name))
activity.details = string.format(self.options.workspace_text, project_name)
local workspace_text = self.options.workspace_text
activity.details = type(workspace_text) == "function"
and workspace_text(project_name, buffer)
or string.format(workspace_text, project_name)
else else
self.log:debug("No project detected") self.log:debug("No project detected")
end end