Пример #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
 void GetSize(Terminal terminal, ref UnixWindowSize size)
 {
     size = new UnixWindowSize()
     {
         col    = (short)terminal.Cols,
         row    = (short)terminal.Rows,
         xpixel = (short)View.Frame.Width,
         ypixel = (short)View.Frame.Height
     };
 }
Пример #3
0
 /// <summary>
 /// Ges the unix window size from the given dimensions
 /// </summary>
 protected static void GetUnixWindowSize(int cols, int rows, nfloat width, nfloat height, ref UnixWindowSize size)
 {
     size = new UnixWindowSize()
     {
         col    = (short)cols,
         row    = (short)rows,
         xpixel = (short)width,
         ypixel = (short)height
     };
 }
Пример #4
0
 static void GetUnixWindowSize(CGRect frame, int rows, int cols, ref UnixWindowSize size)
 {
     size = new UnixWindowSize()
     {
         col    = (short)cols,
         row    = (short)rows,
         xpixel = (short)frame.Width,
         ypixel = (short)frame.Height
     };
 }
Пример #5
0
        void HandleSizeChanged(int newCols, int newRows)
        {
            UnixWindowSize newSize = new UnixWindowSize();

            GetUnixWindowSize(terminalView.Frame, terminalView.Terminal.Rows, terminalView.Terminal.Cols, ref newSize);
            var res = Pty.SetWinSize(shellFileDescriptor, ref newSize);

            // TODO: log result of SetWinSize if != 0

            UpdateScroller();
        }
Пример #6
0
        /// <summary>
        /// Notifies the subshell that the size has changed
        /// </summary>
        public override void NotifySizeChanged(int newCols, int newRows, nfloat width, nfloat height)
        {
            UnixWindowSize newSize = new UnixWindowSize();

            GetUnixWindowSize(newCols, newRows, width, height, ref newSize);

            if (IsRunning)
            {
                var res = Pty.SetWinSize(shellFileDescriptor, ref newSize);
                // TODO: log result of SetWinSize if != 0
            }
            else
            {
                initialSize = newSize;
            }
        }
Пример #7
0
        /// <summary>
        /// Launches the shell
        /// </summary>
        public void StartShell(string shellPath = "/bin/bash", string [] args = null)
        {
            // TODO: throw error if already started
            terminalView.Feed(WelcomeText + "\n");

            var size = new UnixWindowSize();

            GetUnixWindowSize(terminalView.Frame, terminalView.Terminal.Rows, terminalView.Terminal.Cols, ref size);

            var shellArgs = args == null ? new string [1] : new string [args.Length + 1];

            shellArgs [0] = shellPath;
            args?.CopyTo(shellArgs, 1);

            shellPid = Pty.ForkAndExec(shellPath, shellArgs, Terminal.GetEnvironmentVariables(), out shellFileDescriptor, size);
            DispatchIO.Read(shellFileDescriptor, (nuint)readBuffer.Length, DispatchQueue.CurrentQueue, ChildProcessRead);
        }