Skip to content
Jakub Sobon edited this page Nov 14, 2020 · 4 revisions

Doc Status

This section describes container options that specify its style or look.

Borders for containers

Containers don't have any borders by default, use one of the following options to instruct Termdash to draw a border around a container.

The following code shows two containers with different border styles as shown above. The right container has the keyboard focus so its border is highlighted.

t, err := tcell.New()
if err != nil {
    panic(err)
}
defer t.Close()

c, err := container.New(
    t,
    container.SplitVertical(
        container.Left(
            container.Border(linestyle.Light),
        ),
        container.Right(
            container.Border(linestyle.Double),
        ),
    ),
)
if err != nil {
    return fmt.Errorf("container.New => %v", err)
}

The container.Border option is used to enable the border and specify its line style. Refer to the Linestyle API for the available line styles.

The container.BorderColor option sets the color of the border. This option takes no effect when the container has no border.

The container.FocusedColor option sets the color of the border when the container is focused. This option takes no effect when the container has no border.

Titles for containers

Containers that have a border can also have a text title displayed in the border. The title isn't visible on a container without border.

The following code shows a container with a title in the border that is aligned to the right.

t, err := tcell.New()
if err != nil {
    panic(err)
}
defer t.Close()

c, err := container.New(
    t,
    container.Border(linestyle.Light),
    container.BorderTitle("hello world"),
    container.BorderTitleAlignRight(),
)
if err != nil {
    return fmt.Errorf("container.New => %v", err)
}

The container.BorderTitle option sets the title to display on the container. The title is displayed above the container and aligned according to the following alignment options.

The container.BorderTitleAlignLeft option indicates that the container title should be aligned at the top left corner.

The container.BorderTitleAlignCenter option indicates that the container title should be aligned at the top and center above the container.

The container.BorderTitleAlignRight option indicates that the container title should be aligned at the top right corner.