Skip to content

Commit

Permalink
feat: change telescope prompt theme
Browse files Browse the repository at this point in the history
  • Loading branch information
FeiyouG committed Oct 7, 2022
1 parent 7f7f86d commit 63d1952
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 131 deletions.
201 changes: 97 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,30 @@ and search them quickly through Telescope.
[breaking changes](https://github.com/FeiyouG/command_center.nvim/issues/4)
for `command_center.nvim`.


## Table of Contents

<!-- TOC GFM -->

- [Install](#install)
- [vim-plug](#vim-plug)
- [Packer](#packer)
- [Use](#use)
- [Usage](#usage)
- [Setup](#setup)
- [Configure](#configure)
- [Example configuration](#example-configuration)
- [Add commands](#add-commands)
- [`command_center.add`](#command_centeradd)
- [`command_center.mode`](#command_centermode)
- [Filter](#filter)
- [`command_center.remove()`](#command_centerremove)
- [`command_center.remove`](#command_centerremove)
- [`command_center.converter`](#command_centerconverter)
- [Configure](#configure)
- [Example configuration](#example-configuration)
- [Related Projects](#related-projects)

<!-- /TOC -->

## Install

This plugin requires [Telescope](https://github.com/nvim-telescope/telescope.nvim)
to be installed.
This plugin requires [Telescope](https://github.com/nvim-telescope/telescope.nvim).

### vim-plug

Expand All @@ -57,7 +55,7 @@ use {
}
```

## Use
## Usage

### Setup

Expand All @@ -84,6 +82,90 @@ the above keybindings can also be created
in [`command-center`-way](#example-configuration).
Keep reading the following sections.

### Configure

The following is the default configuration
for `command_center`:

```lua
{
-- Specify what components are shown in telescope prompt;
-- Order matters, and components may repeat
components = {
command_center.component.DESC,
command_center.component.KEYS,
command_center.component.CMD,
command_center.component.CATEGORY,
},

-- Spcify by what components that search results are ordered;
-- Order does not matter
sort_by = {
command_center.component.DESC,
command_center.component.KEYS,
command_center.component.CMD,
command_center.component.CATEGORY,
},

-- Change the separator used to separate each component
separator = " ",

-- When set to false,
-- The description compoenent will be empty if it is not specified
auto_replace_desc_with_cmd = true,

-- Default title to Telescope prompt
prompt_title = "Command Center",

-- can be any builtin or custom telescope theme
theme = themes.command_center,
}
```

#### Example configuration

Below is my personal configuration for `command_center`.
You can use it as a reference.

```lua
local telescope = require("telescope")
local command_center = require("command_center")
local noremap = { noremap = true }

command_center.add({
{
desc = "Open command_center",
cmd = "<CMD>Telescope command_center<CR>",
keys = {
{"n", "<Leader>fc", noremap},
{"v", "<Leader>fc", noremap},

-- If ever hesitate when using telescope start with <leader>f,
-- also open command center
{"n", "<Leader>f", noremap},
{"v", "<Leader>f", noremap},
},
}
}, command_center.mode.REGISTER_ONLY)

telescope.setup {
extensions = {
command_center = {
components = {
command_center.component.DESC,
command_center.component.KEYS,
},
sort_by = {
command_center.component.DESC,
command_center.component.KEYS,
},
auto_replace_desc_with_cmd = false,
}
}
}

telescope.load_extension('command_center')
```

### Add commands

Expand Down Expand Up @@ -151,13 +233,6 @@ command_center.add({
})
```

**NOTE**:
- If you are on neovim 0.6,
then you can add a Lua function
as a `cmd` and execute it inside `command_center`.
However, you are not able to set the keymaps
for the lua function.

If you have above snippet in your config,
`command-center` will create your specified keybindings automatically.
And calling `:Telescope command_center`
Expand Down Expand Up @@ -244,19 +319,18 @@ You can filter the commands upon invoking `:Telescope command_center`.
Currently, you can filter either by mode or category.
You can find some examples below:

- Show only commands that has keymaps that work in normal mode
1. Show only commands that has keymaps that work in normal mode
```
:Telescope command_center mode=n
```

- Show only commands that in "git" category
2. Show only commands that in "git" category
```
:Telescope command_center category=git
```
To make this work,
you have to first set the category
when you add a command.
For example:

You can specify the category of a command
as follows:

```lua
command_center.add({
Expand Down Expand Up @@ -302,12 +376,12 @@ You can find some examples below:

```

- Or both
3. Or both
```
:Telescope command_center mode=n category=markdown
```

### `command_center.remove()`
### `command_center.remove`

```lua
command_center.remove(commands, opts)
Expand Down Expand Up @@ -340,87 +414,6 @@ You can find some example usage of converters
in [wiki page](https://github.com/FeiyouG/command_center.nvim/wiki/Integrations).


## Configure

The following is the default configuration
for `command_center`:

```lua
{
-- Specify what components are shown in telescope prompt;
-- Order matters, and components may repeat
components = {
command_center.component.DESC,
command_center.component.KEYS,
command_center.component.CMD,
command_center.component.CATEGORY,
},

-- Spcify by what components that search results are ordered;
-- Order does not matter
sort_by = {
command_center.component.DESC,
command_center.component.KEYS,
command_center.component.CMD,
command_center.component.CATEGORY,
},

-- Change the separator used to separate each component
separator = " ",

-- When set to false,
-- The description compoenent will be empty if it is not specified
auto_replace_desc_with_cmd = true,

-- Default title to Telescope prompt
prompt_title = "Command Center",
}
```

### Example configuration

Below is my personal configuration for `command_center`.
You can use it as a reference.

```lua
local telescope = require("telescope")
local command_center = require("command_center")
local noremap = { noremap = true }

command_center.add({
{
desc = "Open command_center",
cmd = "<CMD>Telescope command_center<CR>",
keys = {
{"n", "<Leader>fc", noremap},
{"v", "<Leader>fc", noremap},

-- If ever hesitate when using telescope start with <leader>f,
-- also open command center
{"n", "<Leader>f", noremap},
{"v", "<Leader>f", noremap},
},
}
}, command_center.mode.REGISTER_ONLY)

telescope.setup {
extensions = {
command_center = {
components = {
command_center.component.DESC,
command_center.component.KEYS,
},
sort_by = {
command_center.component.DESC,
command_center.component.KEYS,
},
auto_replace_desc_with_cmd = false,
}
}
}

telescope.load_extension('command_center')
```
## Related Projects

- [which-key](https://github.com/folke/which-key.nvim)
Expand Down
57 changes: 30 additions & 27 deletions lua/telescope/_extensions/command_center.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,6 @@ local constants = require("command_center.constants")
local component = constants.component
local max_length = constants.max_len

-- Initial opts to defualt values
local user_opts = {
components = {
M.component.DESC,
M.component.KEYS,
M.component.CMD,
M.component.CAT,
},

sort_by = {
M.component.DESC,
M.component.KEYS,
M.component.CMD,
M.component.CAT,
},

separator = " ",
auto_replace_desc_with_cmd = true,
prompt_title = "Command Center",
}

-- Override default opts by user
local function setup(opts)
user_opts = vim.tbl_extend("force", user_opts, opts or {})
end

-- Custom theme for command center
function themes.command_center(opts)
opts = opts or {}
Expand Down Expand Up @@ -88,6 +62,34 @@ function themes.command_center(opts)
return vim.tbl_deep_extend("force", theme_opts, opts)
end

-- Initial opts to defualt values
local user_opts = {
components = {
M.component.DESC,
M.component.KEYS,
M.component.CMD,
M.component.CAT,
},

sort_by = {
M.component.DESC,
M.component.KEYS,
M.component.CMD,
M.component.CAT,
},

separator = " ",
auto_replace_desc_with_cmd = true,
prompt_title = "Command Center",
theme = themes.command_center,
}

-- Override default opts by user
local function setup(opts)
user_opts = vim.tbl_extend("force", user_opts, opts or {})
end


local function run(filter)
filter = filter or {}
local filtered_items, cnt = utils.filter_items(M._items, filter)
Expand Down Expand Up @@ -122,7 +124,8 @@ local function run(filter)
-- Insert the calculated length constants
opts.max_width = utils.get_max_width(opts, max_length)
opts.num_items = cnt
opts = themes.command_center(opts)
-- opts = themes.command_center(opts)
opts = opts.theme(opts)

-- opts = opts or {}
local telescope_obj = pickers.new(opts, {
Expand Down

0 comments on commit 63d1952

Please sign in to comment.