Skip to content

<Text> ​

Styled text. Maps to OpenTUI's text renderable. The text itself is the default slot; boolean props toggle attributes, and fg / bg set colors.

vue
<script setup lang="ts">
import { Text } from 'vue-termui'
</script>

<template>
  <Text fg="#42b883" bold>vue-termui</Text>
</template>

See Styling Text for the guide. This page is the full prop reference.

Props ​

PropTypeDescription
fgColorInputForeground (text) color
bgColorInputBackground color
boldbooleanBolder weight
dimbooleanReduced intensity
italicbooleanItalic
underlinebooleanUnderlined
strikethroughbooleanStruck through
inversebooleanSwap foreground and background
blinkbooleanBlinking (terminal-dependent)
wrap'none' | 'char' | 'word'How text wraps when it overflows its line

ColorInput is a hex/name string (e.g. '#42b883', 'red') or an OpenTUI RGBA instance.

Colors ​

template
<Text fg="#42b883">green</Text>
<Text fg="red">named</Text>
<Text fg="#0b0b0b" bg="#42b883">dark on green</Text>

Attributes combine ​

template
<Text bold italic underline fg="#ff8800">emphasis</Text>

Styling part of a line ​

<Text> does not nest — a <Text> inside another <Text> is ignored (with a warning), the same way the browser drops a <p> inside a <p>. To give part of a line its own color or weight, pass a StyledText to the content prop, built with the t / bold / fg / … helpers re-exported from vue-termui:

vue
<script setup lang="ts">
import { Text, t, bold, fg } from 'vue-termui'

const ok = true
const status = t`Status: ${ok ? bold(fg('#42b883')('OK')) : bold(fg('red')('FAIL'))}`
</script>

<template>
  <Text :content="status" />
</template>

Plain interpolation, v-if and v-for work as usual inside a single <Text>:

template
<Text>Count: {{ count }}</Text>

Wrapping ​

wrap only matters when the text is constrained by its container's width:

template
<Box :width="20">
  <Text wrap="word">A longer sentence that wraps onto multiple lines.</Text>
</Box>

Line breaks ​

For blank lines between text, use <Newline>.

Released under the MIT License.