Skip to content

Commit 7e1b837

Browse files
committed
Created is-unicode-supported pkg
1 parent 930bea2 commit 7e1b837

136 files changed

Lines changed: 2712 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# 🐍 adamlui / python-utils
44

5-
<a href="https://pypacktrends.com/?packages=find-project-root&packages=get-min-py&packages=latin-locales&packages=non-latin-locales&packages=project-markers&packages=remove-json-keys&packages=translate-messages&time_range=allTimeCumulative&scheme=dark">
5+
<a href="https://pypacktrends.com/?packages=find-project-root&packages=get-min-py&packages=is-unicode-supported&packages=latin-locales&packages=non-latin-locales&packages=project-markers&packages=remove-json-keys&packages=translate-messages&time_range=allTimeCumulative&scheme=dark">
66
<img height=31 src="https://img.shields.io/badge/Downloads-9.8k-af68ff.svg?logo=weightsandbiases&logoColor=white&labelColor=464646&style=for-the-badge"></a>
77
<a href="./LICENSE.md">
88
<img height=31 src="https://img.shields.io/badge/License-MIT-f99b27.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
@@ -32,6 +32,15 @@
3232
[CLI usage](https://github.com/adamlui/python-utils/tree/main/get-min-py/#-command-line-usage) /
3333
[Discuss](https://github.com/adamlui/python-utils/discussions)
3434

35+
### <a href="https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#readme">📟 is-unicode-supported</a>
36+
37+
> Detect whether the terminal supports advanced Unicode.
38+
<br>[Install](https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#-installation) /
39+
[Readme](https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#readme) /
40+
[API usage](https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#-api-usage) /
41+
[CLI usage](https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#-command-line-usage) /
42+
[Discuss](https://github.com/adamlui/python-utils/discussions)
43+
3544
### <a href="https://github.com/adamlui/python-utils/tree/main/latin-locales/#readme">🇪🇸 latin-locales</a>
3645

3746
> ISO 639-1 (2-letter) codes for Latin locales.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 🏛️ MIT License
2+
3+
**Copyright © 2026 [Adam Lui](https://github.com/adamlui)**
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<a id="top"></a>
2+
3+
# > is-unicode-supported
4+
5+
<a href="https://github.com/adamlui/python-utils/releases/tag/is-unicode-supported-1.0.0">
6+
<img height=31 src="https://img.shields.io/badge/Latest_Build-1.0.0-32fcee.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7+
<a href="https://github.com/adamlui/python-utils/blob/main/is-unicode-supported/docs/LICENSE.md">
8+
<img height=31 src="https://img.shields.io/badge/License-MIT-f99b27.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
9+
<a href="https://www.codefactor.io/repository/github/adamlui/python-utils">
10+
<img height=31 src="https://img.shields.io/codefactor/grade/github/adamlui/python-utils?label=Code+Quality&logo=codefactor&logoColor=white&labelColor=464646&color=a0fc55&style=for-the-badge"></a>
11+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_python-utils">
12+
<img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_python-utils%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=fafc74"></a>
13+
14+
> ### _Detect whether the terminal supports advanced Unicode._
15+
16+
Checks if terminal supports advanced Unicode (CJK, emoji, etc.) by measuring the cursor position of a single, wide char (𠀀). On Windows, returns `False` for legacy consoles (CMD). On all other modern terminals, returns `True` if the wide char renders as 2 columns.
17+
18+
## ⚡ Installation
19+
20+
```bash
21+
pip install is-unicode-supported
22+
```
23+
24+
## 💻 Command line usage
25+
26+
```bash
27+
$ is-unicode-supported # or isunicodesupported
28+
29+
True
30+
```
31+
32+
CLI options:
33+
34+
| Option | Description
35+
| ----------------- | -----------------
36+
| `-h`, `--help` | Show help screen
37+
| `-v`, `--version` | Show version
38+
| `--docs` | Open docs URL
39+
40+
## 🔌 API usage
41+
42+
```py
43+
import is_unicode_supported
44+
45+
if is_unicode_supported():
46+
print('Advanced Unicode supported!')
47+
else:
48+
print('Advanced Unicode not supported!')
49+
```
50+
51+
_Note: Most type checkers will falsely warn_ `is_unicode_supported` _is not a callable module because they are incapable of analyzing runtime behavior (where the module is replaced w/ a function for cleaner, direct access). You can safely suppress such warnings using_ `# type: ignore`.
52+
53+
## MIT License
54+
55+
Copyright © 2026 [Adam Lui](https://github.com/adamlui).
56+
57+
#
58+
59+
<a href="#top">Back to top ↑</a>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 🛡️ Security Policy
2+
3+
If you find a vulnerability, please e-mail security@tidelift.com and a fix will be coordinated within 2 business days.

is-unicode-supported/noxfile.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from pathlib import Path
2+
from types import SimpleNamespace as sn
3+
4+
import nox
5+
6+
pkg = sn(dir=Path(__file__).parent.name)
7+
pkg.name = pkg.dir.replace('-', '_')
8+
paths = sn(utils=sn(bump='utils/bump.py', clean='utils/clean.py', publish='utils/publish.sh'))
9+
10+
def session(func) : return nox.session(venv_backend='none', name=func.__name__.replace('_', '-'))(func)
11+
12+
# SESSIONS
13+
14+
@session
15+
def dev(session) : session.run('pip', 'install', '-e', '.') ; session.run(pkg.dir, '--help', *session.posargs)
16+
@session
17+
def debug(session) : session.run('py', '-m', pkg.name, '--debug', *session.posargs, env={ 'PYTHONPATH': 'src' })
18+
19+
@session
20+
def lint(session) : session.run('ruff', 'check', '.', *session.posargs)
21+
@session
22+
def lint_fix(session) : session.run('ruff', 'check', '.', '--fix', *session.posargs)
23+
24+
@session
25+
def bump_patch(session, no_push=True):
26+
cmd = ['py', paths.utils.bump, '--patch']
27+
if no_push : cmd.append('--no-push')
28+
session.run(*cmd, *session.posargs)
29+
@session
30+
def bump_minor(session, no_push=True):
31+
cmd = ['py', paths.utils.bump, '--minor']
32+
if no_push : cmd.append('--no-push')
33+
session.run(*cmd, *session.posargs)
34+
@session
35+
def bump_feat(session, no_push=True):
36+
bump_minor(session, no_push)
37+
@session
38+
def bump_major(session, no_push=True):
39+
cmd = ['py', paths.utils.bump, '--major']
40+
if no_push : cmd.append('--no-push')
41+
session.run(*cmd, *session.posargs)
42+
43+
@session
44+
def build(session) : clean(session) ; session.run('py', '-m', 'build') ; print('Build complete!')
45+
@session
46+
def publish(session) : session.run('bash', paths.utils.publish, *session.posargs)
47+
48+
@session
49+
def deploy_patch(session) : bump_patch(session, no_push=False) ; build(session) ; publish(session)
50+
@session
51+
def deploy_minor(session) : bump_minor(session, no_push=False) ; build(session) ; publish(session)
52+
@session
53+
def deploy_feat(session) : deploy_minor(session)
54+
@session
55+
def deploy_major(session) : bump_major(session, no_push=False) ; build(session) ; publish(session)
56+
57+
@session
58+
def clean(session, *args) : session.run('py', paths.utils.clean, *args)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[build-system]
2+
requires = [
3+
"setuptools~=82.0.0",
4+
"wheel",
5+
]
6+
build-backend = "setuptools.build_meta"
7+
8+
[project]
9+
name = "is-unicode-supported"
10+
version = "1.0.0"
11+
description = "Detect whether the terminal supports advanced Unicode."
12+
authors = [
13+
{ name = "Adam Lui", email = "adam@kudoai.com" },
14+
]
15+
readme = "docs/README.md"
16+
license = "MIT"
17+
license-files = [
18+
"docs/LICENSE.md",
19+
]
20+
dependencies = [
21+
"blessed~=1.33.0",
22+
"colorama~=0.4.6 ; platform_system == 'Windows'",
23+
"json5~=0.13.0",
24+
]
25+
requires-python = ">=3.8,<4"
26+
keywords = [
27+
"api",
28+
"arabic",
29+
"chinese",
30+
"cjk",
31+
"cli",
32+
"compatibility",
33+
"console",
34+
"detect",
35+
"detection",
36+
"dev-tool",
37+
"emoji",
38+
"hebrew",
39+
"japanese",
40+
"korean",
41+
"shell",
42+
"support",
43+
"supported",
44+
"supports",
45+
"terminal",
46+
"unicode",
47+
"utf8",
48+
"wide-characters",
49+
"zero-width",
50+
"zwj",
51+
]
52+
classifiers = [
53+
"Development Status :: 5 - Production/Stable",
54+
"Environment :: Console",
55+
"Intended Audience :: Developers",
56+
"Intended Audience :: End Users/Desktop",
57+
"Intended Audience :: Information Technology",
58+
"Intended Audience :: System Administrators",
59+
"Natural Language :: English",
60+
"Operating System :: OS Independent",
61+
"Programming Language :: Python",
62+
"Programming Language :: Python :: 3",
63+
"Programming Language :: Python :: 3 :: Only",
64+
"Programming Language :: Python :: 3.8",
65+
"Programming Language :: Python :: 3.9",
66+
"Programming Language :: Python :: 3.10",
67+
"Programming Language :: Python :: 3.11",
68+
"Programming Language :: Python :: 3.12",
69+
"Programming Language :: Python :: 3.13",
70+
"Programming Language :: Python :: 3.14",
71+
"Programming Language :: Python :: 3.15",
72+
"Topic :: Software Development",
73+
"Topic :: Software Development :: Internationalization",
74+
"Topic :: Software Development :: Libraries",
75+
"Topic :: Software Development :: Libraries :: Python Modules",
76+
"Topic :: Software Development :: Localization",
77+
"Topic :: Text Processing :: Linguistic",
78+
"Topic :: Utilities",
79+
"Typing :: Typed",
80+
]
81+
82+
[project.urls]
83+
Changelog = "https://github.com/adamlui/python-utils/releases/tag/is-unicode-supported-1.0.0"
84+
Documentation = "https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/docs"
85+
Funding = "https://github.com/sponsors/adamlui"
86+
Homepage = "https://github.com/adamlui/python-utils/tree/main/is-unicode-supported/#readme"
87+
Issues = "https://github.com/adamlui/python-utils/issues"
88+
"PyPI Stats" = "https://pepy.tech/projects/is-unicode-supported"
89+
Releases = "https://github.com/adamlui/python-utils/releases"
90+
Repository = "https://github.com/adamlui/python-utils"
91+
92+
[project.scripts]
93+
is-unicode-supported = "is_unicode_supported.cli.__main__:main"
94+
isunicodesupported = "is_unicode_supported.cli.__main__:main"
95+
96+
[project.optional-dependencies]
97+
dev = [
98+
"nox>=2026.2.9",
99+
"remove-json-keys~=1.8.3",
100+
"tomli~=2.4.0",
101+
"tomli-w~=1.2.0",
102+
"translate-messages~=1.8.3",
103+
]
104+
105+
[tool.setuptools.packages.find]
106+
where = [
107+
"src",
108+
]
109+
110+
[tool.setuptools.package-data]
111+
is_unicode_supported = [
112+
"data/*.json",
113+
"data/_locales/en/messages.json",
114+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
from .api import is_unicode_supported
4+
from . import cli
5+
6+
sys.modules[__name__].cli = cli # type: ignore
7+
sys.modules[__name__] = is_unicode_supported # type: ignore
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os, sys
2+
3+
import blessed
4+
5+
def is_unicode_supported() -> bool:
6+
if sys.platform == 'win32' and not os.environ.get('WT_SESSION'):
7+
return False # legacy Win consoles don't suport wide chars
8+
terminal = blessed.Terminal()
9+
with terminal.cbreak(), terminal.hidden_cursor(): # measure rendered width of wide CJK char
10+
r,g,b = terminal.get_bgcolor()
11+
if (r,g,b) == (-1,-1,-1) : (r,g,b) = (0,0,0) # get bg failed, init to black
12+
sys.stdout.write(terminal.color_rgb(r, g, b)) # make text invisible
13+
_, x1 = terminal.get_location()
14+
sys.stdout.write('𠀀')
15+
sys.stdout.flush()
16+
_, x2 = terminal.get_location()
17+
sys.stdout.write('\b' * (x2 - x1) + ' ' * (x2 - x1) + '\b' * (x2 - x1))
18+
sys.stdout.flush()
19+
sys.stdout.write(terminal.normal) # restore text colors
20+
return x2 - x1 > 1 # terminal rendered wide char as 2 col

is-unicode-supported/src/is_unicode_supported/cli/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
3+
from ..api import is_unicode_supported
4+
from .lib import init, settings
5+
6+
def main():
7+
cli = init.cli()
8+
9+
# Process early-exit args (e.g. --help, --version)
10+
for ctrl_name, ctrl in vars(settings.controls).items():
11+
if getattr(ctrl, 'exit', False) and getattr(cli.config, ctrl_name, False):
12+
if hasattr(ctrl, 'handler') : ctrl.handler(cli)
13+
sys.exit(0)
14+
15+
print(is_unicode_supported())
16+
17+
if __name__ == '__main__' : main()

0 commit comments

Comments
 (0)