Skip to content

How to center objects #327

Discussion options

You must be logged in to vote

I would do something along the lines of the following

package main

import (
	"fmt"
	"os"

	"github.com/charmbracelet/lipgloss"
	"golang.org/x/term"
)

func main() {
	physicalWidth, _, _ := term.GetSize(int(os.Stdout.Fd()))

	child := lipgloss.NewStyle().
		Border(lipgloss.RoundedBorder()).
		BorderForeground(lipgloss.Color("420")).
		Padding(1, 2)

	parent := lipgloss.NewStyle().
		Width(physicalWidth).
		AlignHorizontal(lipgloss.Center).
		Padding(2, 0)
	fmt.Println(parent.Render(child.Render("Hello World!")))
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RoastBeefer00
Comment options

Answer selected by RoastBeefer00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants