lipgloss icon indicating copy to clipboard operation
lipgloss copied to clipboard

Add ability to show block title over the border

Open eugener opened this issue 2 years ago ā€¢ 5 comments

The title could be shown either on top or bottom of the block. Here one example of such UI

The API might look like the following

var style = lipgloss.NewStyle().
    BorderStyle(lipgloss.NormalBorder()).
    BorderForeground(lipgloss.Color("63")).
    Title(lipgloss.Top, "Title")

There is also a need to change the title dynamically

  style.SetTitle((lipgloss.Top, "New Title"))

Titles which do not fit the width of the block can be automatically truncated at the front or back. The fact of truncation can be represented by adding ā€¦ character

eugener avatar Jun 16 '22 04:06 eugener

Implementation specifics aside, this seems like a good addition, though it may also be better off as a standalone component. If we were to add it to the library we'd also need to be able to set colors as well as the option to have both a top and bottom label simultaneously, and potential horizontal padding on the label.

If this is something you need right now here's a basic implementation you can start from: https://gist.github.com/meowgorithm/1777377a43373f563476a2bcb7d89306

meowgorithm avatar Jun 16 '22 05:06 meowgorithm

This is pretty similar to what I had to implement within the app I'm working on. Addition of Title API to styles would make it no-brainer. Title colors and horizontal alignment (left, center,right) would be a welcome addition too!

eugener avatar Jun 16 '22 12:06 eugener

@meowgorithm Please take a look at related PR #97. Hopefully, with few iterations, this API can become a part of the library

eugener avatar Jul 31 '22 15:07 eugener

Thanks @eugener. Iā€™m on holiday for the next few weeks and will look at it when Iā€™m back. I do think this is a common enough request that we should accommodate it.

meowgorithm avatar Aug 03 '22 05:08 meowgorithm

I would also like to add a title to my border, similar to TermUI: https://raw.githubusercontent.com/gizak/termui/master/_assets/demo.gif

Thanks!

greenm01 avatar Sep 07 '22 19:09 greenm01