Skip to content

Commit

Permalink
fix: winbar + default_view (#141)
Browse files Browse the repository at this point in the history
closes #139
  • Loading branch information
gorillamoe authored Aug 15, 2024
1 parent 601bf6f commit a578d95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local FS = require("kulala.utils.fs")

local M = {}

M.VERSION = "3.1.3"
M.VERSION = "3.1.4"
M.UI_ID = "kulala://ui"
M.SCRATCHPAD_ID = "kulala://scratchpad"
M.HEADERS_FILE = FS.get_plugin_tmp_dir() .. "/headers.txt"
Expand Down
39 changes: 16 additions & 23 deletions lua/kulala/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,10 @@ M.open = function()
end
if CONFIG.get().default_view == "body" then
M.show_body()
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "body")
end
elseif CONFIG.get().default_view == "headers" then
M.show_headers()
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers")
end
else
elseif CONFIG.get().default_view == "headers_body" then
M.show_headers_body()
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers_body")
end
end
end
end)
Expand Down Expand Up @@ -207,6 +198,10 @@ M.show_body = function()
body = FORMATTER.format(contenttype.formatter, body)
end
set_buffer_contents(body, contenttype.ft)
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "body")
end
CONFIG.options.default_view = "body"
else
vim.notify("No body found", vim.log.levels.WARN)
end
Expand All @@ -220,6 +215,10 @@ M.show_headers = function()
local h = FS.read_file(GLOBALS.HEADERS_FILE)
h = h:gsub("\r\n", "\n")
set_buffer_contents(h, "text")
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers")
end
CONFIG.options.default_view = "headers"
else
vim.notify("No headers found", vim.log.levels.WARN)
end
Expand All @@ -238,6 +237,10 @@ M.show_headers_body = function()
body = FORMATTER.format(contenttype.formatter, body)
end
set_buffer_contents(h .. "\n" .. body, contenttype.ft)
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers_body")
end
CONFIG.options.default_view = "headers_body"
else
vim.notify("No headers or body found", vim.log.levels.WARN)
end
Expand All @@ -260,14 +263,10 @@ M.replay = function()
end
if CONFIG.get().default_view == "body" then
M.show_body()
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "body")
end
else
elseif CONFIG.get().default_view == "headers" then
M.show_headers()
if CONFIG.get().winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers")
end
elseif CONFIG.get().default_view == "headers_body" then
M.show_headers_body()
end
end
end)
Expand All @@ -291,14 +290,8 @@ M.toggle_headers = function()
CONFIG.set(cfg)
if cfg.default_view == "body" then
M.show_body()
if cfg.winbar then
WINBAR.toggle_winbar_tab(get_win(), "body")
end
else
M.show_headers()
if cfg.winbar then
WINBAR.toggle_winbar_tab(get_win(), "headers")
end
end
end

Expand Down
17 changes: 13 additions & 4 deletions lua/kulala/ui/winbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ end
M.winbar_set_key_mapping = function(buf)
if buf then
vim.keymap.set("n", "B", function()
require("kulala.ui").toggle_headers()
require("kulala.ui").show_body()
end, { silent = true, buffer = buf })
vim.keymap.set("n", "H", function()
require("kulala.ui").toggle_headers()
require("kulala.ui").show_headers()
end, { silent = true, buffer = buf })
vim.keymap.set("n", "A", function()
require("kulala.ui").show_headers_body()
end, { silent = true, buffer = buf })
end
end
Expand All @@ -28,13 +31,19 @@ M.toggle_winbar_tab = function(win_id, view)
if view == "body" then
vim.api.nvim_set_option_value(
"winbar",
"%#KulalaTabSel# Body (B) %* %#KulalaTab# Headers (H) %* ",
"%#KulalaTabSel# Body (B) %* %#KulalaTab# Headers (H) %* %#KulalaTab# All (A) %* ",
{ win = win_id }
)
elseif view == "headers" then
vim.api.nvim_set_option_value(
"winbar",
"%#KulalaTab# Body (B) %* %#KulalaTabSel# Headers (H) %* ",
"%#KulalaTab# Body (B) %* %#KulalaTabSel# Headers (H) %* %#KulalaTab# All (A) %* ",
{ win = win_id }
)
elseif view == "headers_body" then
vim.api.nvim_set_option_value(
"winbar",
"%#KulalaTab# Body (B) %* %#KulalaTab# Headers (H) %* %#KulalaTabSel# All (A) %* ",
{ win = win_id }
)
end
Expand Down

0 comments on commit a578d95

Please sign in to comment.