Exemplo n.º 1
0
 protected void WriteInputBuffer()
 {
     StdOut.Write("\x1b[u");
     StdOut.Write(InputBuffer);
     StdOut.Write("\x1b[K");
     UpdateCursor();
 }
Exemplo n.º 2
0
 protected override void Run()
 {
     if (Argv.Count == 1)
     {
         // Read from stdin
     }
     else
     {
         for (int i = 1; i < Argv.Count; i++)
         {
             NixPath path = OpenPath(Argv[i]);
             if (MainSystem.RootDrive.IsFileOrDirectory(path))
             {
                 try
                 {
                     using (Stream file = MainSystem.RootDrive.OpenFile(path, FileAccess.Read, FileMode.Open))
                     {
                         StreamReader reader = new StreamReader(file);
                         StdOut.Write(reader.ReadToEnd());
                     }
                 }
                 catch (System.Exception exp)
                 {
                     StdOut.WriteLine("Error reading file for cat: " + exp.Message);
                 }
             }
             else
             {
                 StdOut.Write(GetCommand() + ": " + Argv[i] + ": No such file or directory\n");
             }
         }
     }
 }
Exemplo n.º 3
0
                public void BeginInput()
                {
                    string result = ParsePS1(MainSession.GetEnvValue("PS1"));

                    StdOut.Write(result);
                    // Important!
                    StdOut.Write("\x1b[s");
                }
Exemplo n.º 4
0
                protected override void Run()
                {
                    // TODO Change to string builder
                    string output = "";

                    for (int i = 1; i < Argv.Count; i++)
                    {
                        if (i > 1)
                        {
                            output += " ";
                        }
                        output += Argv[i];
                    }
                    output += "\n";
                    StdOut.Write(output);
                    return;
                }
Exemplo n.º 5
0
 private void InputRun()
 {
     while (Running)
     {
         int input = InputStream.ReadByte();
         if (input == '\r' || input == '\n')
         {
             string temp = InputBuffer + input;
             InputBuffer = "";
             //if (StdIn.EchoStream)
             {
                 UnityEngine.Debug.Log("Echoing input: " + temp);
                 StdOut.Write(temp);
             }
             StdIn.Write(temp);
         }
         else if (input != '\0')
         {
             InputBuffer += input;
         }
         PushEvent(new InputEvent(KeyboardDown, input));
     }
 }
Exemplo n.º 6
0
        private void ProcessTransferOutEvent(ConsoleTransferEventStruct e)
        {
            using (_logger.CreateCallstack())
            {
                _logger.WriteLine("Len [{0}]", e.Len);

                if (StdOut == null)
                {
                    throw _logger.WriteException(new InvalidOperationException("Unexpected data"));
                }
                int len = (int)e.Len;
                if (len > 0)
                {
                    StdOut.Write(e.Data, 0, len);
                    _logger.WriteLine("Data written to the buffer");
                }
                else
                {
                    StdOut.CloseWrite();
                    _logger.WriteLine("Data buffer closed");
                }
            }
        }
Exemplo n.º 7
0
                protected override void Run()
                {
                    NixPath newPath = MainSession.PhysicalDirectory;

                    if (Argv.Count > 1)
                    {
                        //newPath = MainSession.WorkingDirectory.Combine(Argv[1]);
                        newPath = OpenPath(Argv[1]);
                    }

                    SOD.Nix.FileSystem.FileNode[] files = MainSystem.RootDrive.ListFiles(newPath.ToString());
                    if (files != null)
                    {
                        for (int i = 0; i < files.Length; i++)
                        {
                            FileInfo info = files[i].Info;
                            if (files[i].Symlink != null)
                            {
                                StdOut.Write("@");
                            }
                            StdOut.Write(info.Name);
                            if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                StdOut.Write("/");
                            }
                            if (files[i].Symlink != null)
                            {
                                StdOut.Write(" -> " + files[i].Symlink.ToString());
                            }
                            StdOut.Write("\n");
                        }
                    }
                    else
                    {
                        StdOut.Write(newPath.ToString() + " is not a directory.\n");
                    }
                }
