コード例 #1
0
ファイル: Interactive.cs プロジェクト: shupoval/FarNet
        protected override void Invoke(string code, InteractiveArea area)
        {
            if (Runspace == null)
            {
                EditorOutputWriter2 writer = new EditorOutputWriter2(Editor);
                A.Psf.Act(code, writer, false);
                return;
            }

            // begin editor
            FarUI.PushWriter(new EditorOutputWriter1(Editor));

            // begin command
            PowerShell          = PowerShell.Create();
            PowerShell.Runspace = Runspace;
            PowerShell.Commands.AddScript(code).AddCommand(A.OutHostCommand);
            PowerShell.BeginInvoke <PSObject>(null, null, AsyncInvoke, null);
        }
コード例 #2
0
        internal bool Invoke()
        {
            var area = GetCommandArea();
            if (area == null)
                return false;

            // script, skip empty
            var sb = new StringBuilder();
            for (int y = area.FirstLineIndex; y < area.LastLineIndex; ++y)
                sb.AppendLine(Editor[y].Text);
            var lastText = Editor[area.LastLineIndex].Text;
            sb.Append(lastText);

            string code = sb.ToString();
            if (code.Length == 0)
                return true;
            if (code == OutputMark3)
                return false;

            // copy to the end
            if (!area.Active)
            {
                Editor.GoToEnd(true);
                Editor.BeginUndo();
                Editor.InsertText(code);
                Editor.EndUndo();
                Editor.Redraw();
                return true;
            }

            // history
            bool addHistory = area.FirstLineIndex == area.LastLineIndex;

            // go end
            Editor.GoToEnd(false);

            // go async
            if (Runspace != null)
            {
                InvokePipeline(code, addHistory);
                return true;
            }

            // invoke
            EditorOutputWriter2 writer = new EditorOutputWriter2(Editor);
            Editor.BeginUndo();

            // default runspace
            A.Psf.Act(code, writer, addHistory);
            if (Editor != Far.Api.Editor)
            {
                Far.Api.Message(Res.EditorConsoleCannotComplete);
            }
            else
            {
                // complete output
                EndOutput(writer);
                Editor.EndUndo();
                Editor.Redraw();
            }

            return true;
        }