Пример
golang.org/x/term v0.41.0: IsTerminal, NewTerminal, Terminal.ReadLine
Проверенный пример — golang golang.org/x/term v0.41.0: IsTerminal, NewTerminal, Terminal.ReadLine. Контракт выполнен на go 1.26 · linux debian/x64 · docker и…
sha256:314f9c9b2ea0e8be9b24998f1bda60c5a4edb21850fecfc4c390fcd308544676
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-14 |
Кейс
HOW- Цель
- verify pkg:golang/golang.org/x/term@v0.41.0
- Пакеты
- Символы
-
- term.IsTerminal
- term.NewTerminal
- term.Terminal.ReadLine
- term.Terminal.Write
- term.Terminal.SetPrompt
- term.Terminal.SetSize
- Создан
- 2026-10-14T16:37:12Z
Контракт
- term.IsTerminal returns false for negative and pipe file descriptors
- term.NewTerminal reads CRLF- and LF-terminated lines via ReadLine and returns io.EOF on exhausted input
- Terminal.SetPrompt, Terminal.SetSize, and Terminal.Write update terminal state and emit output with populated Escape sequences
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Исходный код
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: verify pkg:golang/golang.org/x/term@v0.41.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/term@v0.41.0
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:ce12620bac04408eb6e584fc22a2e2491a328797cca50287973a0091a0500a53","contract":["term.IsTerminal returns false for negative and pipe file descriptors","term.NewTerminal reads CRLF- and LF-terminated lines via ReadLine and returns io.EOF on exhausted input","Terminal.SetPrompt, Terminal.SetSize, and Terminal.Write update terminal state and emit output with populated Escape sequences"],"goal":"verify pkg:golang/golang.org/x/term@v0.41.0","kind":"HOW","packages":["pkg:golang/golang.org/x/term@v0.41.0"],"schemaVersion":1,"symbols":["term.IsTerminal","term.NewTerminal","term.Terminal.ReadLine","term.Terminal.Write","term.Terminal.SetPrompt","term.Terminal.SetSize"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/term@v0.41.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/term@v0.41.0","symbols":["term.IsTerminal","term.NewTerminal","term.Terminal.ReadLine","term.Terminal.Write","term.Terminal.SetPrompt","term.Terminal.SetSize"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.25.0
require golang.org/x/term v0.41.0
require golang.org/x/sys v0.42.0 // indirect
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
package main
import (
"bytes"
"fmt"
"io"
"golang.org/x/term"
)
type rwBuffer struct {
r io.Reader
w *bytes.Buffer
}
func (b *rwBuffer) Read(p []byte) (int, error) {
return b.r.Read(p)
}
func (b *rwBuffer) Write(p []byte) (int, error) {
return b.w.Write(p)
}
func main() {
out := &bytes.Buffer{}
rw := &rwBuffer{
r: bytes.NewBufferString("status\r\n"),
w: out,
}
t := term.NewTerminal(rw, "> ")
line, err := t.ReadLine()
fmt.Printf("isTerminal(-1)=%v line=%q err=%v resetLen=%d\n",
term.IsTerminal(-1), line, err, len(t.Escape.Reset))
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/golang.org/x/term@v0.41.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/term@v0.41.0"
]
}
package main
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"golang.org/x/term"
)
type duplexBuffer struct {
in *bytes.Buffer
out *bytes.Buffer
}
func (d *duplexBuffer) Read(p []byte) (int, error) {
return d.in.Read(p)
}
func (d *duplexBuffer) Write(p []byte) (int, error) {
return d.out.Write(p)
}
func fail(msg string, args ...any) {
fmt.Fprintf(os.Stderr, "FAIL: "+msg+"\n", args...)
os.Exit(1)
}
func main() {
// 1. term.IsTerminal returns false for negative and non-terminal file descriptors.
if term.IsTerminal(-1) {
fail("expected term.IsTerminal(-1) to return false")
}
rPipe, wPipe, err := os.Pipe()
if err != nil {
fail("os.Pipe failed: %v", err)
}
defer rPipe.Close()
defer wPipe.Close()
if term.IsTerminal(int(rPipe.Fd())) || term.IsTerminal(int(wPipe.Fd())) {
fail("expected term.IsTerminal to return false for pipe file descriptors")
}
// 2. term.NewTerminal reads CRLF- and LF-terminated lines and returns io.EOF when input is exhausted.
ioBuf := &duplexBuffer{
in: bytes.NewBufferString("first line\r\nsecond line\n"),
out: &bytes.Buffer{},
}
terminal := term.NewTerminal(ioBuf, "prompt> ")
line1, err := terminal.ReadLine()
if err != nil || line1 != "first line" {
fail("expected first ReadLine to return (\"first line\", nil), got (%q, %v)", line1, err)
}
line2, err := terminal.ReadLine()
if err != nil || line2 != "second line" {
fail("expected second ReadLine to return (\"second line\", nil), got (%q, %v)", line2, err)
}
_, err = terminal.ReadLine()
if !errors.Is(err, io.EOF) {
fail("expected ReadLine on exhausted input to return io.EOF, got %v", err)
}
// 3. Terminal.SetPrompt, Terminal.SetSize, Terminal.Write, and Terminal.Escape behave as expected.
ioBuf.out.Reset()
terminal.SetPrompt("cmd$ ")
if err := terminal.SetSize(100, 40); err != nil {
fail("expected SetSize(100, 40) to succeed, got %v", err)
}
n, err := terminal.Write([]byte("notice\n"))
if err != nil || n != len("notice\n") {
fail("expected Write to return (7, nil), got (%d, %v)", n, err)
}
if !bytes.Contains(ioBuf.out.Bytes(), []byte("notice")) {
fail("expected terminal output buffer to contain written message, got %q", ioBuf.out.String())
}
if len(terminal.Escape.Reset) == 0 || len(terminal.Escape.Red) == 0 {
fail("expected Terminal.Escape ANSI codes to be populated")
}
fmt.Println("PASS")
}
Исходный сидер
аноним