Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite440df3

Browse files
committed
fix(dashboard): start job after the terminal window is shown to make sure it has the correct size.Closes#2421
1 parent3893cca commite440df3

File tree

1 file changed

+24
-35
lines changed

1 file changed

+24
-35
lines changed

‎lua/snacks/dashboard.lua‎

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,6 @@ function M.sections.terminal(opts)
961961
localheight,width=opts.heightor10,opts.widthor (self.opts.width- (opts.indentor0))
962962
localhl=opts.hlandhl_groups[opts.hl]oropts.hlor"SnacksDashboardTerminal"
963963
localcache_buf,term_buf,win---@typeinteger?,integer?,integer?
964-
localterm_ready=false
965964

966965
localcache_parts= {
967966
table.concat(type(cmd)=="table"andcmdor {cmd },""),
@@ -974,7 +973,7 @@ function M.sections.terminal(opts)
974973
localhas_cache=statandstat.type=="file"andstat.size>0
975974
localis_expired=has_cacheandstatandos.time()-stat.mtime.sec>=ttl
976975

977-
ifhas_cacheandnotcache_bufandstatthen
976+
ifhas_cacheandstatthen-- show cached output
978977
cache_buf=vim.api.nvim_create_buf(false,true)
979978
vim.bo[cache_buf].buftype="nofile"
980979
localfin=assert(uv.fs_open(cache_file,"r",438))
@@ -985,13 +984,9 @@ function M.sections.terminal(opts)
985984
vim.bo[cache_buf].scrollback=9998
986985
end
987986

988-
localfunctionget_buf()
989-
returnassert(term_readyandterm_buforcache_buf,"No terminal or cache buffer available")
990-
end
991-
992-
localfunctionset_buf()
987+
---@parambufinteger
988+
localfunctionshow(buf)
993989
ifwinandvim.api.nvim_win_is_valid(win)then
994-
localbuf=assert(term_readyandterm_buforcache_buf,"No terminal or cache buffer available")
995990
vim.api.nvim_win_set_buf(win,buf)
996991
Snacks.util.wo(win, {winhighlight="TermCursorNC:"..hl..",NormalFloat:"..hl })
997992
Snacks.util.bo(buf, {filetype=Snacks.config.styles.dashboard.bo.filetype })
@@ -1000,54 +995,43 @@ function M.sections.terminal(opts)
1000995

1001996
localjob---@typesnacks.Job?
1002997
ifnothas_cacheoris_expiredthen
1003-
term_ready,term_buf=nothas_cache,vim.api.nvim_create_buf(false,true)
998+
term_buf=vim.api.nvim_create_buf(false,true)
999+
localterm_ready=false
10041000
localoutput= {}---@typestring[]
1005-
localtimer=assert(uv.new_timer())
1006-
1007-
---@paramforceboolean?
1008-
localfunctionshow(force)
1009-
if
1010-
notforce
1011-
andvim.api.nvim_buf_is_valid(term_buf)
1012-
and#vim.tbl_filter(function(line)
1013-
returnline:match("%S")
1014-
end,vim.api.nvim_buf_get_lines(term_buf,0,-1,false))
1015-
<3
1016-
then
1017-
return
1018-
end
1019-
iftimer:is_active()then
1020-
timer:stop()
1021-
timer:close()
1022-
end
1023-
term_ready=true
1024-
set_buf()
1025-
end
1026-
timer:start(30,30,vim.schedule_wrap(show))
10271001

10281002
localrecording=vim.defer_fn(function()
10291003
output= {}
1030-
show(true)
1004+
show(term_buf)
10311005
end,5000)--[[@as uv.uv_timer_t]]
10321006

10331007
localJob=require("snacks.util.job")
10341008
job=Job.new(
10351009
term_buf,
10361010
cmd,
10371011
Snacks.config.merge({}, {
1012+
start=false,
10381013
term=true,
10391014
width=width,
10401015
height=height,
10411016
on_stdout=function(_,data)
10421017
ifrecording:is_active()then
10431018
table.insert(output,table.concat(data,"\n"))
10441019
end
1020+
ifnotterm_readyandjobthen
1021+
localnon_empty=#vim.tbl_filter(function(line)
1022+
returnline:match("%S")
1023+
end,job.lines)
1024+
ifnon_empty>=3then
1025+
term_ready=true
1026+
show(term_buf)
1027+
end
1028+
end
10451029
end,
10461030
on_exit=function(_,code)
10471031
ifjobandjob.killedthen
10481032
return
10491033
end
1050-
show(true)
1034+
show(term_buf)
10511035
ifrecording:is_active()andcode==0andttl>0then-- save the output
10521036
vim.fn.mkdir(cache_dir,"p")
10531037
localfout=assert(uv.fs_open(cache_file,"w",438))
@@ -1065,7 +1049,9 @@ function M.sections.terminal(opts)
10651049
label=notopts.titleandopts.labelornil,
10661050
render=function(_,pos)
10671051
self:trace("terminal.render")
1068-
win=vim.api.nvim_open_win(get_buf(),false, {
1052+
-- open the window with the terminal buffer if available.
1053+
-- This is to ensure it starts with the correct window size.
1054+
win=vim.api.nvim_open_win(assert(term_buforcache_buf),false, {
10691055
bufpos= {pos[1]-1,pos[2]+1 },
10701056
col=opts.indentor0,
10711057
focusable=false,
@@ -1079,7 +1065,10 @@ function M.sections.terminal(opts)
10791065
win=self.win,
10801066
border="none",
10811067
})
1082-
set_buf()
1068+
ifjobthen-- start the job if needed
1069+
job:start()
1070+
end
1071+
show(assert(cache_buforterm_buf))-- set the correct buffer
10831072
localclose=vim.schedule_wrap(function()
10841073
ifjobthen
10851074
job:stop()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp