Exemple
colorama 0.4.6: colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle
Échantillon vérifié pour pypi colorama 0.4.6: colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle. Le contrat s'est…
sha256:7934af40d2b4ebc58157550a5b3c5de866abdd7e07ce40a9ca9b38d6f16757ab
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python uv
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962… |
2026-08-23 |
Cas
HOW- Objectif
- colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle
- Paquets
- Environnement
- python 3.12
- Créé
- 2026-08-23T16:03:57Z
Contrat
- colorama.Fore provides ANSI color escape sequences including Fore.RED, Fore.GREEN, Fore.BLUE, and Fore.RESET
- colorama.Back provides ANSI background escape sequences including Back.GREEN, Back.RED, and Back.RESET
- colorama.Style provides text style escape sequences including Style.BRIGHT, Style.DIM, Style.NORMAL, and Style.RESET_ALL
- colorama.Cursor provides parameterized terminal cursor positioning escape codes including UP, DOWN, FORWARD, BACK, and POS
- colorama.ansi.code_to_chars converts integer ANSI control codes to escape sequence strings
- colorama.ansitowin32.AnsiToWin32 wraps streams with autoreset to append Style.RESET_ALL after writes
- colorama.init, colorama.deinit, and colorama.reinit manage wrapping and restoring standard output streams
Fichiers
- PROMPT.md
- csx.json
- pyproject.toml
- requirements.txt
- spec.json
- test/contract.py
- uv.lock
Code source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/colorama@0.4.6
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:07c94a13005cf2d465cbfb324841a12eea93d1022b4a053cec0a1ebab2e275ad","contract":["colorama.Fore provides ANSI color escape sequences including Fore.RED, Fore.GREEN, Fore.BLUE, and Fore.RESET","colorama.Back provides ANSI background escape sequences including Back.GREEN, Back.RED, and Back.RESET","colorama.Style provides text style escape sequences including Style.BRIGHT, Style.DIM, Style.NORMAL, and Style.RESET_ALL","colorama.Cursor provides parameterized terminal cursor positioning escape codes including UP, DOWN, FORWARD, BACK, and POS","colorama.ansi.code_to_chars converts integer ANSI control codes to escape sequence strings","colorama.ansitowin32.AnsiToWin32 wraps streams with autoreset to append Style.RESET_ALL after writes","colorama.init, colorama.deinit, and colorama.reinit manage wrapping and restoring standard output streams"],"goal":"colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle","kind":"HOW","packages":["pkg:pypi/colorama@0.4.6"],"schemaVersion":1},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"uv","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/colorama@0.4.6"],"schemaVersion":1,"subject":"pkg:pypi/colorama@0.4.6","verifierAdapter":"python@1"}
[project]
name = "sample-colorama"
version = "0.1.0"
requires-python = ">=3.8"
dependencies = [
"colorama==0.4.6",
]
colorama==0.4.6
{
"schemaVersion": 1,
"goal": "colorize terminal text with Fore, Back, and Style and manage ANSI formatting lifecycle",
"kind": "HOW",
"packages": [
"pkg:pypi/colorama@0.4.6"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import io
import sys
import colorama
from colorama import Fore, Back, Style, Cursor, ansi
from colorama.ansitowin32 import AnsiToWin32
def test_fore_colors():
assert Fore.RED == "\033[31m", f"Fore.RED mismatch: {repr(Fore.RED)}"
assert Fore.GREEN == "\033[32m", f"Fore.GREEN mismatch: {repr(Fore.GREEN)}"
assert Fore.BLUE == "\033[34m", f"Fore.BLUE mismatch: {repr(Fore.BLUE)}"
assert Fore.RESET == "\033[39m", f"Fore.RESET mismatch: {repr(Fore.RESET)}"
def test_back_colors():
assert Back.RED == "\033[41m", f"Back.RED mismatch: {repr(Back.RED)}"
assert Back.GREEN == "\033[42m", f"Back.GREEN mismatch: {repr(Back.GREEN)}"
assert Back.RESET == "\033[49m", f"Back.RESET mismatch: {repr(Back.RESET)}"
def test_styles():
assert Style.BRIGHT == "\033[1m", f"Style.BRIGHT mismatch: {repr(Style.BRIGHT)}"
assert Style.DIM == "\033[2m", f"Style.DIM mismatch: {repr(Style.DIM)}"
assert Style.NORMAL == "\033[22m", f"Style.NORMAL mismatch: {repr(Style.NORMAL)}"
assert Style.RESET_ALL == "\033[0m", f"Style.RESET_ALL mismatch: {repr(Style.RESET_ALL)}"
def test_cursor():
assert Cursor.UP(3) == "\033[3A", f"Cursor.UP mismatch: {repr(Cursor.UP(3))}"
assert Cursor.DOWN(2) == "\033[2B", f"Cursor.DOWN mismatch: {repr(Cursor.DOWN(2))}"
assert Cursor.FORWARD(4) == "\033[4C", f"Cursor.FORWARD mismatch: {repr(Cursor.FORWARD(4))}"
assert Cursor.BACK(1) == "\033[1D", f"Cursor.BACK mismatch: {repr(Cursor.BACK(1))}"
assert Cursor.POS(10, 5) == "\033[5;10H", f"Cursor.POS mismatch: {repr(Cursor.POS(10, 5))}"
def test_code_to_chars():
assert ansi.code_to_chars(31) == "\033[31m", f"code_to_chars(31) mismatch: {repr(ansi.code_to_chars(31))}"
assert ansi.code_to_chars(42) == "\033[42m", f"code_to_chars(42) mismatch: {repr(ansi.code_to_chars(42))}"
assert ansi.code_to_chars(0) == "\033[0m", f"code_to_chars(0) mismatch: {repr(ansi.code_to_chars(0))}"
def test_ansitowin32_autoreset():
buf = io.StringIO()
wrapper = AnsiToWin32(buf, autoreset=True, convert=False, strip=False)
wrapper.write(Fore.GREEN + "success")
assert buf.getvalue() == Fore.GREEN + "success" + Style.RESET_ALL, f"autoreset mismatch: {repr(buf.getvalue())}"
def test_lifecycle():
orig_stdout = sys.stdout
orig_stderr = sys.stderr
try:
colorama.init(autoreset=False)
assert sys.stdout is not None, "sys.stdout is None after colorama.init()"
colorama.deinit()
assert sys.stdout is orig_stdout, "deinit did not restore original stdout"
assert sys.stderr is orig_stderr, "deinit did not restore original stderr"
colorama.reinit()
assert sys.stdout is not None, "sys.stdout is None after colorama.reinit()"
finally:
colorama.deinit()
assert sys.stdout is orig_stdout, "final deinit did not restore stdout"
def main():
test_fore_colors()
test_back_colors()
test_styles()
test_cursor()
test_code_to_chars()
test_ansitowin32_autoreset()
test_lifecycle()
print("All contract assertions passed.")
if __name__ == "__main__":
main()
version = 1
revision = 3
requires-python = ">=3.8"
[[package]]
name = "colorama"
version = "0.4.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
]
[package.metadata]
requires-dist = [{ name = "colorama", specifier = "==0.4.6" }]
Seeder d'origine
anonyme