Exemplo n.º 8
0
                protected override void Run()
                {
                    if (Argv.Count <= 1)
                    {
                        StdOut.WriteLine("Need help");
                        return;
                    }
                    try{
                        NixPath newPath      = MainSession.WorkingDirectory.Combine(Argv[1]).ResolvePath();
                        NixPath followedPath = MainSystem.RootDrive.FollowLinks(MainSession.PhysicalDirectory.Combine(Argv[1]));

                        if (MainSystem.RootDrive.IsDirectory(followedPath))
                        {
                            MainSession.SetWorkingDirectory(newPath);
                        }
                        else
                        {
                            StdOut.Write(newPath.ToString() + " is not a directory.\n");
                        }
                    }
                    catch (System.Exception exp) {
                        Debug.Log("CD EXP: " + exp.Message);
                    }
                }
Exemplo n.º 9
0
 protected override void Run()
 {
     StdOut.Write(0x1b);
     StdOut.Write("[2J");
 }
Exemplo n.º 10
0
 protected void UpdateCursor()
 {
     StdOut.Write("\x1b[u\x1b[" + Cursor + "C");
 }
Exemplo n.º 11
0
                protected void ProcessInputEvent(Program.InputEvent keyEvent)
                {
                    int c = keyEvent.KeyCode;

                    if (c != '\0')
                    {
                        if (c == '\r' || c == '\n')
                        {
                            StdOut.Write("\n");
                            if (InputBuffer.Length > 1 &&
                                (History.Count == 0 || (History.Count > 0 && History[History.Count - 1] != InputBuffer)))
                            {
                                History.Add(InputBuffer);
                            }
                            HistoryPosition = History.Count;
                            Execute(InputBuffer);
                            BeginInput();
                            SetInputBuffer("");
                            Cursor = 0;
                        }
                        else if (c == '\t')
                        {
                            //InputBuffer = AutocompleteInput(InputBuffer, InputBuffer.Length - 1);
                            SetInputBuffer(AutocompleteInput(InputBuffer, Cursor - 1));
                            Cursor = InputBuffer.Length;
                        }
                        else
                        {
                            try
                            {
                                InputBuffer = InputBuffer.Insert(Cursor, c.ToString());
                            }
                            catch (Exception exp)
                            {
                                InputBuffer += c;
                            }

                            Cursor++;
                        }
                        WriteInputBuffer();
                    }
                    // Check for backspace
                    else if (keyEvent.KeyCode == 8)
                    {
                        if (InputBuffer.Length > 0)
                        {
                            if (Cursor > 0)
                            {
                                InputBuffer = InputBuffer.Remove(Cursor - 1, 1);
                                Cursor--;
                            }
                            WriteInputBuffer();
                        }
                    }
                    else if (keyEvent.KeyCode == 127)
                    {
                        if (InputBuffer.Length > 0)
                        {
                            if (Cursor < InputBuffer.Length)
                            {
                                InputBuffer = InputBuffer.Remove(Cursor, 1);
                            }
                            WriteInputBuffer();
                        }
                    }
                    else if (keyEvent.KeyCode == 279)
                    {
                        Cursor = InputBuffer.Length;
                        UpdateCursor();
                    }
                    else if (keyEvent.KeyCode == 278)
                    {
                        Cursor = 0;
                        UpdateCursor();
                    }
                    else if (keyEvent.KeyCode == 274)
                    {
                        Debug.Log("History: " + HistoryPosition + ", " + History.Count);
                        if (HistoryPosition >= History.Count - 1)
                        {
                            SetInputBuffer("");
                            HistoryPosition = History.Count - 1;
                            Debug.Log("Writing empty buffer");
                            WriteInputBuffer();
                            return;
                        }

                        if (HistoryPosition < 0)
                        {
                            return;
                        }
                        SetInputBuffer(History[++HistoryPosition]);
                        WriteInputBuffer();
                    }
                    else if (keyEvent.KeyCode == 273)
                    {
                        if (HistoryPosition >= History.Count)
                        {
                            HistoryPosition = History.Count - 1;
                        }
                        if (HistoryPosition < 0)
                        {
                            return;
                        }
                        SetInputBuffer(History[HistoryPosition--]);
                        if (HistoryPosition < 0)
                        {
                            HistoryPosition = 0;
                        }
                        WriteInputBuffer();
                    }
                    // Left
                    else if (keyEvent.KeyCode == 276)
                    {
                        if (Cursor > 0)
                        {
                            Cursor--;
                        }
                        UpdateCursor();
                    }
                    // Right
                    else if (keyEvent.KeyCode == 275)
                    {
                        if (Cursor < InputBuffer.Length)
                        {
                            Cursor++;
                        }
                        UpdateCursor();
                    }
                }
Exemplo n.º 12
0
 protected override void Run()
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Test out!");
     StdOut.Write(bytes, 0, bytes.Length);
 }