Beispiel #1
0
Datei: Input.cs Projekt: w-k/pp
        public static bool ProcessKey(ConsoleKeyInfo key, CheckList checklist)
        {
            switch (key.Key)
            {
                case ConsoleKey.Escape:
                    checklist.Exit();
                    return false;

                case ConsoleKey.Enter:
                    checklist.Exit();
                    Program.ProcessSelectedItems(checklist.Selected);
                    return false;

                case ConsoleKey.I:
                case ConsoleKey.UpArrow:
                    checklist.MoveUp();
                    return true;

                case ConsoleKey.K:
                case ConsoleKey.DownArrow:
                    checklist.MoveDown();
                    return true;

                case ConsoleKey.J:
                case ConsoleKey.LeftArrow:
                    checklist.MoveLeft();
                    return true;

                case ConsoleKey.L:
                case ConsoleKey.RightArrow:
                    checklist.MoveRight();
                    return true;

                case ConsoleKey.Spacebar:
                    checklist.Toggle();
                    return true;

                default:
                    return true;
            }
        }
Beispiel #2
0
Datei: Program.cs Projekt: w-k/pp
        private static void Main(string[] args)
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            var lineParser = new LineParser(currentDirectory);
            // https://msdn.microsoft.com/en-us/library/System.Console%28v=vs.110%29.aspx
            Console.OutputEncoding = new UnicodeEncoding(!BitConverter.IsLittleEndian, false);
            var options = new HashSet<Option>();
            var inputStream = Console.OpenStandardInput();
            using (var reader = new StreamReader(inputStream))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    Option option;
                    if (lineParser.Parse(line, out option))
                        options.Add(option);
                }
            }

            if (options.Count == 0) return;

            // https://stackoverflow.com/questions/21779818
            FreeConsole();
            AttachConsole(-1);
            checklist = new CheckList(options);
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Handler);
            checklist.InitialRender(Console.WindowHeight - 6);
            while (Input.ProcessKey(Console.ReadKey(true), checklist)) Thread.Sleep(10);
        }