예제 #1
0
 private async Task Log(LogMessage arg)
 {
     if (_config.LogDiscord)
     {
         await AtomicConsole.WriteLine($"Log: {arg.ToString()}");
     }
 }
예제 #2
0
        private async Task Disconnected(Exception arg)
        {
            await AtomicConsole.WriteLine("Disconnected from Discord; shutting down.");

            _scriptExecutor.Stop();
            _signal.Release();
        }
예제 #3
0
        static async Task Main(string[] args)
        {
            var random = new Random();
            var atom   = new AtomicConsole();

            var tasks = Enumerable.Range(0, 20)
                        .Select(i => RunAsync(i, random, atom));

            await Task.WhenAll(tasks);

            Console.WriteLine("Finished!");
        }
예제 #4
0
        private async Task Ready()
        {
            // Connected to Discord, let's initialize!
            _scriptInterface = new ScriptInterface();
            _scriptExecutor  = new ScriptExecutor(_config, _client, _scriptInterface);
            _eventDispatcher = new EventDispatcher(_client, _scriptExecutor);
            _scriptManager   = new ScriptManager(_config, _scriptExecutor, _eventDispatcher);
            _commandManager  = new CommandManager(_client, _scriptManager, _scriptInterface);
            await _commandManager.InitAsync();

            await AtomicConsole.WriteLine("ScriptBot Ready.");
        }
예제 #5
0
        private static async Task RunAsync(int index, Random random, AtomicConsole atom)
        {
            var delay = random.Next() % 1000;
            var cmd   = random.Next() % 10;

            await Task.Delay(delay);

            if (cmd <= 5)
            {
                await atom.WriteLineAsync($"Write from {index}");
            }
            else
            {
                await atom.Run(() =>
                {
                    Console.Write("> ");
                    Console.ReadLine();
                });
            }
        }
예제 #6
0
 public async Task Print() => await AtomicConsole.WriteLine($"test_print: {_text}");
예제 #7
0
        /// <inheritdoc />
        public void Run(IConsole console)
        {
            console.Clear();
            var exitGuid = new Guid(@"a7725515-7f82-4c18-9c36-343003bdf20d");

            var menuItems = new ConsoleMenuItem[]
            {
                new ConsoleMenuItem
                {
                    Enabled = true,
                    Caption = "menu item number one",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = true,
                    Caption = "menu item number two",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = false,
                    Caption = "menu item number three",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = true,
                    Caption = "menu item number four with very long description",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = false,
                    Caption = "menu item number five",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = true,
                    Caption = "menu item number six",
                    Code    = Guid.NewGuid()
                },
                new ConsoleMenuItem
                {
                    Enabled = true,
                    Caption = "Exit menu DEMO",
                    Code    = exitGuid
                }
            };

            var menuStyling = new MenuStyles
            {
                ActiveItem   = new ConsoleFontColor(Color.Red, Color.Black),
                DisabledItem = new ConsoleFontColor(Color.Gray, Color.Black),
                NormalItem   = new ConsoleFontColor(Color.WhiteSmoke, Color.Black),
                SelectedItem = new ConsoleFontColor(Color.Black, Color.LightGray),
                Alignment    = TextAlign.Center
            };

            var aConsole = new AtomicConsole(console);

            int menuStartY       = 6;
            int menuStartX       = 5;
            int menuContentWidth = 25;

            var frameColors    = new ConsoleFontColor(Color.Yellow, Color.Black);
            var boxInnerColors = new ConsoleFontColor(Color.WhiteSmoke, Color.Black);
            var frameStyle     = new FrameStyle(frameColors, boxInnerColors, @"┌─┐││└─┘", ' ');

            var ops = new ConsoleOperations(aConsole);

            ops.WriteTextBox(new Rectangle(menuStartX - 1, menuStartY - 1, menuContentWidth + 2, menuItems.Length + 2), "", frameStyle);

            var menu = new ConsoleMenu(aConsole, new Rectangle(menuStartX, menuStartY, menuContentWidth, 0), menuItems, menuStyling);

            menu.RenderAll();

            ConsoleMenuItem result = null;

            while (result == null || result.Code != exitGuid)
            {
                result = menu.Focus(resetActiveItem: true);

                aConsole.CleanLineSync(0, Color.Black);
                aConsole.RunAtomicOperations(ac =>
                {
                    aConsole.SetCursorPosition(0, 0);
                    aConsole.PrintColorfullText(
                        new KeyValuePair <ConsoleFontColor, string>(new ConsoleFontColor(Color.BlanchedAlmond, Color.Black), @"Selected menu: "),
                        new KeyValuePair <ConsoleFontColor, string>(new ConsoleFontColor(Color.Gold, Color.Black), result?.Caption ?? "#NULL#")
                        );
                });
                Thread.Sleep(1000);
            }

            aConsole.SetCursorPosition(0, menuStartY + menuItems.Length + 1);
            aConsole.ShowCursor();

            aConsole.WaitForNextPage();
        }