mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
add telescope support
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||

|
||||
|
||||
With [telescope](https://github.com/nvim-telescope/telescope.nvim) support:
|
||||
|
||||

|
||||
|
||||
With [fzf](https://github.com/junegunn/fzf) support:
|
||||
|
||||

|
||||
|
||||
### Read message view
|
||||
|
||||

|
||||
|
||||
@@ -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
|
||||
@@ -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, ", ") . ": ")
|
||||
|
||||
@@ -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" ],
|
||||
|
||||
Reference in New Issue
Block a user