Пример #1
0
        public static void Main(string[] args)
        {
            var le = new LineEditor("foo")
            {
                HeuristicsMode = "csharp"
            };

            le.AutoCompleteEvent += (text, pos) => {
                var completions = new  [] {
                    "One",
                    "Two",
                    "Three",
                    "Four",
                    "Five",
                    "Six",
                    "Seven",
                    "Eight",
                    "Nine",
                    "Ten"
                };
                return(new LineEditor.Completion(string.Empty, completions));
            };

            string s;

            while ((s = le.Edit("shell> ", "")) != null)
            {
                Console.WriteLine("----> [{0}]", s);
            }
        }
Пример #2
0
        public InteractiveConsole(string appName = "gizmo", int histSize = 100)
        {
            Error = StandardStreamWriter.Create(System.Console.Error);
            Out   = StandardStreamWriter.Create(System.Console.Out);

            _lineEditor = new LineEditor(appName, histSize);
        }
Пример #3
0
        public void Calculate_index_from_position()
        {
            /*
             *   01234
             * 0 ab_cd
             * 1 efg
             * 2 hijkl
             * 3 mn op
             * 4 qrst
             */
            var sut   = new LineEditor("ab cd efg hijklmn op qrst", 5);
            var index = sut.GetIndex(0, 0); // before "a"

            Assert.AreEqual(0, index);

            index = sut.GetIndex(0, 4); // before "d"
            Assert.AreEqual(4, index);

            index = sut.GetIndex(1, 0); // before "e"
            Assert.AreEqual(6, index);

            index = sut.GetIndex(3, 3); // before "o"
            Assert.AreEqual(18, index);

            index = sut.GetIndex(5, 10); // far after "t"
            Assert.AreEqual(sut.Line.Length, index);
        }
Пример #4
0
        public static void Main(string[] args)
        {
            LineEditor lineEditor = new LineEditor("DiceShell");

            string input;

            while ((input = lineEditor.Edit("DiceShell $ ", "")) != null)
            {
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                try
                {
                    AntlrInputStream        inputStream       = new AntlrInputStream(input);
                    DiceLexer               diceLexer         = new DiceLexer(inputStream);
                    CommonTokenStream       commonTokenStream = new CommonTokenStream(diceLexer);
                    DiceParser              diceParser        = new DiceParser(commonTokenStream);
                    DiceParser.ShellContext context           = diceParser.shell();
                    DiceVisitor             visitor           = new DiceVisitor();

                    int result = (int)visitor.Visit(context);

                    Console.WriteLine(string.Format("[{0:HH:mm:ss}] {1}\n", DateTime.Now, result));
                }
                catch (Exception)
                {
                    Console.WriteLine("Parsing Error\n");
                }
            }
        }
Пример #5
0
            private void Save()
            {
                string file = LineEditor.RequestPath(TYPE, _saveLocation);

                if (file != null)
                {
                    try
                    {
                        if (File.Exists(file))
                        {
                            int selected =
                                MultipleChoice.Show("File already exists. Overwrite?", "No", "", "Yes");

                            if (selected == 2)
                            {
                                SaveGame(file);
                            }
                        }
                        else
                        {
                            SaveGame(file);
                        }
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("An error occured while saving.");
                    }
                }
            }
Пример #6
0
        public void Calculate_cursor_position_from_index()
        {
            /*
             *   01234
             * 0 ab_cd
             * 1 efg
             * 2 hijkl
             * 3 mn op
             * 4 qrst
             */
            var sut      = new LineEditor("ab cd efg hijklmn op qrst", 5);
            var position = sut.GetSoftPosition(0); // before "a"

            Assert.AreEqual((0, 0), position);

            position = sut.GetSoftPosition(4); // before "d"
            Assert.AreEqual((0, 4), position);

            position = sut.GetSoftPosition(5); // after "d"
            Assert.AreEqual((0, 5), position);

            position = sut.GetSoftPosition(6); // before "e"
            Assert.AreEqual((1, 0), position);

            position = sut.GetSoftPosition(18); // before "o"
            Assert.AreEqual((3, 3), position);

            position = sut.GetSoftPosition(99); // far after "t"
            Assert.AreEqual((4, 4), position);
        }
        public ConsoleInteractivity()
        {
            var history = new History("Mages.Repl", 300);

            _editor   = new LineEditor(history);
            _blockers = new List <CancellationRegistration>();
            Console.CancelKeyPress += OnCancelled;
        }
Пример #8
0
        public void Insert_past_end()
        {
            var sut   = new LineEditor("ab", 5);
            var index = sut.Insert(10, "c", null);

            Assert.AreEqual(3, index);
            Assert.AreEqual("abc", sut.Line);
        }
Пример #9
0
        static public string ConsoleEditString(this string @default, string prefix = null)
        {
            var editor = new LineEditor(null);

            editor.TabAtStartCompletes = true;

            return(editor.Edit(prefix ?? "", @default));
        }
Пример #10
0
        static public string ConsoleEditString(this string Default, string Prefix = null)
        {
            var Editor = new LineEditor(null);

            Editor.TabAtStartCompletes = true;

            return(Editor.Edit(Prefix ?? "", Default));
        }
Пример #11
0
            private void UpdateNames()
            {
                string[] names    = GetNames();
                string[] newNames = LineEditor.RequestStringBatch("Change names", names.Length, null, names);

                for (int i = 0; i < names.Length; i++)
                {
                    _players[i].Name = newNames[i];
                }
            }
Пример #12
0
        private static void CreateShapeLine()
        {
            MovableLine zone   = CreateGenericShape <MovableLine>("SHAPE: Line");
            SimpleLine  spline = LineEditor.CreateLineOnGameObject(zone.gameObject);

            UnityEditor.Editor splineEditorGeneric = UnityEditor.Editor.CreateEditor(zone, typeof(MovableLineEditor));
            MovableLineEditor  zoneEditor          = (MovableLineEditor)splineEditorGeneric;

            zoneEditor.ConstructSplineZone(spline);
        }
Пример #13
0
        public void StartLineEditor()
        {
            LineEditor le = new LineEditor("LineEditor", 50);

            le.AutoCompleteEvent = (string text, int pos) =>
            {
                //text = text.ToLower();
                string token = null;
                for (int i = pos - 1; i >= 0; i--)
                {
                    if (Char.IsWhiteSpace(text[i]))
                    {
                        token = text.Substring(i + 1, pos - i - 1);
                        break;
                    }
                    else if (i == 0)
                    {
                        token = text.Substring(0, pos);
                    }
                }
                List <string> results = new List <string>();
                if (token == null)
                {
                    token = string.Empty;
                    results.AddRange(CommandMatcher.AutoComplete.Select(x => x.Path).ToArray());
                }
                else
                {
                    string[] completePaths = CommandMatcher.AutoComplete
                                             .Where(x => x.Path.Length > pos)
                                             .Select(x => x.Path.Substring(pos - token.Length))
                                             .ToArray();
                    for (int i = 0; i < completePaths.Length; i++)
                    {
                        if (completePaths[i].StartsWith(token))
                        {
                            string result = completePaths[i];
                            results.Add(result.Substring(token.Length, result.Length - token.Length));
                        }
                    }
                }
                return(new LineEditor.Completion(token, results.ToArray()));
            };
            string s;

            while ((s = le.Edit("> ", "")) != null)
            {
                if (new[] { "exit", "quit", "bye", "q", "e" }.Contains(s))
                {
                    break;
                }
                CommandMatcher.CallAction(s);
            }
        }
Пример #14
0
        public void Run()
        {
            LineEditor le = new LineEditor("foo");

            // Prompts the user for input
            while (true)
            {
                string s = le.Edit("# ", "");
                Exec(s).Wait();
            }
        }
Пример #15
0
        internal CommandLineInterpreter(DebuggerOptions options, bool is_interactive)
        {
            if (options.HasDebugFlags)
            {
                Report.Initialize(options.DebugOutput, options.DebugFlags);
            }
            else
            {
                Report.Initialize();
            }

            Configuration = new DebuggerConfiguration();
#if HAVE_XSP
            if (options.StartXSP)
            {
                Configuration.SetupXSP();
            }
            else
            {
                Configuration.LoadConfiguration();
            }
#else
            Configuration.LoadConfiguration();
#endif

            Configuration.SetupCLI();

            interpreter     = new Interpreter(is_interactive, Configuration, options);
            interpreter.CLI = this;

            engine = interpreter.DebuggerEngine;
            parser = new LineParser(engine);

            if (!interpreter.IsScript)
            {
                line_editor = new LineEditor("mdb");

                line_editor.AutoCompleteEvent += delegate(string text, int pos) {
                    return(engine.Completer.Complete(text, pos));
                };

                Console.CancelKeyPress += control_c_event;
            }

            interrupt_event          = new ST.AutoResetEvent(false);
            nested_break_state_event = new ST.AutoResetEvent(false);

            main_loop_stack = new Stack <MainLoop> ();
            main_loop_stack.Push(new MainLoop(interpreter));

            main_thread = new ST.Thread(new ST.ThreadStart(main_thread_main));
            main_thread.IsBackground = true;
        }
Пример #16
0
            public void EnterActualTricks()
            {
                string[] names  = GetNames();
                int[]    actual = LineEditor.RequestIntBatch("Enter Tricks", _players.Length, names, 0, 255);

                if (actual != null)
                {
                    for (int i = 0; i < _players.Length; i++)
                    {
                        _players[i].setActualTricks((byte)actual[i]);
                    }
                }
            }
Пример #17
0
            private void RoundOver()
            {
                int[] points =
                    LineEditor.RequestIntBatch("Enter points", _players.Length, GetNames(), 0, 255);

                if (points != null)
                {
                    for (int i = 0; i < _players.Length; i++)
                    {
                        _players[i].add((byte)points[i]);
                    }
                }
            }
Пример #18
0
        public SearchWindow(EditorControl editor)
        {
            this.editor = editor;

            Cursor           = Cursors.Default;
            SearchBox        = new LineEditor(editor);
            SearchBox.Paint += SearchBoxPaint;
            SearchBox.Styles.StyleNeeded += SearchBoxStyling;
            SearchBox.CommandRejected    += SearchBoxCommandRejected;
            SearchBox.LostFocus          += SearchBoxLostFocus;
            Controls.Add(SearchBox);
            SearchBox.Text = "";
            SearchBox.EditorSettings.ShowEol = false;
        }
Пример #19
0
        public void Run()
        {
            LineEditor le = new LineEditor("foo")
            {
                HeuristicsMode = "csharp"
            };

            // Prompts the user for input
            while (true)
            {
                string s = le.Edit("# ", "");
                Exec(s).Wait();
            }
        }
Пример #20
0
        public HinterWrapper(Shell shell)
        {
            Shell      = shell;
            LineEditor = new LineEditor("iox")
            {
                HeuristicsMode      = "iodine",
                TabAtStartCompletes = false,
            };

            LineEditor.AutoCompleteEvent += (string text, int pos) => {
                var       strippedText = text.Split(' ').Last();
                string [] completions  = new string [0];
                if (text.Contains('.'))
                {
                    var attrName = text.Substring(0, text.LastIndexOf('.'));
                    var attrObj  = Shell.Iodine.CompileAndInvokeOrNull(attrName);
                    if (attrObj != null)
                    {
                        text        = text.Split(new [] { ' ', '.', '(', '[', '{', '}', ']', ')' }).Last();
                        pos         = text.Length;
                        completions = (
                            attrObj.Attributes
                            .Where(attr => attr.Key.StartsWith(text, StringComparison.Ordinal))
                            .Select(attr => attr.Key)
                            .Where(attr => !attr.StartsWith("__", StringComparison.Ordinal) && !attr.EndsWith("__", StringComparison.Ordinal))
                            .Select(attr => attr.Substring(pos))
                            .Reverse()
                            .ToArray()
                            );
                    }
                }
                else
                {
                    text        = text.Split(new [] { ' ', '.', '(', '[', '{', '}', ']', ')' }).Last();
                    pos         = text.Length;
                    completions = (
                        Shell.Iodine.Engine.Context.Globals
                        .Concat(Shell.Iodine.Engine.Context.InteractiveLocals)
                        .Where(attr => attr.Key.StartsWith(text, StringComparison.Ordinal))
                        .Select(attr => attr.Key)
                        .Where(attr => !attr.StartsWith("__", StringComparison.Ordinal) && !attr.EndsWith("__", StringComparison.Ordinal))
                        .Select(attr => attr.Substring(pos))
                        .Reverse()
                        .ToArray()
                        );
                }
                return(new LineEditor.Completion(text.Split(' ').Last(), completions));
            };
        }
Пример #21
0
        private void OpenLineEditor(LineEditor.LineData ld)
        {
            LineEditor lineEditor = new LineEditor(ld, pf.project.type);

            if (lineEditor.ShowDialog() == DialogResult.OK)
            {
                string currentItem = fileListBox.SelectedItem.ToString();

                if (!pf.project.files.ContainsKey(currentItem))
                {
                    ProjectFile.RevisedFile rf = new ProjectFile.RevisedFile
                    {
                        complete = false,
                        note     = "",
                        content  = new List <ProjectFile.FileContent>(),
                    };

                    pf.project.files.Add(currentItem, rf);
                }

                int contentId = lineEditor.newfc.contentId;

                if (pf.project.files[currentItem].content.FindIndex(line => line.contentId == contentId) != -1)
                {
                    var item = pf.project.files[currentItem].content.Single(line => line.contentId == contentId);

                    if (pf.project.files[currentItem].content.Contains(item))
                    {
                        pf.project.files[currentItem].content.Remove(item);
                    }
                }

                ProjectFile.FileContent fc = new ProjectFile.FileContent
                {
                    contentId  = lineEditor.newfc.contentId,
                    lineId     = lineEditor.newfc.lineId,
                    proposal   = lineEditor.newfc.proposal,
                    prevLineId = lineEditor.newfc.prevLineId,
                    comment    = lineEditor.newfc.comment,
                    color      = lineEditor.newfc.color
                };

                pf.project.files[currentItem].content.Add(fc);

                ListViewUpdate();

                fileChanged = true;
            }
        }
Пример #22
0
        static CommandLine()
        {
            Root        = new RootCommand();
            ResumeEvent = new AutoResetEvent(false);

            try
            {
                LibEdit.Initialize();
            }
            catch (DllNotFoundException)
            {
                // Fall back to `Mono.Terminal.LineEditor`.
                _lineEditor = new LineEditor(null);
            }
        }
Пример #23
0
        /// <summary>
        /// Static method to present a prompt in a REPL.
        /// </summary>
        /// <param name="prompt"></param>
        /// <returns></returns>
        public static string LineReader(string prompt)
        {
            if (Mode == ModeEnum.Terminal)
            {
                if (_lineEditor == null)
                {
                    _lineEditor = new LineEditor("OpenLisp.NET");
                }

                return(_lineEditor.Edit(prompt, ""));
            }

            Console.WriteLine(prompt);
            Console.Out.Flush();
            return(Console.ReadLine());
        }
Пример #24
0
        private EditorControl GetEditor()
        {
            if (commandEditor == null)
            {
                commandEditor                     = new LineEditor(editor);
                commandEditor.LostFocus          += EditorLostFocus;
                commandEditor.KeyDown            += EditorKeyDown;
                commandEditor.Paint              += EditorPaint;
                commandEditor.Styles.StyleNeeded += EditorStyleNeeded;
                commandEditor.CommandRejected    += EditorCommandRejected;
                ResetBuffer();
                Controls.Add(commandEditor);
            }

            return(commandEditor);
        }
Пример #25
0
        /// <summary>
        /// Method implements main application loop where application search configuration files, load them and
        /// then run LineEditor (emulator of Unix line terminal).
        /// </summary>
        private void Loop()
        {
            PreloadConfiguration();

            String command;

            LineEditor = new LineEditor(null);
            LineEditor.AutoCompleteEvent += OnAutoComplete;
            LineEditor.TabKeyEvent       += OnEditorTabKeyEvent;

            InvokeOnConfigurationLoaded(EventArgs.Empty);

            while ((command = LineEditor.Edit(CurrentSession.Prompt, "")) != null)
            {
                RunCommand(command);
            }
        }
Пример #26
0
 public static string Readline(string prompt)
 {
     if (mode == Mode.Terminal)
     {
         if (lineedit == null)
         {
             lineedit = new LineEditor("Mal");
         }
         return(lineedit.Edit(prompt, ""));
     }
     else
     {
         Console.Write(prompt);
         Console.Out.Flush();
         return(Console.ReadLine());
     }
 }
Пример #27
0
        public void Backspace()
        {
            //0123456789012345678901234
            var sut = new LineEditor("ab cd efg hijklmn op qrst", 5);

            var index = sut.Backspace(12);

            Assert.AreEqual(11, index);
            //012345678901234567890123
            Assert.AreEqual("ab cd efg hjklmn op qrst", sut.Line);
            Assert.AreEqual(new[] { "ab cd ", "efg ", "hjklm", "n op ", "qrst" }, sut.SoftLines);

            index = sut.Backspace(24);
            Assert.AreEqual(23, index);
            Assert.AreEqual("ab cd efg hjklmn op qrs", sut.Line);
            Assert.AreEqual(new[] { "ab cd ", "efg ", "hjklm", "n op ", "qrs" }, sut.SoftLines);
        }
        public static void Main(string[] args)
        {
            PrintIntroduction();

            LineEditor  editor    = new LineEditor("Bing Dictionary");
            var         dic       = new BingDictionary();
            var         sounder   = new Sounder();
            QueryResult LastQuery = null;

            while (true)
            {
                string line = editor.Edit("> ", string.Empty);
                if (line == null)
                {
                    break;
                }
                else
                {
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    else if (line == "-q")
                    {
                        break;
                    }
                    else if (line == "-a" || line == "-b")
                    {
                        if (LastQuery != null)
                        {
                            sounder.PronounceWord(line, LastQuery);
                        }
                        else
                        {
                            Console.WriteLine("No query history.");
                        }
                    }
                    else
                    {
                        LastQuery = dic.SearchWord(line);
                    }
                }
            }
        }
Пример #29
0
            public SafeLineEditor(
                string name,
                Action beforeRenderPrompt = null,
                Action afterRenderPrompt  = null)
            {
                if (System.Console.WindowWidth > 0 && System.Console.WindowHeight > 0)
                {
                    lineEditor = new LineEditor(name)
                    {
                        BeforeRenderPrompt = beforeRenderPrompt,
                        AfterRenderPrompt  = afterRenderPrompt
                    }
                }
                ;

                this.beforeRenderPrompt = beforeRenderPrompt;
                this.afterRenderPrompt  = afterRenderPrompt;
            }
Пример #30
0
        public void Insertion_with_linebreaks()
        {
            var sut = new LineEditor("ab cd efg", 5);

            var result = "";
            var index  = sut.Insert(5, "x\ny\nz",
                                    excessText => result = excessText);

            Assert.AreEqual(6, index);
            Assert.AreEqual("ab cdx", sut.Line);
            Assert.AreEqual("y\nz efg", result);

            index = sut.Insert(1, "\n",
                               excessText => result = excessText);
            Assert.AreEqual(1, index);
            Assert.AreEqual("a", sut.Line);
            Assert.AreEqual("b cdx", result);
        }