Improvement: Center align util method
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Read lua/dashboard/utils.lua:53 and inspect utils.center_align, starting with how fill_sizes computes each line's indentation. The change is done when multiline content receives one shared minimum indentation rather than line-by-line shifts; the issue does not mention a test file to run.
Written by the indexing model from the issue text.
Description
Hi,
TLDR
I changed the behaviour of utils.center_align as its current behaviour does
not fit my use case. The injected string is shifted line by line rather than
indenting the whole block. I don't know if I should either:
- open a PR, and overwrite the align function
- open a PR, and add a new align function + user setting
- keep it to my fork
Issue
I was playing with the multi line string rendered in the dashboard in order to
display custom ASCII art. Unfortunately, lines with numerous spaces around
are not properly rendered.
After reading utils.center_align method, I noticed that alignment is done on
a line basis instead of considering the whole block's indentation.
Please find below the code change and the different renderings.
Code change
In utils.lua:53
Before
The current code applies shifts to each line independently.
local centered_lines = {}
local fills = fill_sizes(tbl)
for i = 1, #tbl do
local fill_line = (' '):rep(fills[i]) .. tbl[i]
table.insert(centered_lines, fill_line)
end
After
We add a fill_min variable to indent all lines by the same amount.
local centered_lines = {}
local fills = fill_sizes(tbl)
local fill_min = math.min(unpack(fills))
for i = 1, #tbl do
local fill_line = (' '):rep(fill_min) .. tbl[i]
table.insert(centered_lines, fill_line)
end
Please find below this wonderful spider I downloaded
here.
Raw string (input)
/\
/ \
| _ \ _
| / \ \ / \
|/ \ \ / \
/ \ | /\ / \
/| \| ~ ~ / \/ \
_______/_|_______\(o)(o)/___/\_____ \
/ / | (______) \ \ \_
/ / | \ \
/ / | \ \
/ / | \ \
/ _/ | \ \
/ _| \ \_
_/ \
\
\_
~tahl~
Neovim render (before)
Neovim render (after)
- Dominant language
- Lua
- Stars
- 2.9k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nvimdev/dashboard-nvim
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
nvimdev/dashboard-nvim#534 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
nvimdev/dashboard-nvim#480 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
nvimdev/dashboard-nvim#523 · 2 comments · 3 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
nvimdev/dashboard-nvim#521 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
nvimdev/dashboard-nvim#518 · 1 comment · 1 reaction ·
All issues in nvimdev/dashboard-nvim
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
api7/lua-resty-saml#62 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nvim-tree/nvim-tree.lua#3357 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
codymikol/multiverse.nvim#320 ·
-
Data Correction tbc
Difficulty 2/5 1-3 hours Newbie friendliness 68/100