Improvement: Center align util method

Open Beginner friendly
#402 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
lua
Domain
tooling

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)

before

Neovim render (after)

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nvimdev/dashboard-nvim

All issues in nvimdev/dashboard-nvim

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.