Skip to content

Commit 87b0dcf

Browse files
committed
feat: configurable TERM env var for 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.
1 parent 4d89691 commit 87b0dcf

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [0.8.2] - 2026-03-02
8+
9+
### Added
10+
11+
- 🎨 **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.
12+
713
## [0.8.1] - 2026-03-02
814

915
### Added

open_terminal/env.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ def _resolve_file_env(var: str, default: str = "") -> str:
7070
"OPEN_TERMINAL_ENABLE_TERMINAL",
7171
str(config.get("enable_terminal", True)),
7272
).lower() not in ("false", "0", "no")
73+
74+
TERMINAL_TERM = os.environ.get(
75+
"OPEN_TERMINAL_TERM",
76+
config.get("term", "xterm-256color"),
77+
)

open_terminal/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
2+
from importlib.metadata import version as _pkg_version
33
import fnmatch
44
import json
55

@@ -24,7 +24,7 @@
2424
from pydantic import BaseModel, Field
2525
from pypdf import PdfReader
2626

27-
from open_terminal.env import API_KEY, BINARY_FILE_MIME_PREFIXES, CORS_ALLOWED_ORIGINS, ENABLE_TERMINAL, LOG_DIR, MAX_TERMINAL_SESSIONS
27+
from open_terminal.env import API_KEY, BINARY_FILE_MIME_PREFIXES, CORS_ALLOWED_ORIGINS, ENABLE_TERMINAL, LOG_DIR, MAX_TERMINAL_SESSIONS, TERMINAL_TERM
2828
from open_terminal.runner import PipeRunner, ProcessRunner, create_runner
2929

3030
try:
@@ -69,7 +69,7 @@ async def verify_api_key(
6969
app = FastAPI(
7070
title="Open Terminal",
7171
description="A remote terminal API.",
72-
version="0.8.1",
72+
version=_pkg_version("open-terminal"),
7373
)
7474
app.add_middleware(
7575
CORSMiddleware,
@@ -1223,13 +1223,15 @@ async def create_terminal(request: Request):
12231223
fcntl.ioctl(slave_fd, termios.TIOCSWINSZ, struct.pack("HHHH", 24, 80, 0, 0))
12241224

12251225
shell = os.environ.get("SHELL", "/bin/sh")
1226+
spawn_env = os.environ.copy()
1227+
spawn_env.setdefault("TERM", TERMINAL_TERM)
12261228
process = subprocess.Popen(
12271229
[shell],
12281230
stdin=slave_fd,
12291231
stdout=slave_fd,
12301232
stderr=slave_fd,
12311233
cwd=os.getcwd(),
1232-
env=os.environ.copy(),
1234+
env=spawn_env,
12331235
start_new_session=True,
12341236
)
12351237
except Exception:
@@ -1252,10 +1254,12 @@ async def create_terminal(request: Request):
12521254

12531255
else: # winpty
12541256
shell = os.environ.get("COMSPEC", "cmd.exe")
1257+
spawn_env = os.environ.copy()
1258+
spawn_env.setdefault("TERM", TERMINAL_TERM)
12551259
pty_proc = _WinPtyProcess.spawn(
12561260
[shell],
12571261
cwd=os.getcwd(),
1258-
env=os.environ.copy(),
1262+
env=spawn_env,
12591263
dimensions=(24, 80),
12601264
)
12611265
_terminal_sessions[session_id] = {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "open-terminal"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
description = "A remote terminal API."
55
readme = "README.md"
66
authors = [

0 commit comments

Comments
 (0)