diff --git a/lua/peek/app.lua b/lua/peek/app.lua index af5148e..8dce9e0 100644 --- a/lua/peek/app.lua +++ b/lua/peek/app.lua @@ -1,4 +1,5 @@ local config = require('peek.config') +local util = require('peek.util') local chansend = vim.fn.chansend local concat = table.concat @@ -25,11 +26,18 @@ local function message(chunks) end, chunks)) end -function module.setup() +function module.setup(cfg) + local cfg = cfg or {} local sep = vim.loop.os_uname().sysname:match('Windows') and '\\' or '/' + local theme = cfg['theme'] or config.get('theme') + + if cfg['auto_os_theme'] or config.get('auto_os_theme') then + theme = util.get_color_scheme() + end + local args = { '--logfile=' .. string.format('%s%speek.log', vim.fn.stdpath('log'), sep), - '--theme=' .. config.get('theme'), + '--theme=' .. theme, '--app=' .. vim.json.encode(config.get('app')), } diff --git a/lua/peek/config.lua b/lua/peek/config.lua index 15ca57e..44af244 100644 --- a/lua/peek/config.lua +++ b/lua/peek/config.lua @@ -5,6 +5,7 @@ local config = { close_on_bdelete = true, syntax = true, theme = 'dark', + auto_os_theme = false, update_on_change = true, throttle_at = 200000, throttle_time = 'auto', diff --git a/lua/peek/init.lua b/lua/peek/init.lua index 3378d3c..4aa2f96 100644 --- a/lua/peek/init.lua +++ b/lua/peek/init.lua @@ -17,7 +17,8 @@ local function get_buf_content(bufnr) return concat(nvim_buf_get_lines(bufnr, 0, -1, false), '\n'):gsub('%s*$', '') end -local function open(bufnr) +local function open(bufnr, cfg) + app.setup(cfg) augroup = nvim_create_augroup('PeekActiveAugroup', { clear = true }) app.init(function() diff --git a/lua/peek/util.lua b/lua/peek/util.lua new file mode 100644 index 0000000..18c7c96 --- /dev/null +++ b/lua/peek/util.lua @@ -0,0 +1,19 @@ +local M = {} + +local function get_color_scheme() + local color_scheme = 'light' + local system = vim.loop.os_uname().sysname + if system == 'Darwin' then + if vim.fn.executable('defaults') ~= 0 then + local appleInterfaceStyle = vim.fn.system({ 'defaults', 'read', '-g', 'AppleInterfaceStyle' }) + if appleInterfaceStyle:find('Dark') then + color_scheme = 'dark' + end + end + end + + return color_scheme +end + +M.get_color_scheme = get_color_scheme +return M