Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var file    = Property("file");
            var dicPath = Property("dicpath");

            long seed          = 0;
            bool useCustomSeed = Int64.TryParse(Property("seed"), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out seed);

            Title = "Rant Console" + (Flag("nsfw") ? " [NSFW]" : "");

            var rant = new RantEngine(String.IsNullOrEmpty(dicPath) ? "dictionary" : dicPath, Flag("nsfw") ? NsfwFilter.Allow : NsfwFilter.Disallow);

            rant.AddHook("load", hArgs => hArgs.Length != 1 ? "" : rant.DoFile(hArgs[0]));

            if (!String.IsNullOrEmpty(file))
            {
                try
                {
                    PrintOutput(useCustomSeed ? rant.DoFile(file, seed) : rant.DoFile(file), true);
                }
                catch (Exception ex)
                {
                    ForegroundColor = ConsoleColor.Red;
                    WriteLine(ex.Message);
                    ResetColor();
                }

                if (Flag("wait"))
                {
                    ReadKey(true);
                }
                return;
            }

            while (true)
            {
                ForegroundColor = Flag("nsfw") ? ConsoleColor.Magenta : ConsoleColor.Yellow;
                Write("\u211d> "); // real number symbol
                ResetColor();

                var input = ReadLine();
#if DEBUG
                PrintOutput(rant.Do(input, 0, PATTERN_TIMEOUT));
#else
                try
                {
                    PrintOutput(rant.Do(input, 0, PATTERN_TIMEOUT));
                }
                catch (Exception e)
                {
                    ForegroundColor = ConsoleColor.Red;
                    if (e is RantException)
                    {
                        WriteLine(e.Message);
                    }
                    else
                    {
                        WriteLine(e.ToString()); // Print the whole stack trace if it isn't a syntax error
                    }
                    ResetColor();
                }
#endif
            }
        }