Skip to content

Windows: initialCommand with \n causes cursor at start instead of auto-executing #234

@kshivang

Description

@kshivang

Issue Summary

When using TabbedTerminal or createTab() with initialCommand parameter on Windows, appending \n to the command causes the cursor to appear at the START of the command instead of executing it.

Reproduction Steps

  1. On Windows (PowerShell or CMD)
  2. Create a TabbedTerminal with initialCommand = "cd C:\path; clear; echo test\n"
  3. Observe: Command text appears in terminal, but cursor is at the START of the command line
  4. Expected: Command should execute automatically (like it does on Linux/macOS)

Actual Behavior on Windows

cd C:\path; clear; echo test
█                              <-- cursor here (at start)

User must press Enter manually to execute the command.

Expected Behavior

cd C:\path; clear; echo test
C:\path> █                     <-- cursor here (after execution)

Command should auto-execute, just like on Linux/macOS.

Root Cause Analysis

BossTerm on Windows appears to process the \n character before rendering the command text:

  1. Processes \n → moves to next line
  2. Displays command text
  3. Stops (no execution)

On Linux/macOS, BossTerm processes it correctly:

  1. Displays command text
  2. Processes \n → executes command

Platform Details

  • OS: Windows 10/11
  • Shell: PowerShell 5.x / PowerShell 7.x / CMD
  • BossTerm Version: 1.0.82
  • Kotlin Version: 2.0.21

Code Example

val state = rememberTabbedTerminalState()

TabbedTerminal(
    state = state,
    initialCommand = "echo 'Hello World'\n",  // Appends \n for auto-execution
    workingDirectory = "C:\Users\username\project",
    modifier = Modifier.fillMaxSize()
)

Result on Windows: Text appears, cursor at start, needs manual Enter
Result on Linux/macOS: Text appears and executes automatically ✓

Workaround (Temporary)

Use sendInput() after terminal initialization instead of initialCommand:

val state = rememberTabbedTerminalState()

TabbedTerminal(
    state = state,
    initialCommand = null,  // Don't use initialCommand
    workingDirectory = workingDirectory,
    modifier = Modifier.fillMaxSize()
)

LaunchedEffect(Unit) {
    delay(150) // Wait for terminal init
    val enterKey = if (isWindows) "\r" else "\n"
    state.sendInput("$command$enterKey".toByteArray(Charsets.UTF_8))
}

This works correctly on all platforms.

Suggested Fix

BossTerm should handle initialCommand with trailing \n consistently across all platforms:

  1. Display the command text first
  2. Then process the \n to execute it

Or alternatively:

  • Automatically append \n on Windows (like it does on Linux/macOS)
  • Document the platform difference if this behavior is intentional

Impact

This affects any application using BossTerm that wants to auto-execute commands on Windows, including:

  • Workspace initialization commands
  • Runner/task execution in terminal tabs
  • Any automated terminal command execution

Context

Discovered while working on BossConsole's workspace and runner integration. We attempted to fix this by appending \n to initialCommand on Windows (commits 529ab6ca and 5ebc65b2), but this resulted in the cursor appearing at the start of the command line instead of executing the command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions