From 7fe2791dbfd14e859c8be13ba4557d2359362729 Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Tue, 17 Dec 2024 09:10:04 -0600 Subject: [PATCH 1/3] Base the theme on the current OS theme --- lua/peek/app.lua | 9 ++++++++- lua/peek/config.lua | 1 + lua/peek/util.lua | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lua/peek/util.lua diff --git a/lua/peek/app.lua b/lua/peek/app.lua index af5148e..8117d36 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 @@ -27,9 +28,15 @@ end function module.setup() local sep = vim.loop.os_uname().sysname:match('Windows') and '\\' or '/' + local theme = config.get('theme') + + if config.get('auto_os_theme') then + theme = util.get_theme() + 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/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 From 7dc99ee76d23b5b48d980b271bffd20263026bce Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Tue, 17 Dec 2024 09:18:02 -0600 Subject: [PATCH 2/3] Allow passing config to peek open --- lua/peek/app.lua | 7 ++++--- lua/peek/init.lua | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/peek/app.lua b/lua/peek/app.lua index 8117d36..d361e6f 100644 --- a/lua/peek/app.lua +++ b/lua/peek/app.lua @@ -26,11 +26,12 @@ 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 = config.get('theme') + local theme = cfg['theme'] or config.get('theme') - if config.get('auto_os_theme') then + if cfg['auto_os_theme'] or config.get('auto_os_theme') then theme = util.get_theme() end 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() From 2ea40273c2a0171d97354531655405a5ded6eb62 Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Wed, 18 Dec 2024 10:22:49 -0600 Subject: [PATCH 3/3] Fix util name --- lua/peek/app.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/peek/app.lua b/lua/peek/app.lua index d361e6f..8dce9e0 100644 --- a/lua/peek/app.lua +++ b/lua/peek/app.lua @@ -32,7 +32,7 @@ function module.setup(cfg) local theme = cfg['theme'] or config.get('theme') if cfg['auto_os_theme'] or config.get('auto_os_theme') then - theme = util.get_theme() + theme = util.get_color_scheme() end local args = {