Skip to content

Commit

Permalink
Fix/pre script output error (#198)
Browse files Browse the repository at this point in the history
* feat(style): Standardize the code format

* fix(scripts): pre script output remove error

---------

Co-authored-by: xiaojianzhneg <[email protected]>
  • Loading branch information
iamxiaojianzheng and xiaojianzhneg authored Aug 31, 2024
1 parent 9f31a39 commit 91b3a7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lua/kulala/parser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,6 @@ function M.parse(start_request_linenr)
FS.delete_file(GLOBALS.HEADERS_FILE)
FS.delete_file(GLOBALS.BODY_FILE)
FS.delete_file(GLOBALS.COOKIES_JAR_FILE)
FS.delete_file(GLOBALS.SCRIPT_PRE_OUTPUT_FILE)
FS.delete_file(GLOBALS.SCRIPT_POST_OUTPUT_FILE)
if CONFIG.get().debug then
FS.write_file(PLUGIN_TMP_DIR .. "/request.txt", table.concat(res.cmd, " "), false)
end
Expand Down
17 changes: 13 additions & 4 deletions lua/kulala/scripts/javascript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,33 @@ M.run = function(type, data)
})
:wait()
if output ~= nil then
local script_pre_output_file = GLOBALS.SCRIPT_PRE_OUTPUT_FILE
FS.delete_file(script_pre_output_file)
local script_post_output_file = GLOBALS.SCRIPT_POST_OUTPUT_FILE
FS.delete_file(script_post_output_file)

if output.stderr ~= nil and not string.match(output.stderr, "^%s*$") then
if not CONFIG.get().disable_script_print_output then
vim.print(output.stderr)
end
if type == "pre_request" then
FS.write_file(GLOBALS.SCRIPT_PRE_OUTPUT_FILE, output.stderr, false)
FS.write_file(script_pre_output_file, output.stderr)
elseif type == "post_request" then
FS.write_file(GLOBALS.SCRIPT_POST_OUTPUT_FILE, output.stderr, false)
FS.write_file(script_post_output_file, output.stderr)
end
end
if output.stdout ~= nil and not string.match(output.stdout, "^%s*$") then
if not CONFIG.get().disable_script_print_output then
vim.print(output.stdout)
end
if type == "pre_request" then
FS.write_file(GLOBALS.SCRIPT_PRE_OUTPUT_FILE, output.stdout, false)
if not FS.write_file(script_pre_output_file, output.stdout) then
vim.print("write " .. script_pre_output_file .. " fail")
end
elseif type == "post_request" then
FS.write_file(GLOBALS.SCRIPT_POST_OUTPUT_FILE, output.stdout, false)
if not FS.write_file(script_post_output_file, output.stdout) then
vim.print("write " .. script_post_output_file .. " fail")
end
end
end
end
Expand Down
10 changes: 6 additions & 4 deletions lua/kulala/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ M.open = function()
if not buffer_exists() then
open_buffer()
end
if CONFIG.get().default_view == "body" then

local default_view = CONFIG.get().default_view
if default_view == "body" then
M.show_body()
elseif CONFIG.get().default_view == "headers" then
elseif default_view == "headers" then
M.show_headers()
elseif CONFIG.get().default_view == "headers_body" then
elseif default_view == "headers_body" then
M.show_headers_body()
elseif CONFIG.get().default_view == "script_output" then
elseif default_view == "script_output" then
M.show_script_output()
elseif CONFIG.get().default_view == "stats" then
M.show_stats()
Expand Down

0 comments on commit 91b3a7f

Please sign in to comment.