execute method
Execute the command.
Implementation
@override
Future<CommandResult> execute(String args, ToolUseContext context) async {
final terminal = detectTerminal();
// Check if terminal natively supports CSI u.
if (terminal != null && nativeCSIuTerminals.containsKey(terminal)) {
final displayName = nativeCSIuTerminals[terminal]!;
return TextCommandResult(
'Shift+Enter is natively supported in $displayName.\n\n'
'No configuration needed. Just use Shift+Enter to add newlines.',
);
}
// Check if terminal is supported for setup.
if (!shouldOfferTerminalSetup()) {
final terminalName = terminal ?? 'your current terminal';
final platformTerminals = StringBuffer();
if (Platform.isMacOS) {
platformTerminals.writeln(' - macOS: Apple Terminal');
} else if (Platform.isWindows) {
platformTerminals.writeln(' - Windows: Windows Terminal');
}
return TextCommandResult(
'Terminal setup cannot be run from $terminalName.\n\n'
'This command configures a convenient Shift+Enter shortcut for '
'multi-line prompts.\n'
'Note: You can already use backslash (\\) + return to add newlines.\n\n'
'To set up the shortcut (optional):\n'
'1. Exit tmux/screen temporarily\n'
'2. Run /terminal-setup directly in one of these terminals:\n'
'$platformTerminals'
' - IDE: VSCode, Cursor, Windsurf, Zed\n'
' - Other: Alacritty\n'
'3. Return to tmux/screen - settings will persist\n\n'
'Note: iTerm2, WezTerm, Ghostty, Kitty, and Warp support '
'Shift+Enter natively.',
);
}
try {
final result = await setupTerminal();
return TextCommandResult(result);
} catch (e) {
return TextCommandResult('Terminal setup failed: $e');
}
}