add telescope support

This commit is contained in:
Clément DOUIN 2021-04-05 23:57:01 +02:00
parent e54efced2d
commit 442dc457b5
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
5 changed files with 50 additions and 5 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Telescope support [#61]
## [0.2.2] - 2021-04-04
### Added
@ -113,3 +117,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#39]: https://github.com/soywod/himalaya/issues/39
[#40]: https://github.com/soywod/himalaya/issues/40
[#41]: https://github.com/soywod/himalaya/issues/41
[#61]: https://github.com/soywod/himalaya/issues/61

View file

@ -10,6 +10,7 @@ Vim plugin for [Himalaya](https://github.com/soywod/himalaya) CLI email client.
* [Installation](#installation)
* [Usage](#usage)
* [List messages view](#list-messages-view)
* [List mailboxes](#list-mailboxes)
* [Read message view](#read-message-view)
* [Write message view](#write-message-view)
* [License](https://github.com/soywod/himalaya.vim/blob/master/LICENSE)
@ -81,6 +82,20 @@ nmap gf <plug>(himalaya-msg-forward)
nmap ga <plug>(himalaya-msg-attachments)
```
### List mailboxes
Default behaviour (basic prompt):
![screenshot](https://user-images.githubusercontent.com/10437171/113631817-51eb3180-966a-11eb-8b13-cd1f1f2539ab.jpeg)
With [telescope](https://github.com/nvim-telescope/telescope.nvim) support:
![screenshot](https://user-images.githubusercontent.com/10437171/113631294-86122280-9669-11eb-8074-1c43c36b65a9.jpeg)
With [fzf](https://github.com/junegunn/fzf) support:
![screenshot](https://user-images.githubusercontent.com/10437171/113631382-acd05900-9669-11eb-817d-c28fd5d9574c.jpeg)
### Read message view
![gif](https://user-images.githubusercontent.com/10437171/110708073-7b937300-81fa-11eb-9f4c-5472cea22e21.gif)

View file

@ -0,0 +1,22 @@
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local pickers = require('telescope.pickers')
local sorters = require('telescope.sorters')
function mbox_picker(mboxes)
pickers.new {
results_title = 'Mailboxes',
finder = finders.new_table(mboxes),
sorter = sorters.fuzzy_with_index_bias(),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.fn['himalaya#mbox#post_input'](selection.display)
end)
return true
end,
}:find()
end

View file

@ -1,3 +1,4 @@
let s:dir = expand("<sfile>:h")
let s:cli = function("himalaya#shared#cli#call")
" Pagination
@ -27,12 +28,18 @@ endfunction
function! himalaya#mbox#input()
try
let mboxes = map(s:cli("mailboxes", [], "Fetching mailboxes"), "v:val.name")
if &rtp =~ "fzf"
if &rtp =~ "telescope"
execute printf("luafile %s/mbox.lua", s:dir)
call luaeval(printf("mbox_picker({%s})", join(map(mboxes, "string(v:val)"), ", ")))
else if &rtp =~ "fzf"
call fzf#run({
\"source": mboxes,
\"sink": function("himalaya#mbox#post_input"),
\"down": "25%",
\})
else
let choice = map(copy(mboxes), "printf('%s (%d)', v:val, v:key)")
let choice = input(join(choice, ", ") . ": ")

View file

@ -4,10 +4,6 @@ setlocal nomodifiable
setlocal nowrap
setlocal startofline
nnoremap <buffer><silent>q :bwipeout<cr>
nnoremap <buffer><silent><cr> :bwipeout<cr>
nnoremap <buffer><silent><esc> :bwipeout<cr>
call himalaya#shared#bindings#define([
\["n", "gm" , "mbox#input" ],
\["n", "gp" , "mbox#prev_page" ],