Пример #1
0
		static public string ConsoleEditString(this string @default, string prefix = null)
		{
			var Editor = new LineEditor(null);

			Editor.TabAtStartCompletes = true;

			return Editor.Edit(prefix ?? "", @default);
		}
Пример #2
0
        static void Main()
        {
            LineEditor le = new LineEditor("foo");
            string     s;

            while ((s = le.Edit("shell> ", "")) != null)
            {
                Console.WriteLine("----> [{0}]", s);
            }
        }
Пример #3
0
    public void Interactive()
    {
        var    lineEditor = new Mono.Terminal.LineEditor("muget");
        string s;

        while ((s = lineEditor.Edit("muget> ", "")) != null)
        {
            Run(s.Split(' '), true);
        }
    }
Пример #4
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();
     }
 }
Пример #5
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);
            }
        }
Пример #6
0
    void SetupConsole()
    {
        if (is_unix)
        {
            string term = Environment.GetEnvironmentVariable("TERM");
            dumb = term == "dumb" || term == null || isatty == false;
        }
        else
        {
            dumb = false;
        }

        editor = new Mono.Terminal.LineEditor("csharp", 300)
        {
            HeuristicsMode = "csharp"
        };
        InteractiveBaseShell.Editor = editor;

        editor.AutoCompleteEvent += delegate(string s, int pos){
            string    prefix      = null;
            string    complete    = s.Substring(0, pos);
            string [] completions = evaluator.GetCompletions(complete, out prefix);
            return(new Mono.Terminal.LineEditor.Completion(prefix, completions));
        };
#if false
        //
        // This is a sample of how completions sould be implemented.
        //
        editor.AutoCompleteEvent += delegate(string s, int pos){
            // Single match: "Substring": Sub-string
            if (s.EndsWith("Sub"))
            {
                return(new string [] { "string" });
            }

            // Multiple matches: "ToString" and "ToLower"
            if (s.EndsWith("T"))
            {
                return(new string [] { "ToString", "ToLower" });
            }
            return(null);
        };
#endif
        Console.CancelKeyPress += ConsoleInterrupt;
    }
Пример #7
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;
        }
Пример #8
0
        static void Main()
        {
            LineEditor le = new LineEditor("foo")
            {
                HeuristicsMode = "csharp"
            };

            le.AutoCompleteEvent += delegate(string a, int pos){
                string prefix      = "";
                var    completions = new string [] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };
                return(new Mono.Terminal.LineEditor.Completion(prefix, completions));
            };

            string s;

            while ((s = le.Edit("shell> ", "")) != null)
            {
                Console.WriteLine("----> [{0}]", s);
            }
        }
        public void Run()
        {
            var le = new LineEditor(
                Config.ConsoleMode.AppName,
                Config.ConsoleMode.HistorySize.GetValueOrDefault(10))
                     	{
                     		AutoCompleteEvent = (text, pos) => GetEntries(text)
                     	};

            using (CommandsOptions.HideCommandOfType<ConsoleCommand>())
            {
                Writer.WriteLines(
                    "Type ctrl+c to exit.",
                    "Type \"cls\" to clear the console window.",
                    "Type \"> filename\" to redirect output to a file.");

                do
                {
                    string[] args;
                    do
                    {
                        args = le.Edit(Config.ConsoleMode.CommandPromptText +  "> ", string.Empty).SplitCmdLineArgs();
                    } while (args.IsNullOrEmpty());

                    if (args[0].Equals("cls", StringComparison.OrdinalIgnoreCase))
                    {
                        Console.Clear();
                    }
                    else if (args[0].Equals(CommandName, StringComparison.OrdinalIgnoreCase))
                    {
                        //already in console mode
                    }
                    else
                    {
                        le.SaveHistory();
                        RunCommand(args);
                    }

                } while (true);
            }
        }
Пример #10
0
        private void Run()
        {
            Stopwatch stopwatch = new Stopwatch();
            Console.Write("Constructing search tree...");
            stopwatch.Start();
            var wordFinder = new WordFinder(@"C:\Users\Daniel\Dropbox\Programming\TernarySearchTree\swedish-word-list-bigger.txt", Encoding.UTF8, Language.Swedish);
            //var wordFinder = new WordFinder(@"C:\Users\danlid\Dropbox\Programming\TernarySearchTree\english-word-list.txt", Encoding.UTF8, Language.English);
            //var wordFinder = new WordFinder(@"C:\Users\danlid\Dropbox\Programming\TernarySearchTree\swedish-english.txt", Encoding.UTF8, Language.Swedish);
            stopwatch.Stop();
            Console.WriteLine("{0} ms", stopwatch.ElapsedMilliseconds);

            Console.WriteLine("Enter word to search for. A single 'q' exits.");
            var lineEditor = new LineEditor("input");
            string input = lineEditor.Edit(": ", string.Empty);
            while (input != "q")
            {
                do
                {
                    if (string.IsNullOrWhiteSpace(input))
                        break;

                    stopwatch.Restart();
                    var matches = wordFinder.Matches(input, 2, 100);
                    stopwatch.Stop();
                    if (matches.Count > 0)
                    {
                        Console.WriteLine("Found {0} words matching '{1}':", matches.Count, input);
                        matches.ForEach(m => Console.WriteLine("{0,-7}: {1}", m.Type, m.Value));
                    }
                    else
                    {
                        Console.WriteLine("Did not find any words matching '{0}'", input);
                    }

                    Console.WriteLine("Search completed in {0:F2} ms. Visited {1} nodes.", 1000.0 * stopwatch.ElapsedTicks / Stopwatch.Frequency, wordFinder.Nodes);
                }
                while (false);
                input = lineEditor.Edit(": ", string.Empty);
            }
        }
Пример #11
0
    public void Interactive()
    {
        var lineEditor = new Mono.Terminal.LineEditor ("muget");
        string s;

        while ((s = lineEditor.Edit ("muget> ", "")) != null){
            Run (s.Split (' '), true);
        }
    }
Пример #12
0
		static void Main ()
		{
			LineEditor le = new LineEditor (null);
			string s;
			
			while ((s = le.Edit ("shell> ", "")) != null){
				Console.WriteLine ("----> [{0}]", s);
			}
		}
Пример #13
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);
            }
        }
Пример #14
0
    void SetupConsole()
    {
        if (is_unix) {
            string term = Environment.GetEnvironmentVariable ("TERM");
            dumb = term == "dumb" || term == null || isatty == false;
        } else {
            dumb = false;
        }

        editor = new Mono.Terminal.LineEditor ("csharp", 300) {
            HeuristicsMode = "csharp"
        };
        InteractiveBaseShell.Editor = editor;

        editor.AutoCompleteEvent += delegate (string s, int pos){
            string prefix = null;
            string complete = s.Substring (0, pos);
            string [] completions = evaluator.GetCompletions (complete, out prefix);
            return new Mono.Terminal.LineEditor.Completion (prefix, completions);
        };
        #if false
        //
        // This is a sample of how completions sould be implemented.
        //
        editor.AutoCompleteEvent += delegate (string s, int pos){

            // Single match: "Substring": Sub-string
            if (s.EndsWith ("Sub")){
                return new string [] { "string" };
            }

            // Multiple matches: "ToString" and "ToLower"
            if (s.EndsWith ("T")){
                return new string [] { "ToString", "ToLower" };
            }
            return null;
        };
        #endif
        Console.CancelKeyPress += ConsoleInterrupt;
    }
Пример #15
0
        public static int Main(string[] args)
        {
            var show_help = false;
            var use_precompiled = true;
            var options = new OptionSet {
                {"p|no-precomp", "do not use precompiled libraries", v => use_precompiled = v == null},
                {"h|help", "show this message and exit", v => show_help = v != null}
            };

            List<string> files;
            try {
                files = options.Parse(args);
            } catch (OptionException e) {
                Console.Error.Write(AppDomain.CurrentDomain.FriendlyName + ": ");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Try “" + AppDomain.CurrentDomain.FriendlyName + " --help” for more information.");
                return 1;
            }

            if (show_help) {
                Console.WriteLine("Usage: " + AppDomain.CurrentDomain.FriendlyName + " input.flbgst");
                Console.WriteLine("Run Flabbergast interactively.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return 1;
            }

            if (files.Count > 1) {
                Console.Error.WriteLine("No more than one Flabbergast script may be given.");
                return 1;
            }

            Frame original = null;

            var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Repl"), AssemblyBuilderAccess.Run);
            var module_builder = assembly_builder.DefineDynamicModule("ReplModule");
            var unit = new CompilationUnit(module_builder, false);
            var collector = new ConsoleCollector();
            var task_master = new ConsoleTaskMaster();
            task_master.AddUriHandler(BuiltInLibraries.INSTANCE);
            if (use_precompiled) {
                task_master.AddUriHandler(new LoadPrecompiledLibraries());
            }
            task_master.AddUriHandler(new DynamicallyCompiledLibraries(collector));

            if (files.Count == 1) {
                var parser = Parser.Open(files[0]);
                var root_type = parser.ParseFile(collector, unit, "REPLRoot");
                if (root_type != null) {
                    var computation = (Computation) Activator.CreateInstance(root_type, task_master);
                    computation.Notify(r => original = r as Frame);
                    task_master.Slot(computation);
                    task_master.Run();
                    task_master.ReportCircularEvaluation();
                }
            }
            if (original == null) {
                original = new Frame(task_master, task_master.NextId(), new SourceReference("<repl>", "<native>", 0, 0, 0, 0, null), null, null);
            }

            var id = 0;
            Frame current = original;
            bool run = true;
            ConsumeResult update_current = (x) => current = (x as Frame) ?? current;

            var line_editor = new LineEditor("flabbergast");
            var completables = new Completables();
            line_editor.AutoCompleteEvent = completables.Handler;
            string s;

            while (run && (s = line_editor.Edit(id + "‽ ", "")) != null) {
                var parser = new Parser("line" + id, s);
                var run_type = parser.ParseRepl(collector, unit, "REPL" + id++);
                if (run_type != null) {
                    object result = null;
                    var computation = (Computation) Activator.CreateInstance(run_type, new object[] { task_master, original, current, update_current, (ConsumeResult) (output => result = output), (ConsumeResult) Console.WriteLine });
                    computation.Notify(r => run = (r as bool?) ?? true);
                    task_master.Slot(computation);
                    task_master.Run();
                    if (result != null) {
                        HandleResult(result);
                    }
                    task_master.ReportCircularEvaluation();
                }
            }
            line_editor.SaveHistory();
            return 0;
        }
Пример #16
0
		void SetupConsole ()
		{

			if (is_unix)
            {
				var term = Environment.GetEnvironmentVariable("TERM");
				dumb = term == "dumb" || term == null || isatty == false;
			}
            
            else
				dumb = false;
			

			_Editor = new LineEditor("PipesShell", 300);
			InteractiveBaseShell.Editor = _Editor;

			_Editor.AutoCompleteEvent += delegate(String myString, Int32 myPosition)
            {
				
                String prefix = null;

				var complete    = myString.Substring(0, myPosition);				
				var completions = evaluator.GetCompletions(complete, out prefix);
				
				return new Mono.Terminal.LineEditor.Completion(prefix, completions);

			};
			
#if false
			//
			// This is a sample of how completions sould be implemented.
			//
			editor.AutoCompleteEvent += delegate (string s, int pos){

				// Single match: "Substring": Sub-string
				if (s.EndsWith ("Sub")){
					return new string [] { "string" };
				}

				// Multiple matches: "ToString" and "ToLower"
				if (s.EndsWith ("T")){
					return new string [] { "ToString", "ToLower" };
				}
				return null;
			};
#endif
			
			Console.CancelKeyPress += ConsoleInterrupt;

		}
Пример #17
0
 public ScriptConsole()
 {
     _editor = new LineEditor ("scriptcs");
 }
Пример #18
0
        public static void Main(string[] args)
        {
            var c = new WebDavConnection ();

            bool show_help = false;
            bool show_version = false;
            var o = new OptionSet {
                "Usage: webdav [OPTIONS]",
                "",
                "Simple WebDav command-line client to excercise WebDavClient.",
                "",
                "Options:",
                { "server=",
                  "Set name of WebDAV {SERVER} to connect to.",
                  v => c.Builder.Server = new Uri (v) },
                { "user="******"Set {USERNAME} on WebDAV server to connect to.",
                  v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential ())).UserName = v },
                { "pass="******"Set {PASSWORD} on WebDAV server to connect to.",
                  v => (c.Builder.NetworkCredential ?? (c.Builder.NetworkCredential = new NetworkCredential ())).Password = v },
                { "v",
                  "Show verbose communication information.",
                  v => c.Builder.Log = Console.Out },
                { "version",
                  "Show version information and exit.",
                  v => show_version = v != null },
                { "help|h|?",
                  "Show this message and exit.",
                  v => show_help = v != null },
            };

            try {
                o.Parse (args);
            } catch (Exception ex) {
                Console.Error.WriteLine ("webdav: {0}", ex.Message);
            }

            if (show_version) {
                Console.WriteLine ("webdav 0.1");
                return;
            }
            if (show_help) {
                o.WriteOptionDescriptions (Console.Out);
                return;
            }

            LineEditor e = new LineEditor ("webdav");
            string s;

            while ((s = e.Edit ("webdav> ", "")) != null) {
                if ((s = s.Trim ()).Length == 0)
                    continue;

                var p = s.IndexOf (' ');
                var m = p < 0 ? s : s.Substring (0, p);
                var a = WebDavConnection.GetCommand (m);
                if (a == null) {
                    Console.Error.WriteLine ("webdav: Invalid command: {0}", s);
                    continue;
                }
                while (p > 0 && p < s.Length && char.IsWhiteSpace (s, p))
                    ++p;
                s = p >= 0 && p < s.Length ? s.Substring (p) : "";
                a (c, s);
            }
        }
Пример #19
0
		static void Main ()
		{
			LineEditor le = new LineEditor ("foo") {
				HeuristicsMode = "csharp"
			};
			le.AutoCompleteEvent += delegate (string a, int pos){
				string prefix = "";
				var completions = new string [] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };
				return new Mono.Terminal.LineEditor.Completion (prefix, completions);
			};
			
			string s;
			
			while ((s = le.Edit ("shell> ", "")) != null){
				Console.WriteLine ("----> [{0}]", s);
			}
		}
Пример #20
0
        internal static void CommandLoop()
        {
            Logger.WriteInfoLine("Welcome to the Mono Soft Debugger CLI!");
            Logger.WriteInfoLine("Using {0} and {1} with features: {2}", typeof(VirtualMachine).Assembly.GetName().Name,
                typeof(SoftDebuggerSession).Assembly.GetName().Name, SoftDebugger.Features);
            Logger.WriteInfoLine("Type \"Help\" for a list of commands or \"Exit\" to quit.");

            var lineEditor = new LineEditor ("sdb");
            string line;

            while (true)
            {
                line = lineEditor.Edit ("sdb> ", "");
            if (line == null){
            if (SoftDebugger.State != DebuggerState.Null && SoftDebugger.State != DebuggerState.Initialized){
                var answer = lineEditor.Edit ("Do you really want to quit? (y/n) ", "");
                if (answer == null || answer.ToLower ().StartsWith ("y"))
                    break;
            } else
                break;
            }

                if (string.IsNullOrWhiteSpace(line))
                    continue;

                var fullCmd = line.Split(' ');
                var cmd = fullCmd[0];
                var command = Dialect.Commands.SingleOrDefault(x => x.Key.Equals(cmd, StringComparison.OrdinalIgnoreCase)).Value;

                if (command == null)
                {
                    Logger.WriteErrorLine("No such command: {0}", cmd);
                    continue;
                }

                try
                {
                    command.Execute(new CommandArguments(fullCmd.Skip(1)));
                }
                catch (Exception ex)
                {
                    Logger.WriteErrorLine("Error executing command:", cmd);
                    Logger.WriteErrorLine(ex.Message);

                    if (!(ex is CommandArgumentException))
                        Logger.WriteErrorLine(ex.StackTrace);
                }

                if (Suspended)
                {
                    ResumeEvent.WaitOne();
                    Suspended = false;
                }

                if (Stopped)
                    break;
            }

            if (SoftDebugger.State != DebuggerState.Null)
                SoftDebugger.Stop();

            if (Logger.LogOutput != null)
            {
                Logger.LogOutput.Dispose();
                Logger.LogOutput = null;
            }
        }