openInEditor function

Future<void> openInEditor(
  1. String editor,
  2. String path, {
  3. bool headless = false,
})

Implementation

Future<void> openInEditor(String editor, String path, {bool headless = false}) async {
  String command;
  switch (editor) {
    case 'code':
      command = 'code';
    case 'antigravity':
      command = 'antigravity';
    default:
      command = 'code';
  }

  try {
    if (headless) {
      stdout.writeln('[nitro] opening $editor: $path');
    } else {
      stdout.writeln(gray('  🚀 Opening in $editor...'));
    }
    final result = await Process.run(command, [path]);
    if (result.exitCode != 0) {
      if (headless) {
        stderr.writeln('[nitro:error] failed to open $editor (exit ${result.exitCode})');
        if (editor == 'code') stderr.writeln('[nitro:hint] make sure the "code" command is in your PATH.');
      } else {
        stderr.writeln(red('  ✘ Failed to open $editor (exit ${result.exitCode})'));
        if (editor == 'code') stderr.writeln(gray('    Make sure the "code" command is in your PATH.'));
      }
    }
  } catch (e) {
    if (headless) {
      stderr.writeln('[nitro:error] error launching $editor: $e');
    } else {
      stderr.writeln(red('  ✘ Error launching $editor: $e'));
    }
  }
}