Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 3, 2025

Fixes #149 by adding support for TERM_SESSION_ID and TERM_PROGRAM=Apple_Terminal environment variables to the Mac Terminal sample application.

Changes Made

This implementation adds Apple Terminal compatibility to the SwiftTerm Mac sample app by modifying TerminalApp/MacTerminal/ViewController.swift to:

  1. Generate unique session IDs: Each terminal session now gets a UUID-based session identifier for session restoration support
  2. Set Apple Terminal identification: Adds TERM_PROGRAM=Apple_Terminal to enable automatic directory tracking
  3. Pass custom environment: Modified the process startup to include these variables in the terminal environment

Implementation Details

// Added session ID property
private let termSessionId = UUID().uuidString

// Created environment setup function
func getTerminalEnvironment() -> [String] {
    var env = Terminal.getEnvironmentVariables(termName: "xterm-256color")
    
    // Add Apple Terminal program identification for directory tracking support
    env.append("TERM_PROGRAM=Apple_Terminal")
    
    // Add session ID for session restoration support
    env.append("TERM_SESSION_ID=\(termSessionId)")
    
    return env
}

// Modified process startup
let environment = getTerminalEnvironment()
terminal.startProcess(executable: shell, execName: shellIdiom, environment: environment)

Benefits

  • Directory Tracking: Setting TERM_PROGRAM=Apple_Terminal automatically enables directory tracking on macOS, allowing the terminal title bar to show the current working directory
  • Session Restoration: The unique session ID enables future session restoration functionality where terminal sessions can be saved and restored across app restarts
  • Compatibility: Makes the SwiftTerm Mac app behave more like the native Apple Terminal, improving user experience

Testing

The implementation has been verified to correctly:

  • Generate unique session IDs in valid UUID format
  • Include TERM_PROGRAM=Apple_Terminal in the environment
  • Include TERM_SESSION_ID=<UUID> in the environment
  • Maintain all existing environment variables from SwiftTerm's default set

This is a minimal, focused change that only affects the Mac sample application without modifying the core SwiftTerm library functionality.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: migueldeicaza <36863+migueldeicaza@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Implement #149 Implement TERM_SESSION_ID and Apple Terminal support for Mac sample app Sep 3, 2025
@Copilot Copilot AI requested a review from migueldeicaza September 3, 2025 17:06
Copilot finished work on behalf of migueldeicaza September 3, 2025 17:06
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.

Mac Apple Sample: add support for TERM_SESSION_ID

2 participants