diff --git a/bin/clide.dart b/bin/clide.dart index 57969921..e4a1426f 100644 --- a/bin/clide.dart +++ b/bin/clide.dart @@ -142,9 +142,10 @@ Future _runDaemon(List args) async { socketPath: socketPath, dispatch: dispatcher.dispatch, ); + final ptycPath = _resolvePtycPath(); final events = _ServerEventSink(server); final registry = PaneRegistry(events: events); - registerPaneCommands(dispatcher, registry); + registerPaneCommands(dispatcher, registry, defaultPtycPath: ptycPath); final files = FilesService.atCwd(events: events); registerFilesCommands(dispatcher, files); @@ -423,6 +424,20 @@ void _emitError({ stderr.writeln(jsonEncode(err.toJson())); } +String _resolvePtycPath() { + final self = Platform.resolvedExecutable; + final binDir = File(self).parent.path; + final candidates = [ + '$binDir/../ptyc/bin/ptyc', + '$binDir/ptyc', + 'ptyc', + ]; + for (final c in candidates) { + if (File(c).existsSync()) return c; + } + return 'ptyc'; +} + Never _die(String msg) { _emitError( code: IpcExitCode.userError, diff --git a/lib/src/daemon/pane_commands.dart b/lib/src/daemon/pane_commands.dart index 4e451573..3d157852 100644 --- a/lib/src/daemon/pane_commands.dart +++ b/lib/src/daemon/pane_commands.dart @@ -17,8 +17,8 @@ import '../panes/pane.dart'; import '../panes/registry.dart'; import 'dispatcher.dart'; -void registerPaneCommands(DaemonDispatcher d, PaneRegistry registry) { - d.register('pane.spawn', (req) => _spawn(req, registry)); +void registerPaneCommands(DaemonDispatcher d, PaneRegistry registry, {String defaultPtycPath = 'ptyc'}) { + d.register('pane.spawn', (req) => _spawn(req, registry, defaultPtycPath)); d.register('pane.list', (req) => _list(req, registry)); d.register('pane.close', (req) => _close(req, registry)); d.register('pane.write', (req) => _write(req, registry)); @@ -47,7 +47,7 @@ IpcResponse _notFound(String id, String message) => IpcResponse.err( ), ); -Future _spawn(IpcRequest req, PaneRegistry registry) async { +Future _spawn(IpcRequest req, PaneRegistry registry, String defaultPtycPath) async { final args = req.args; final rawArgv = args['argv']; if (rawArgv is! List || rawArgv.isEmpty) { @@ -84,7 +84,7 @@ Future _spawn(IpcRequest req, PaneRegistry registry) async { cols: (args['cols'] as num?)?.toInt() ?? 80, rows: (args['rows'] as num?)?.toInt() ?? 24, title: args['title'] as String?, - ptycPath: (args['ptyc_path'] as String?) ?? 'ptyc', + ptycPath: (args['ptyc_path'] as String?) ?? defaultPtycPath, ); return IpcResponse.ok(id: req.id, data: pane.toJson()); } catch (e) {