feat: configurable TERM env var for terminal color support
Some checks failed
Build Docker Image / build (linux/amd64) (push) Has been cancelled
Build Docker Image / build (linux/arm64) (push) Has been cancelled
Release / release (push) Has been cancelled
Build Docker Image / merge (push) Has been cancelled

Terminal sessions now set the TERM environment variable (default
xterm-256color) so programs emit ANSI color codes. Configurable via
OPEN_TERMINAL_TERM environment variable or 'term' in config.toml.
This commit is contained in:
Timothy Jaeryang Baek 2026-03-02 19:16:23 -06:00
parent 4d896916bd
commit 87b0dcfba5
4 changed files with 21 additions and 6 deletions

View file

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [0.8.2] - 2026-03-02
### Added
- 🎨 **Terminal color support** — terminal sessions now set the `TERM` environment variable (default `xterm-256color`) so programs emit ANSI color codes. Configurable via `OPEN_TERMINAL_TERM` environment variable or `term` in config.toml.
## [0.8.1] - 2026-03-02
### Added

View file

@ -70,3 +70,8 @@ ENABLE_TERMINAL = os.environ.get(
"OPEN_TERMINAL_ENABLE_TERMINAL",
str(config.get("enable_terminal", True)),
).lower() not in ("false", "0", "no")
TERMINAL_TERM = os.environ.get(
"OPEN_TERMINAL_TERM",
config.get("term", "xterm-256color"),
)

View file

@ -1,5 +1,5 @@
import asyncio
from importlib.metadata import version as _pkg_version
import fnmatch
import json
@ -24,7 +24,7 @@ from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from pydantic import BaseModel, Field
from pypdf import PdfReader
from open_terminal.env import API_KEY, BINARY_FILE_MIME_PREFIXES, CORS_ALLOWED_ORIGINS, ENABLE_TERMINAL, LOG_DIR, MAX_TERMINAL_SESSIONS
from open_terminal.env import API_KEY, BINARY_FILE_MIME_PREFIXES, CORS_ALLOWED_ORIGINS, ENABLE_TERMINAL, LOG_DIR, MAX_TERMINAL_SESSIONS, TERMINAL_TERM
from open_terminal.runner import PipeRunner, ProcessRunner, create_runner
try:
@ -69,7 +69,7 @@ async def verify_api_key(
app = FastAPI(
title="Open Terminal",
description="A remote terminal API.",
version="0.8.1",
version=_pkg_version("open-terminal"),
)
app.add_middleware(
CORSMiddleware,
@ -1223,13 +1223,15 @@ if ENABLE_TERMINAL:
fcntl.ioctl(slave_fd, termios.TIOCSWINSZ, struct.pack("HHHH", 24, 80, 0, 0))
shell = os.environ.get("SHELL", "/bin/sh")
spawn_env = os.environ.copy()
spawn_env.setdefault("TERM", TERMINAL_TERM)
process = subprocess.Popen(
[shell],
stdin=slave_fd,
stdout=slave_fd,
stderr=slave_fd,
cwd=os.getcwd(),
env=os.environ.copy(),
env=spawn_env,
start_new_session=True,
)
except Exception:
@ -1252,10 +1254,12 @@ if ENABLE_TERMINAL:
else: # winpty
shell = os.environ.get("COMSPEC", "cmd.exe")
spawn_env = os.environ.copy()
spawn_env.setdefault("TERM", TERMINAL_TERM)
pty_proc = _WinPtyProcess.spawn(
[shell],
cwd=os.getcwd(),
env=os.environ.copy(),
env=spawn_env,
dimensions=(24, 80),
)
_terminal_sessions[session_id] = {

View file

@ -1,6 +1,6 @@
[project]
name = "open-terminal"
version = "0.8.1"
version = "0.8.2"
description = "A remote terminal API."
readme = "README.md"
authors = [