-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thibault Hazelart
committed
Nov 29, 2021
1 parent
45918b8
commit 7ac4d9d
Showing
3 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# figban.nvim | ||
This neovim plugin will help you easily create commented figlet banners to separate your code and configurations. | ||
|
||
## Requirement | ||
This plugin requires figlet to be installed. | ||
<details> | ||
<summary>RedHat like</summary> | ||
|
||
```bash | ||
dnf install figlet | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Debian like</summary> | ||
|
||
```sh | ||
apt install figlet | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Arch</summary> | ||
|
||
```sh | ||
pacman -S figlet | ||
``` | ||
</details> | ||
|
||
## Installation | ||
<details> | ||
<summary>Vim Plug</summary> | ||
|
||
#### [Vim-Plug](https://github.com/junegunn/vim-plug) | ||
|
||
1. Add `Plug 'thazelart/figban.nvim'` to your vimrc file. | ||
2. Reload your vimrc or restart | ||
3. Run `:PlugInstall` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary>Dein.vim</summary> | ||
|
||
#### [Dein.vim](https://github.com/Shougo/dein.vim) | ||
|
||
1. Add `call dein#add('thazelart/figban.nvim')` to your vimrc file. | ||
2. Reload your vimrc or restart | ||
3. Run `:call dein#install()` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary>Vundle</summary> | ||
|
||
#### [Vundle](https://github.com/VundleVim/Vundle.vim) or similar | ||
|
||
1. Add `Plugin 'thazelart/figban.nvim'` to your vimrc file. | ||
2. Reload your vimrc or restart | ||
3. Run `:BundleInstall` | ||
|
||
</details> | ||
|
||
## Configuration | ||
You can choose you figlet `fontstyle` by adding this config in your vimrc | ||
```vim | ||
let g:figban_fontstyle='shadow' | ||
``` | ||
|
||
## command | ||
Generate your banner | ||
```sh | ||
:Figban My banner | ||
``` | ||
|
||
#### Examples | ||
<details> | ||
<summary>Golang</summary> | ||
|
||
```go | ||
/** __ __ ____ | ||
* | \/ |_ _ | __ ) __ _ _ __ _ __ ___ _ __ | ||
* | |\/| | | | | | _ \ / _` | '_ \| '_ \ / _ \ '__| | ||
* | | | | |_| | | |_) | (_| | | | | | | | __/ | | ||
* |_| |_|\__, | |____/ \__,_|_| |_|_| |_|\___|_| | ||
* |___/ | ||
**/ | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Python</summary> | ||
|
||
```python | ||
""" __ __ ____ | ||
| \/ |_ _ | __ ) __ _ _ __ _ __ ___ _ __ | ||
| |\/| | | | | | _ \ / _` | '_ \| '_ \ / _ \ '__| | ||
| | | | |_| | | |_) | (_| | | | | | | | __/ | | ||
|_| |_|\__, | |____/ \__,_|_| |_|_| |_|\___|_| | ||
|___/ | ||
""" | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Bash</summary> | ||
|
||
```sh | ||
# __ __ ____ | ||
# | \/ |_ _ | __ ) __ _ _ __ _ __ ___ _ __ | ||
# | |\/| | | | | | _ \ / _` | '_ \| '_ \ / _ \ '__| | ||
# | | | | |_| | | |_) | (_| | | | | | | | __/ | | ||
# |_| |_|\__, | |____/ \__,_|_| |_|_| |_|\___|_| | ||
# |___/ | ||
# | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>Lua</summary> | ||
|
||
```lua | ||
--[[ __ __ ____ | ||
-- | \/ |_ _ | __ ) __ _ _ __ _ __ ___ _ __ | ||
-- | |\/| | | | | | _ \ / _` | '_ \| '_ \ / _ \ '__| | ||
-- | | | | |_| | | |_) | (_| | | | | | | | __/ | | ||
-- |_| |_|\__, | |____/ \__,_|_| |_|_| |_|\___|_| | ||
-- |___/ | ||
--]] | ||
``` | ||
</details> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
local api = vim.api | ||
|
||
--[[ | ||
-- Begin definition of comment patterns | ||
--]] | ||
comment_formats = {} | ||
comment_formats["default"] = {"# ", "# ", "# "} | ||
comment_formats["ansible"] = {"# ", "# ", "# "} | ||
comment_formats["apache"] = {"# ", "# ", "# "} | ||
comment_formats["apachestyle"] = {"# ", "# ", "# "} | ||
comment_formats["asciidoc"] = {"//// ", " ", "////"} | ||
comment_formats["awk"] = {"# ", "# ", "#"} | ||
comment_formats["c"] = {"/** ", " * ", "**/"} | ||
comment_formats["django"] = {"{% comment %} ", " ", "{% endcomment %"} | ||
comment_formats["dockerfile"] = {"# ", "# ", "#"} | ||
comment_formats["go"] = {"/** ", " * ", "**/"} | ||
comment_formats["groovy"] = {"/** ", " * ", "**/"} | ||
comment_formats["html"] = {"<-- ", "-- ", "-->"} | ||
comment_formats["java"] = {"/** ", " * ", "**/"} | ||
comment_formats["javascript"] = {"/** ", " * ", "**/"} | ||
comment_formats["jinja"] = {"{# ", " ", "#}"} | ||
comment_formats["jsonnet"] = {"/** ", " * ", "**/"} | ||
comment_formats["lua"] = {"--[[ ", "-- ", "--]]"} | ||
comment_formats["nginx"] = {"# ", "# ", "#"} | ||
comment_formats["perl"] = {"# ", "# ", "#"} | ||
comment_formats["php"] = {"/** ", " * ", "**/"} | ||
comment_formats["plsql"] = {"/** ", " * ", "**/"} | ||
comment_formats["ps1"] = {"# ", "# ", "#"} | ||
comment_formats["python"] = {'""" ', " ", '"""'} | ||
comment_formats["ruby"] = {"# ", "# ", "#"} | ||
comment_formats["rust"] = {"/** ", " * ", "**/"} | ||
comment_formats["sh"] = {"# ", "# ", "#"} | ||
comment_formats["sql"] = {"/** ", " * ", "**/"} | ||
comment_formats["terraform"] = {"/** ", " * ", "**/"} | ||
comment_formats["yaml"] = {"# ", "# ", "#"} | ||
comment_formats["vim"] = {"\" ", "\" ", "\""} | ||
comment_formats["zsh"] = {"# ", "# ", "#"} | ||
--[[ | ||
-- End definition of comment patterns | ||
--]] | ||
|
||
-- get_comment_format get the comment format according to the type of file | ||
-- return: the good format (table) | ||
function get_comment_format() | ||
local filetype = vim.bo.filetype | ||
if comment_formats[filetype] ~= nil then | ||
return comment_formats[filetype] | ||
else | ||
return comment_formats["default"] | ||
end | ||
end | ||
|
||
-- rtrim trim the right of the given string | ||
-- return: the trimmed string | ||
function rtrim(s) | ||
return s:match "(.-)%s*$" | ||
end | ||
|
||
--[[ | ||
-- Begin FigBan class declaration | ||
--]] | ||
local FigBan = {} | ||
FigBan.__index = FigBan | ||
|
||
function FigBan.new(text) | ||
local self = setmetatable({}, FigBan) | ||
self.font_style = vim.g.figban_fontstyle or "standard" | ||
self.format = get_comment_format() | ||
self.text = text | ||
self.banner = "" | ||
return self | ||
end | ||
|
||
function FigBan.generate(self) | ||
local banner = {} | ||
local handler = assert(io.popen("figlet -f " .. self.font_style .. " " .. self.text)) | ||
|
||
|
||
local line = handler:read("*l") | ||
repeat | ||
local next_line = handler:read("*l") | ||
if #banner == 0 then | ||
table.insert(banner, rtrim(self.format[1] .. line)) | ||
elseif next_line ~= nil then | ||
table.insert(banner, rtrim(self.format[2] .. line)) | ||
else | ||
if rtrim(line) ~= "" then | ||
table.insert(banner, rtrim(self.format[2] .. line)) | ||
end | ||
table.insert(banner, rtrim(self.format[3])) | ||
end | ||
|
||
line = next_line | ||
until line == nil | ||
|
||
if handler then handler:close() end | ||
self.banner = banner | ||
end | ||
|
||
function FigBan.print(self) | ||
api.nvim_put(self.banner, "l", true, true) | ||
end | ||
--[[ | ||
-- End FigBan class declaration | ||
--]] | ||
|
||
function figban(text) | ||
local figban = FigBan.new(text) | ||
figban:generate() | ||
figban:print() | ||
end | ||
|
||
return { | ||
figban = figban | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
" Last Change: 2021 Nov 28 | ||
" Maintainer: Thibault Hazelart <thazelart@gmail.com> | ||
" License: GNU General Public License v3.0 | ||
|
||
if exists('g:loaded_figban') | finish | endif " prevent loading file twice | ||
|
||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
hi def link FigbanHeader Number | ||
hi def link FigbanSubHeader Identifier | ||
" hi FigbanCursorLine ctermbg=238 cterm=none | ||
|
||
command! -nargs=+ Figban lua require'figban'.figban(<q-args>) | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
|
||
let g:loaded_figban = 1 | ||
|
||
" Figlet fontfile to use | ||
let g:figban_fontfile = "standard" |