Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            terminalView = new TerminalView(View.Frame);
            var t    = terminalView.Terminal;
            var size = new UnixWindowSize();

            GetSize(t, ref size);

            pid = Pty.ForkAndExec("/bin/bash", new string [] { "/bin/bash" }, Terminal.GetEnvironmentVariables(), out fd, size);
            DispatchIO.Read(fd, (nuint)readBuffer.Length, DispatchQueue.CurrentQueue, ChildProcessRead);


            terminalView.UserInput += (byte [] data) => {
                DispatchIO.Write(fd, DispatchData.FromByteBuffer(data), DispatchQueue.CurrentQueue, ChildProcessWrite);
            };
            terminalView.Feed("Welcome to XtermSharp - NSView frontend!\n");
            terminalView.TitleChanged += (TerminalView sender, string title) => {
                View.Window.Title = title;
            };
            terminalView.SizeChanged += (newCols, newRows) => {
                UnixWindowSize nz = new UnixWindowSize();
                GetSize(t, ref nz);
                var res = Pty.SetWinSize(fd, ref nz);
                Console.WriteLine(res);
            };
            View.AddSubview(terminalView);
        }
Пример #2
0
        /// <summary>
        /// Notfies the subshell that the user entered some data
        /// </summary>
        public override void NotifyUserInput(byte [] data)
        {
            if (!IsRunning)
            {
                return;
            }

            DispatchIO.Write(shellFileDescriptor, DispatchData.FromByteBuffer(data), DispatchQueue.CurrentQueue, ChildProcessWrite);
        }
Пример #3
0
 static void ReceiveLoop(NWConnection connection)
 {
     connection.ReceiveData(1, uint.MaxValue, (DispatchData dispatchData, NWContentContext context, bool isComplete, NWError error) => {
         Action scheduleNext = () => {
             // If the context is marked as complete, and is the final context,
             // we're read-closed.
             if (isComplete)
             {
                 if (context != null && context.IsFinal)
                 {
                     if (verbose)
                     {
                         warn("Exiting because isComplete && context.IsFinal");
                     }
                     Environment.Exit(0);
                 }
                 if (dispatchData == null)
                 {
                     if (verbose)
                     {
                         warn($"Exiting because isComplete && data == zero;  error={error}");
                     }
                     Environment.Exit(0);
                 }
             }
             if (error == null)
             {
                 ReceiveLoop(connection);
             }
         };
         if (dispatchData != null)
         {
             const int STDOUT_FILENO = 1;
             DispatchIO.Write(STDOUT_FILENO, dispatchData, DispatchQueue.MainQueue, (data, stdoutError) => {
                 if (stdoutError != 0)
                 {
                     warn("stdout write error");
                 }
                 scheduleNext();
             });
         }
         else
         {
             scheduleNext();
         }
     });
 }
Пример #4
0
        /// <summary>
        /// Notifies the subshell that the terminal emited some data, eg a response to device status
        /// </summary>
        public override void NotifyDataEmitted(string txt)
        {
            var data = System.Text.Encoding.UTF8.GetBytes(txt);

            DispatchIO.Write(shellFileDescriptor, DispatchData.FromByteBuffer(data), DispatchQueue.CurrentQueue, ChildProcessWrite);
        }
Пример #5
0
 void HandleUserInput(byte [] data)
 {
     DispatchIO.Write(shellFileDescriptor, DispatchData.FromByteBuffer(data), DispatchQueue.CurrentQueue, ChildProcessWrite);
 }