Skip to content

<ProgressBar>

A horizontal progress bar. It's a small composite of <Box> and <Text> (OpenTUI has no native progress renderable): the filled portion is drawn in color, the remainder in trackColor.

vue
<script setup lang="ts">
import { ProgressBar, ref } from 'vue-termui'

const downloaded = ref(40)
const total = 100
</script>

<template>
  <ProgressBar :value="downloaded" :max="total" :width="30" color="#42b883" />
</template>

Props

PropTypeDefaultDescription
valuenumberrequiredCurrent progress, between 0 and max
maxnumber1The value representing 100%
widthnumber25Total width of the bar, in cells
colorColorInput'#42b883'Color of the filled portion
trackColorColorInput'#3a3a3a'Color of the unfilled track
charstring'█'Character used to draw the bar

The bar fills proportionally to value / max, clamped to the 0100% range.

Examples

A determinate bar driven by a ref:

vue
<script setup lang="ts">
import { ProgressBar, ref, useInterval } from 'vue-termui'

const value = ref(0)
useInterval(() => {
  value.value = (value.value + 1) % 101
}, 100)
</script>

<template>
  <ProgressBar :value="value" :max="100" :width="40" />
</template>

Tie it to real work — for example, how full an input is:

vue
<script setup lang="ts">
import { Box, Input, ProgressBar, Text, ref, computed } from 'vue-termui'

const name = ref('')
const max = 20
const filled = computed(() => Math.min(name.value.length, max))
</script>

<template>
  <Input v-model="name" :maxLength="max" focus placeholder="Type…" />
  <Box flexDirection="row" :gap="1">
    <ProgressBar :value="filled" :max="max" :width="max" />
    <Text fg="#888888">{{ filled }}/{{ max }}</Text>
  </Box>
</template>

Customize the look with char and colors:

template
<ProgressBar :value="60" :max="100" char="" color="#ff8800" trackColor="#222222" />

Released under the MIT License.