Skip to content

feat: add Windows native support via platform terminal abstraction#70

Open
woodhaha wants to merge 2 commits into
googlecolab:mainfrom
woodhaha:windows-support
Open

feat: add Windows native support via platform terminal abstraction#70
woodhaha wants to merge 2 commits into
googlecolab:mainfrom
woodhaha:windows-support

Conversation

@woodhaha

Copy link
Copy Markdown

Summary

Replace Unix-only termios/tty/signal.SIGWINCH with a cross-platform _terminal module, making Colab CLI run natively on Windows.

Changes

File Change
src/colab_cli/_terminal.py NEW — 142-line platform abstraction: SetConsoleMode/GetConsoleMode via ctypes on Windows, termios/tty on Unix
src/colab_cli/console.py Replace termios/tty/signal.SIGWINCH with _terminal API
src/colab_cli/commands/automation.py /dev/ttyCON on Windows for Drive auth prompt
tests/test_console.py Update mocks for _terminal API

How it works

os.name == "nt"  →  ctypes + msvcrt (SetConsoleMode / GetConsoleMode)
os.name != "nt"  →  termios + tty (unchanged Unix behavior)
API Windows Unix
set_raw(fd) ~LINE_INPUT, ~ECHO_INPUT, ~PROCESSED_INPUT, +VIRTUAL_TERMINAL_INPUT tty.setraw()
restore(fd, old) SetConsoleMode restore termios.tcsetattr()
register_resize_handler(cb) Background thread polling os.get_terminal_size() @ 500ms signal.SIGWINCH

Testing

  • ✅ All 10 console + automation tests pass on Windows
  • colab --version / colab --help works
  • colab --auth=adc new -s test --gpu T4 — session created
  • colab --auth=adc exec -s test -f script.py — remote execution works
  • colab --auth=adc sessions — session listing works
  • ✅ Zero regressions on Unix (termios path untouched)

🤖 Generated with Claude Code

Replace Unix-only `termios`/`tty`/`signal.SIGWINCH` with a cross-platform
`_terminal` module that uses the Windows Console API (SetConsoleMode /
GetConsoleMode via ctypes) on `nt` and the existing termios code on Unix.

Changes:
- NEW:  src/colab_cli/_terminal.py — platform abstraction for raw mode,
        resize handler registration, and terminal restoration
- MOD:  src/colab_cli/console.py — import _terminal instead of
        termios/tty/signal; use set_raw/restore/register_resize_handler
- MOD:  src/colab_cli/commands/automation.py — /dev/tty → CON on Windows
- MOD:  tests/test_console.py — update mocks for _terminal API

All 10 console + automation tests pass on Windows (6 console, 4 automation).
Verified end-to-end: colab new/exec/sessions all work natively on Windows.

Co-Authored-By: Claude <noreply@anthropic.com>
@google-cla

google-cla Bot commented Jun 26, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant