diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1c4c2f..1b385a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,15 +21,14 @@ jobs: printf 'Apt::Install-Recommends "false";\n' | tee -a /etc/apt/apt.conf apt-get update apt-get install -y python3-gi-cairo gir1.2-pango-1.0 + apt-get install -y perl - name: check Python version run: | python3 --version - - name: smoke test + - name: run tests run: | export LC_ALL=C.UTF-8 - ./ubanner --trim 'νιάου' - ./ubanner --full-screen 'νιάου' - ./ubanner --list-fonts + prove -v static: runs-on: ${{matrix.os}} diff --git a/README b/README index b9980e6..a41f824 100644 --- a/README +++ b/README @@ -3,19 +3,19 @@ Overview .. code:: console - $ ubanner --trim 'νιάου' - ░░░ - ██░ - ░█▒ + $ ubanner --trim πανό + ░░░ + ██░ + █▒ - ░░░░░ ░░ ░░░░░ ░░░░░░ ░░ ░░░░░ ░░░░░ ░░░ - ▒██ ██░ ▒██ ▒██░░░▒██░ █▒ ▒██░ ░░██░ ▒██ ░██░ - ▒██ ░██░ ▒██ ███ ▒███▒ ███ ██▒ ▒██ ░██ - ▒██ ▒██░ ▒██ ░██░ ███ ░██░ ▒██░ ▒██ ██▒ - ▒██ ░██░ ▒██ ▒██░ ▒██ ▒██░ ▒██░ ▒██ ██▒ - ▒██ ▒██ ▒██ ░██▒ ███▒ ░██▒ ▒██ ▒██ ▒██░ - ▒██ ▒█▒ ░██ ░██░ ▒▒▒██ ░██░ ▒██░ ░██ ▒██░ - ▒███▒░ ░▒██▒ ▒██▒▒▒░ ░███▒ ░▒█▒▒▒█▒░ ▒██▒██▒░ + ░░░░░░░░░░░░░░░░ ░░░░░░ ░░ ░░░░░ ░░ ░░░░░ + ▒██ ▒██ ▒██░░░▒██░ █▒ ▒██ ██░ ▒██░ ░░██░ + ▒██ ▒██ ███ ▒███▒ ▒██ ░██░ ███ ██▒ + ▒██ ▒██ ░██░ ███ ▒██ ▒██░ ░██░ ▒██░ + ▒██ ▒██ ▒██░ ▒██ ▒██ ░██░ ▒██░ ▒██░ + ▒██ ▒██ ░██▒ ███▒ ▒██ ▒██ ░██▒ ▒██ + ▒██ ▒██ ░██░ ▒▒▒██ ▒██ ▒█▒ ░██░ ▒██░ + ▒▒███▒▒ ░▒███▒▒ ▒██▒▒▒░ ░███▒ ▒███▒░ ░▒█▒▒▒█▒░ Dependencies ============ diff --git a/t/common.sh b/t/common.sh new file mode 100644 index 0000000..f08d816 --- /dev/null +++ b/t/common.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +dir="${0%/*}/.." +prog="${UBANNER_TEST_TARGET:-"$dir/ubanner"}" + +is_unicode_locale() +{ + local charset=$'\u2591\u2592\u2588' + test ${#charset} -eq 3 +} + +# vim:ts=4 sts=4 sw=4 et ft=sh diff --git a/t/full-screen.t b/t/full-screen.t new file mode 100755 index 0000000..ad7ce81 --- /dev/null +++ b/t/full-screen.t @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +. "${0%/*}/common.sh" + +echo 1..1 +is_unicode_locale || { + echo 'non-Unicode locale' >&2 + exit 1 +} +if out=$("$prog" --full-screen $'\u10E3') +then + sed -e 's/^/# /' <<< "$out" + echo ok 1 +else + echo not ok 1 +fi + +# vim:ts=4 sts=4 sw=4 et ft=sh diff --git a/t/lists-fonts.t b/t/lists-fonts.t new file mode 100755 index 0000000..d38d7ce --- /dev/null +++ b/t/lists-fonts.t @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +. "${0%/*}/common.sh" + +echo 1..1 +if out=$("$prog" --list-fonts) +then + sed -e 's/^/# /' <<< "$out" + echo ok 1 +else + echo not ok 1 +fi + +# vim:ts=4 sts=4 sw=4 et ft=sh diff --git a/t/trim.t b/t/trim.t new file mode 100755 index 0000000..99fe707 --- /dev/null +++ b/t/trim.t @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +. "${0%/*}/common.sh" + +echo 1..1 +is_unicode_locale || { + echo 'non-Unicode locale' >&2 + exit 1 +} +if out=$("$prog" --trim $'\u10E3') +then + sed -e 's/^/# /' <<< "$out" + echo ok 1 +else + echo not ok 1 +fi + +# vim:ts=4 sts=4 sw=4 et ft=sh diff --git a/ubanner b/ubanner index b486e97..771ebb1 100755 --- a/ubanner +++ b/ubanner @@ -7,6 +7,7 @@ import argparse import bisect import itertools +import locale import shutil import signal import sys @@ -62,7 +63,6 @@ def pango_render(text, size=(76, 24), font=None, font_size=None): PangoCairo.show_layout(ctx, layout) data = surface.get_data() stride = surface.get_stride() - charset = ' ░▒█' cdiv = 512 // len(charset) for y in range(ht // 2): s = '' @@ -93,6 +93,13 @@ class act_list_fonts(argparse.Action): seen.add(descr) sys.exit() +encoding = locale.nl_langinfo(locale.CODESET) +charset = ' ░▒█' +try: + charset.encode(encoding, 'strict') +except UnicodeError: + charset = ' +*#' + def main(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) ap = argparse.ArgumentParser()