Skip to content

Feature Request: Support for center aligned text #916

@kevinMEH

Description

@kevinMEH

Hi,

I'm currently developing a quotes plugin for OpenCode but I'm running into a problem:

Image

For one liners, the text is correctly centered, but for text with multiple lines there doesn't appear to be a way to center each line as we could using text-align: center as in HTML:

Image

Expected:


Now is no time to think of what you do not have. Think of
what you can do with what there is.
- Ernest Hemingway


Code:

function Quotes(props: { theme: TuiThemeCurrent }) {
  const quote = QUOTES[Math.floor(Math.random() * QUOTES.length)]!;
  const split = quote.split("—"); // NOTE: Emdash; regular dashes are for names.
  const author = split.at(-1)?.trim() || "";
  const text = split.slice(0, -1).join("—").trim();

  return (
    <box width="100%" flexDirection="column">
      <text alignSelf="center" style={{ fg: props.theme.text }}>
        {text}
      </text>
      <text
        // alignSelf={text.length < 40 ? "center" : "flex-end"}
        alignSelf="center"
        style={{ fg: props.theme.textMuted }}
      >
        <em>
          - {author}
        </em>
      </text>
    </box>
  )
}

function View(props: { show: boolean; theme: TuiThemeCurrent }) {
  return (
    <box minHeight={4} width="100%" maxWidth={60} alignItems="center" paddingTop={3}>
      <Show when={props.show}>
        <Quotes theme={props.theme} />
      </Show>
    </box>
  )
}

Is there some way to enable this functionality that I don't know about? (preferably without needing to resort to complex width calculations & text splitting)

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis relates to the core package

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions