示例#1
0
        private static void ShowEmployeesTable(List <Employes> employees)
        {
            Configuration = Configuration.ValidateConfiguration();

            try
            {
                if (employees is not null)
                {
                    AnsiConsole.Record();
                    var table = new Table();

                    // Add some columns
                    table.AddColumn($"[{Configuration.Color3}]Nombre[/]");
                    table.AddColumn($"[{Configuration.Color3}]Cedula[/]");
                    table.AddColumn($"[{Configuration.Color3}]Año de nacimiento[/]");
                    table.AddColumn($"[{Configuration.Color3}]Ciudad[/]");
                    table.AddColumn($"[{Configuration.Color3}]Celular[/]");
                    table.AddColumn($"[{Configuration.Color3}]Puesto[/]");
                    table.AddColumn($"[{Configuration.Color3}]Edad[/]");
                    table.AddColumn($"[{Configuration.Color3}]Salario[/]");

                    // Itera sobre la lista de empleados y la muestra en la tabla
                    foreach (var(item, index) in employees.Select((x, y) => (x, y)))
                    {
                        if (index % 2 == 0)
                        {
                            table.AddRow($"[{Configuration.Color1}]{item.Name}[/]", $"[{Configuration.Color1}]{item.IdCard}[/]",
                                         $"[{Configuration.Color1}]{item.BirthDate}[/]", $"[{Configuration.Color1}]{item.City}[/]",
                                         $"[{Configuration.Color1}]{item.Phone}[/]",
                                         $"[{Configuration.Color1}]{item.Position}[/]", $"[{Configuration.Color1}]{item.YearsOld}[/]",
                                         $"[{Configuration.Color1}]{item.Salary}[/]");
                        }
                        else
                        {
                            table.AddRow($"[{Configuration.Color2}]{item.Name}[/]", $"[{Configuration.Color2}]{item.IdCard}[/]",
                                         $"[{Configuration.Color2}]{item.BirthDate}[/]", $"[{Configuration.Color2}]{item.City}[/]",
                                         $"[{Configuration.Color2}]{item.Phone}[/]",
                                         $"[{Configuration.Color2}]{item.Position}[/]", $"[{Configuration.Color2}]{item.YearsOld}[/]",
                                         $"[{Configuration.Color2}]{item.Salary}[/]");
                        }
                    }

                    // Renderiza la tabla con la información
                    AnsiConsole.Render(table);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("No hay empleados en el sistema");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            catch (System.NullReferenceException)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No existe empleado");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
        public void UseSpectreAnsiConsole_should_register_IAnsiConsole_as_resolveable_parameter()
        {
            AnsiConsole.Record();
            var result = new AppRunner <App>()
                         .UseSpectreAnsiConsole()
                         .RunInMem("Ansi lala");

            result.ExitCode.Should().Be(0);
            AnsiConsole.ExportText().Should().Be("lala");
            result.Console.AllText().Should().BeEmpty();
        }
        public void Console_should_forward_to_AnsiConsole()
        {
            AnsiConsole.Record();

            var result = new AppRunner <App>()
                         .UseSpectreAnsiConsole()
                         .RunInMem("Console lala");

            result.ExitCode.Should().Be(0);
            result.Console.AllText().Should().Be(@"lala");
            AnsiConsole.ExportText().Should().BeEmpty("lala");
        }
示例#4
0
        public override bool Execute(LamarServicesInput input)
        {
            if (input.FileFlag.IsNotEmpty())
            {
                AnsiConsole.Record();
            }

            AnsiConsole.Render(new FigletText("Lamar")
            {
                Color = Color.Blue
            });

            using (var host = input.BuildHost())
            {
                var container = (IContainer)host.Services;


                // TODO -- check for the interactive mode here.


                var configurations = input.Query(container)
                                     .GroupBy(x => x.ServiceType.ResolveServiceType().Assembly)
                                     .OrderBy(x => x.Key.FullName)
                                     .ToArray();

                var display = input.BuildPlansFlag ? WhatDoIHaveDisplay.BuildPlan : WhatDoIHaveDisplay.Summary;

                WriteSummaries(input, configurations, display, container);



                if (input.FileFlag.IsNotEmpty())
                {
                    var fullPath = input.FileFlag.ToFullPath();
                    Console.WriteLine("Writing the query results to " + fullPath);

                    var extension = Path.GetExtension(fullPath);
                    if (extension.EndsWith("htm", StringComparison.OrdinalIgnoreCase) ||
                        extension.EndsWith("html", StringComparison.OrdinalIgnoreCase))
                    {
                        File.WriteAllText(fullPath, AnsiConsole.ExportHtml());
                    }
                    else
                    {
                        File.WriteAllText(fullPath, AnsiConsole.ExportText());
                    }
                }
            }

            return(true);
        }
示例#5
0
        static async Task Main(string[] args)
        {
            string name, surname;
            int    birthday;

            List <Person> personsList = new List <Person> ();

            do
            {
                Console.WriteLine("1- Para agregar persona\n2- Para mostrar información");
                var option = int.Parse(Console.ReadLine());
                switch (option)
                {
                case 1:

                    name     = AnsiConsole.Ask <string> ("Cual es tu [blue]nombre[/]?");
                    surname  = AnsiConsole.Ask <string> ("Cual es tu  [blue]apellido[/]?");
                    birthday = AnsiConsole.Ask <int> ("Cual es tu [green]año de nacimiento[/]?");
                    Person persona = new Person(name, surname, birthday);
                    personsList.Add(persona);
                    AnsiConsole.Status()
                    .Start("Guardando...", ctx => {
                        Thread.Sleep(1000);
                        // Update the status and spinner
                        ctx.Status("Finalizado");
                        ctx.Spinner(Spinner.Known.Star);
                        ctx.SpinnerStyle(Style.Parse("green"));
                        Thread.Sleep(1000);
                    });
                    Console.Clear();
                    break;

                case 2:

                    var saveTable = AnsiConsole.Confirm("Guardar tabla?");
                    AnsiConsole.Record();
                    Table table = new Table();

                    table.AddColumn("Nombre");
                    table.AddColumn("Apellido");
                    table.AddColumn("Edad");
                    table.AddColumn("Pais");
                    table.AddColumn("Ciudad");
                    table.AddColumn("Idioma");
                    table.AddColumn("Cordenadas");

                    foreach (var item in personsList)
                    {
                        table.AddRow(item.Name, item.Surname, item.Birthday.ToString(), item.Country, item.City, item.Language, item.Cordinates);
                    }

                    var title = new TableTitle("Empleado", Style.WithDecoration(Decoration.Bold));
                    table.Title = title;

                    table.Border(TableBorder.Rounded);
                    table.BorderColor <Table> (Color.Blue);
                    AnsiConsole.Render(table);

                    if (saveTable)
                    {
                        string html = AnsiConsole.ExportHtml();
                        Directory.CreateDirectory("../Employes");
                        File.WriteAllText("../Employes/index.html", html);

                        Console.ForegroundColor = Color.Green;
                        Console.WriteLine("Guardado Exitosamente");
                        Console.ForegroundColor = Color.White;
                    }

                    break;

                default:
                    break;
                }
            } while (true);
        }