public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            Id = request.Id;
            _terminalsManager = terminalsManager;
            _terminalSize     = request.Size;

            ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
            var cwd = GetWorkingDirectory(request.Profile);

            var args = string.Empty;

            if (!string.IsNullOrWhiteSpace(request.Profile.Location))
            {
                args = $"\"{request.Profile.Location}\" {request.Profile.Arguments}";
            }
            else
            {
                args = request.Profile.Arguments;
            }

            _terminal              = new Terminal();
            _terminal.OutputReady += _terminal_OutputReady;
            _terminal.Exited      += _terminal_Exited;
            Task.Run(() => _terminal.Start(args, cwd, terminalsManager.GetDefaultEnvironmentVariableString(request.Profile.EnvironmentVariables), request.Size.Columns, request.Size.Rows));
        }
Esempio n. 2
0
        public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            _enableBuffer = request.Profile.UseBuffer;

            _reader?.Dispose();
            _reader = null;

            Id = request.Id;
            _terminalsManager = terminalsManager;

            ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
            var cwd = GetWorkingDirectory(request.Profile);

            var args = !string.IsNullOrWhiteSpace(request.Profile.Location)
                ? $"\"{request.Profile.Location}\" {request.Profile.Arguments}"
                : request.Profile.Arguments;

            _terminal              = new Terminal();
            _terminal.OutputReady += _terminal_OutputReady;
            _terminal.Exited      += _terminal_Exited;

            Task.Factory.StartNew(() => _terminal.Start(args, cwd,
                                                        terminalsManager.GetDefaultEnvironmentVariableString(request.Profile.EnvironmentVariables),
                                                        request.Size.Columns, request.Size.Rows));
        }
Esempio n. 3
0
        public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            _terminalsManager = terminalsManager;

            var configHandle      = IntPtr.Zero;
            var spawnConfigHandle = IntPtr.Zero;
            var errorHandle       = IntPtr.Zero;

            try
            {
                configHandle = winpty_config_new(WINPTY_FLAG_COLOR_ESCAPES, out errorHandle);
                winpty_config_set_initial_size(configHandle, request.Size.Columns, request.Size.Rows);

                _handle = winpty_open(configHandle, out errorHandle);
                if (errorHandle != IntPtr.Zero)
                {
                    throw new Exception(winpty_error_msg(errorHandle));
                }

                string exe  = request.Profile.Location;
                string args = $"\"{exe}\" {request.Profile.Arguments}";
                string cwd  = GetWorkingDirectory(request.Profile);
                spawnConfigHandle = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, exe, args, cwd, null, out errorHandle);
                if (errorHandle != IntPtr.Zero)
                {
                    throw new Exception(winpty_error_msg(errorHandle).ToString());
                }

                _stdin  = CreatePipe(winpty_conin_name(_handle), PipeDirection.Out);
                _stdout = CreatePipe(winpty_conout_name(_handle), PipeDirection.In);

                if (!winpty_spawn(_handle, spawnConfigHandle, out IntPtr process, out IntPtr thread, out int procError, out errorHandle))
                {
                    throw new Exception($"Failed to start the shell process. Please check your shell settings.\nTried to start: {args}");
                }

                ShellExecutableName = Path.GetFileNameWithoutExtension(exe);
            }
            finally
            {
                winpty_config_free(configHandle);
                winpty_spawn_config_free(spawnConfigHandle);
                winpty_error_free(errorHandle);
            }

            var port = Utilities.GetAvailablePort();

            if (port == null)
            {
                throw new Exception("no port available");
            }

            Id = port.Value;

            ListenToStdOut();
        }
Esempio n. 4
0
        public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            Id = request.Id;
            _terminalsManager = terminalsManager;

            ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
            var    cwd  = GetWorkingDirectory(request.Profile);
            string args = $"\"{request.Profile.Location}\" {request.Profile.Arguments}";

            _terminal              = new Terminal();
            _terminal.OutputReady += _terminal_OutputReady;
            _terminal.Exited      += _terminal_Exited;
            Task.Run(() => _terminal.Start(args, cwd, request.Size.Columns, request.Size.Rows));
        }
Esempio n. 5
0
        public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            _terminalsManager = terminalsManager;

            var port = Utilities.GetAvailablePort();

            if (port == null)
            {
                throw new Exception("no port available");
            }

            Id = port.Value;
            ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
            var    cwd  = GetWorkingDirectory(request.Profile);
            string args = $"\"{request.Profile.Location}\" {request.Profile.Arguments}";

            _terminal              = new Terminal();
            _terminal.OutputReady += _terminal_OutputReady;
            _terminal.Exited      += _terminal_Exited;
            Task.Run(() => _terminal.Start(args, cwd, request.Size.Columns, request.Size.Rows));
        }
Esempio n. 6
0
        public void Start(CreateTerminalRequest request, TerminalsManager terminalsManager)
        {
            Id = request.Id;
            _terminalsManager = terminalsManager;
            _terminalSize     = request.Size;

            var configHandle      = IntPtr.Zero;
            var spawnConfigHandle = IntPtr.Zero;
            var errorHandle       = IntPtr.Zero;

            try
            {
                configHandle = winpty_config_new(WINPTY_FLAG_COLOR_ESCAPES, out errorHandle);
                winpty_config_set_initial_size(configHandle, request.Size.Columns, request.Size.Rows);

                _handle = winpty_open(configHandle, out errorHandle);
                if (errorHandle != IntPtr.Zero)
                {
                    throw new Exception(winpty_error_msg(errorHandle));
                }

                var cwd  = GetWorkingDirectory(request.Profile);
                var args = request.Profile.Arguments;

                if (!string.IsNullOrWhiteSpace(request.Profile.Location))
                {
                    args = $"\"{request.Profile.Location}\" {args}";
                }

                spawnConfigHandle = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, request.Profile.Location, args, cwd, terminalsManager.GetDefaultEnvironmentVariableString(request.Profile.EnvironmentVariables), out errorHandle);
                if (errorHandle != IntPtr.Zero)
                {
                    throw new Exception(winpty_error_msg(errorHandle));
                }

                _stdin  = CreatePipe(winpty_conin_name(_handle), PipeDirection.Out);
                _stdout = CreatePipe(winpty_conout_name(_handle), PipeDirection.In);

                if (!winpty_spawn(_handle, spawnConfigHandle, out IntPtr process, out IntPtr thread, out int procError, out errorHandle))
                {
                    throw new Exception($@"Failed to start the shell process. Please check your shell settings.{Environment.NewLine}Tried to start: {request.Profile.Location} ""{request.Profile.Arguments}""");
                }

                var shellProcessId = ProcessApi.GetProcessId(process);
                _shellProcess = Process.GetProcessById(shellProcessId);
                _shellProcess.EnableRaisingEvents = true;
                _shellProcess.Exited += _shellProcess_Exited;

                if (!string.IsNullOrWhiteSpace(request.Profile.Location))
                {
                    ShellExecutableName = Path.GetFileNameWithoutExtension(request.Profile.Location);
                }
                else
                {
                    ShellExecutableName = request.Profile.Arguments.Split(' ')[0];
                }
            }
            finally
            {
                winpty_config_free(configHandle);
                winpty_spawn_config_free(spawnConfigHandle);
                winpty_error_free(errorHandle);
            }

            ListenToStdOut();
        }
 public TerminalsController(TerminalsManager terminalsManager)
 {
     _terminalsManager = terminalsManager ?? throw new ArgumentNullException(nameof(terminalsManager));
 }