Exemplo n.º 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);
        }
Exemplo n.º 2
0
        void ChildProcessRead(DispatchData data, int error)
        {
            using (var map = data.CreateMap(out var buffer, out var size)) {
                // Faster, but harder to debug:
                // terminalView.Feed (buffer, (int) size);
                //Console.WriteLine ("Read {0} bytes", size);
                if (size == 0)
                {
                    View.Window.Close();
                    return;
                }
                byte [] copy = new byte [(int)size];
                Marshal.Copy(buffer, copy, 0, (int)size);

                System.IO.File.WriteAllBytes("/tmp/log-" + (x++), copy);
                terminalView.Feed(copy);
            }
            DispatchIO.Read(fd, (nuint)readBuffer.Length, DispatchQueue.CurrentQueue, ChildProcessRead);
        }