Beispiel #1
0
 public static async Task AddOffset(this PaginatorController pie, object item, int offset)
 => await pie.AddOffset(await pie.GetCurrentFocusPage(), item, offset);
Beispiel #2
0
        static async Task MainAsync(string[] args)
        {
            var evenItems = Enumerable.Range(0, 197).Select(x => (x * 2).ToString());
            var oddItems  = Enumerable.Range(0, 27).Select(x => (x * 2 + 1).ToString());
            var pdb       = new PagedDataSetBuilder <string, string>()
                            .WithName("Even page")
                            .WithStringPageGenerator()
                            .WithDefaultCapabilities()
                            .WithDataSource(evenItems)
                            .WithPageSize(10)
                            .WithItemFilter(new StringItemFilter());
            var evenPd = await pdb.BuildPagedDataSource();

            var oddPd = await pdb.WithDataSource(oddItems)
                        .WithName("Odd page")
                        .BuildPagedDataSource();

            PaginatorController controller = new PaginatorController();

            controller.Add(evenPd);
            controller.Add(oddPd);
            await controller.SetFocusPage(evenPd);

            var ic = StringComparison.OrdinalIgnoreCase;

            while (true)
            {
                Console.Clear();
                foreach (var item in await controller.GetPageContents())
                {
                    Console.WriteLine("Header".Center(50, '-'));
                    Console.WriteLine(await item.GetHeader());
                    Console.WriteLine("Content".Center(50, '-'));
                    Console.WriteLine(await item.GetContent());
                    Console.WriteLine("-".Multiply(50));
                }

                var cmd = Console.ReadKey(true);
                if (cmd.Key == ConsoleKey.Q && cmd.Modifiers == ConsoleModifiers.Shift)
                {
                    var pds = await controller.GetCurrentFocusPage();

                    await controller.MovePagedDataSetOffset(pds, -1);
                }
                else if (cmd.Key == ConsoleKey.E && cmd.Modifiers == ConsoleModifiers.Shift)
                {
                    var pds = await controller.GetCurrentFocusPage();

                    await controller.MovePagedDataSetOffset(pds, 1);
                }
                else if (cmd.Key == ConsoleKey.Q)
                {
                    await controller.SetFocusPageAtOffset(-1);
                }
                else if (cmd.Key == ConsoleKey.E)
                {
                    await controller.SetFocusPageAtOffset(1);
                }
                else if (cmd.Key == ConsoleKey.D)
                {
                    await controller.MoveCurrentPageIndex(1);
                }
                else if (cmd.Key == ConsoleKey.A)
                {
                    await controller.MoveCurrentPageIndex(-1);
                }
                else if (cmd.Key == ConsoleKey.W && cmd.Modifiers == ConsoleModifiers.Shift)
                {
                    var sel = await controller.GetSelectedItem();

                    await controller.MoveOffset(sel, -1);

                    await controller.SetSelectedItem(sel);
                }
                else if (cmd.Key == ConsoleKey.S && cmd.Modifiers == ConsoleModifiers.Shift)
                {
                    var sel = await controller.GetSelectedItem();

                    await controller.MoveOffset(sel, 1);

                    await controller.SetSelectedItem(sel);
                }
                else if (cmd.Key == ConsoleKey.W)
                {
                    await controller.MoveCaretBy(-1, true);
                }
                else if (cmd.Key == ConsoleKey.S)
                {
                    await controller.MoveCaretBy(1, true);
                }
                else if (cmd.Key == ConsoleKey.Enter && cmd.Modifiers == ConsoleModifiers.Shift)
                {
                    await controller.RemoveAtOffset(0);
                }
                else if (cmd.Key == ConsoleKey.Enter)
                {
                    await controller.AddOffset(DateTime.Now.ToString(), 0);
                }
                else if (cmd.Key == ConsoleKey.Spacebar)
                {
                    await controller.SetSelectedItem("20");
                }


                else if (cmd.KeyChar == '/')
                {
                    Console.WriteLine("Line Command: ");
                    string command = Console.ReadLine();
                    if (command.StartsWith("f", ic))
                    {
                        var sp = command.Split(' ');
                        if (sp.Length > 1)
                        {
                            await(await controller.GetCurrentFocusPage()).SetFilter(sp.Skip(1).Aggregate((l, r) => $"{l} {r}"));
                        }
                        else
                        {
                            await(await controller.GetCurrentFocusPage()).SetFilter(string.Empty);
                        }
                    }
                }
            }
        }