Skip to content

Commit

Permalink
fix: ensure all of stdout can be collected
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin committed Apr 3, 2024
1 parent dd8889d commit 541e990
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 82 deletions.
27 changes: 10 additions & 17 deletions lua/vgit/core/ReadStream.lua → lua/vgit/core/Spawn.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local loop = require('vgit.core.loop')
local Object = require('vgit.core.Object')

local ReadStream = Object:extend()
local Spawn = Object:extend()

function ReadStream:constructor(spec) return { spec = spec } end
function Spawn:constructor(spec) return { spec = spec } end

function ReadStream:is_background() return self.spec.is_background == true end

function ReadStream:parse_result(output, callback)
function Spawn:parse_result(output, callback)
if not callback then
return
end
Expand All @@ -25,17 +23,13 @@ function ReadStream:parse_result(output, callback)
line[#line + 1] = char
end
end
end

function ReadStream:wrap_callback(callback)
if self:is_background() then
return vim.schedule_wrap(callback)
if #line > 0 then
callback(table.concat(line))
end

return callback
end

function ReadStream:start()
function Spawn:start()
local stdout_result = {}
local stderr_result = {}
local stdout = vim.loop.new_pipe(false)
Expand All @@ -60,7 +54,6 @@ function ReadStream:start()
if not stdout:is_closing() then
stdout:close()
end

if not stderr:is_closing() then
stderr:close()
end
Expand All @@ -77,12 +70,12 @@ function ReadStream:start()
args = self.spec.args,
stdio = { nil, stdout, stderr },
cwd = self.spec.cwd,
}, self:wrap_callback(on_exit))
}, on_exit)

stdout:read_start(self:wrap_callback(on_stdout))
stderr:read_start(self:wrap_callback(on_stderr))
stdout:read_start(on_stdout)
stderr:read_start(on_stderr)

return self
end

return ReadStream
return Spawn
1 change: 1 addition & 0 deletions lua/vgit/features/screens/HistoryScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function HistoryScreen:show()
end

-- Show and bind data (data will have all the necessary shape required)
loop.free_textlock()
self.diff_view:define()
self.table_view:define()

Expand Down
22 changes: 0 additions & 22 deletions lua/vgit/git/GitReadStream.lua

This file was deleted.

Loading

0 comments on commit 541e990

Please sign in to comment.