Skip to content

Commit 255dd41

Browse files
authored
add loading popup message #5 (#9)
add loading messsage
1 parent db14702 commit 255dd41

1 file changed

Lines changed: 102 additions & 48 deletions

File tree

lua/telescope/_extensions/gh_builtin.lua

Lines changed: 102 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ local finders = require('telescope.finders')
33
local previewers = require('telescope.previewers')
44
local pickers = require('telescope.pickers')
55
local conf = require('telescope.config').values
6+
local make_entry = require('telescope.make_entry')
7+
local utils = require('telescope.utils')
8+
local popup=require('popup')
69

10+
local log = require('telescope.log')
711
local gh_p= require('telescope._extensions.gh_previewers')
812
local gh_a= require('telescope._extensions.gh_actions')
913

@@ -30,76 +34,126 @@ local function parse_opts(opts,target)
3034
return query
3135
end
3236

37+
local function msgLoadingPopup(msg,cmd,complete_fn)
38+
local row = math.floor((vim.o.lines-5) / 2)
39+
local width = math.floor(vim.o.columns / 1.5)
40+
local col = math.floor((vim.o.columns - width) / 2)
41+
for _ = 1 , (width-#msg)/2 , 1 do
42+
msg = " "..msg
43+
end
44+
local prompt_win, prompt_opts = popup.create(msg, {
45+
border ={},
46+
borderchars = conf.borderchars ,
47+
height = 5,
48+
col = col,
49+
line = row,
50+
width = width,
51+
})
52+
vim.api.nvim_win_set_option(prompt_win, 'winhl', 'Normal:TelescopeNormal')
53+
vim.api.nvim_win_set_option(prompt_win, 'winblend', 0)
54+
local prompt_border_win = prompt_opts.border and prompt_opts.border.win_id
55+
if prompt_border_win then vim.api.nvim_win_set_option(prompt_border_win, 'winhl', 'Normal:TelescopePromptBorder') end
56+
vim.defer_fn(vim.schedule_wrap(function()
57+
local results = vim.split(utils.get_os_command_output(cmd), '\n')
58+
if not pcall(vim.api.nvim_win_close, prompt_win, true) then
59+
log.trace("Unable to close window: ", "ghcli", "/", prompt_win)
60+
end
61+
complete_fn(results)
62+
end),10)
63+
end
64+
3365
-- b for builtin function
3466
B.gh_issues = function(opts)
3567
opts = opts or {}
3668
opts.limit = opts.limit or 100
3769
local opts_query = parse_opts(opts , 'issue')
3870
local cmd = vim.tbl_flatten({'gh' , 'issue' , 'list', opts_query})
39-
pickers.new(opts , {
40-
prompt_title = 'Issues',
41-
finder = finders.new_oneshot_job(
42-
cmd,
43-
opts
44-
),
45-
previewer = previewers.new_termopen_previewer{
46-
get_command = function(entry)
47-
local tmp_table = vim.split(entry.value,"\t");
48-
if vim.tbl_isempty(tmp_table) then
49-
return {"echo", ""}
50-
end
51-
return { 'gh' ,'issue' ,'view',tmp_table[1] }
52-
end
53-
},
54-
sorter = conf.file_sorter(opts),
55-
attach_mappings = function(_,map)
56-
actions.goto_file_selection_edit:replace(actions.close)
57-
map('i','<c-t>',gh_a.gh_web_view('issue'))
58-
return true
71+
local title = 'Issues'
72+
msgLoadingPopup("Loading "..title, table.concat(cmd , ''), function (results)
73+
if results[1]== "" then
74+
print ('Empty ' .. title)
75+
return
5976
end
60-
}):find()
77+
pickers.new(opts , {
78+
prompt_title = title,
79+
finder = finders.new_table {
80+
results = results,
81+
entry_maker = make_entry.gen_from_string(opts),
82+
},
83+
previewer = previewers.new_termopen_previewer{
84+
get_command = function(entry)
85+
local tmp_table = vim.split(entry.value,"\t");
86+
if vim.tbl_isempty(tmp_table) then
87+
return {"echo", ""}
88+
end
89+
return { 'gh' ,'issue' ,'view',tmp_table[1] }
90+
end
91+
},
92+
sorter = conf.file_sorter(opts),
93+
attach_mappings = function(_,map)
94+
actions.goto_file_selection_edit:replace(actions.close)
95+
map('i','<c-t>',gh_a.gh_web_view('issue'))
96+
return true
97+
end
98+
}):find()
99+
end)
61100
end
62101

102+
63103
B.gh_pull_request = function(opts)
64104
opts = opts or {}
65105
opts.limit = opts.limit or 100
66106
local opts_query = parse_opts(opts , 'pr')
67107
local cmd = vim.tbl_flatten({'gh' , 'pr' , 'list' , opts_query})
68-
pickers.new(opts, {
69-
prompt_title = 'Pull Requests' ,
70-
finder = finders.new_oneshot_job(
71-
cmd,
72-
opts
73-
),
74-
previewer = gh_p.gh_pr_preview.new(opts) ,
75-
sorter = conf.file_sorter(opts),
76-
attach_mappings = function(_,map)
77-
actions.goto_file_selection_edit:replace(gh_a.gh_pr_checkout)
78-
map('i','<c-e>',gh_a.gh_pr_v_toggle)
79-
map('i','<c-t>',gh_a.gh_web_view('pr'))
80-
return true
108+
local title = 'Pull Requests'
109+
msgLoadingPopup("Loading "..title, table.concat(cmd , ' '), function(results)
110+
if results[1]== "" then
111+
print ('Empty ' .. title)
112+
return
81113
end
82-
}):find()
114+
pickers.new(opts, {
115+
prompt_title =title ,
116+
finder = finders.new_table {
117+
results = results,
118+
entry_maker = make_entry.gen_from_string(opts),
119+
},
120+
previewer = gh_p.gh_pr_preview.new(opts) ,
121+
sorter = conf.file_sorter(opts),
122+
attach_mappings = function(_,map)
123+
actions.goto_file_selection_edit:replace(gh_a.gh_pr_checkout)
124+
map('i','<c-e>',gh_a.gh_pr_v_toggle)
125+
map('i','<c-t>',gh_a.gh_web_view('pr'))
126+
return true
127+
end
128+
}):find()
129+
end)
83130
end
84131

85132
B.gh_gist = function(opts)
86133
opts = opts or {}
87134
opts.limit = opts.limit or 100
88135
local opts_query = parse_opts(opts , 'gist')
136+
local title = 'Gist'
89137
local cmd = vim.tbl_flatten({'gh' , 'gist' , 'list' , opts_query})
90-
pickers.new(opts, {
91-
prompt_title = 'gist list' ,
92-
finder = finders.new_oneshot_job(
93-
cmd,
94-
opts
95-
),
96-
previewer = gh_p.gh_gist_preview.new(opts),
97-
sorter = conf.file_sorter(opts),
98-
attach_mappings = function(_,map)
99-
actions.goto_file_selection_edit:replace(gh_a.gh_gist_append)
100-
map('i','<c-t>',gh_a.gh_web_view('gist'))
101-
return true
138+
msgLoadingPopup("Loading " .. title, table.concat(cmd,' '), function(results)
139+
if results[1]== "" then
140+
print ('Empty ' .. title)
141+
return
102142
end
103-
}):find()
143+
pickers.new(opts, {
144+
prompt_title = title ,
145+
finder = finders.new_table {
146+
results = results,
147+
entry_maker = make_entry.gen_from_string(opts),
148+
},
149+
previewer = gh_p.gh_gist_preview.new(opts),
150+
sorter = conf.file_sorter(opts),
151+
attach_mappings = function(_,map)
152+
actions.goto_file_selection_edit:replace(gh_a.gh_gist_append)
153+
map('i','<c-t>',gh_a.gh_web_view('gist'))
154+
return true
155+
end
156+
}):find()
157+
end)
104158
end
105159
return B

0 commit comments

Comments
 (0)