Esempio n. 1
0
        public static Parent LaunchExample()
        {
            var data = new ObservableCollection <Example>
            {
                new Example {
                    Name = "Test", Number = 7, Color = ConsoleColor.Cyan
                },
                new Example {
                    Name = "Woosh", Number = 18, Color = ConsoleColor.Red
                },
                new Example {
                    Name = "Yeet", Number = 68, Color = ConsoleColor.Gray
                }
            };

            var par = new Parent(new BorderStrategy())
            {
                ClearAreaBeforePrint = true
            };

            var table = new TableComponent <Example> {
                Data = data
            };

            table.ActionOnListElement += (o, args) => { data.Remove(args.Item); };
            table.AddColumn(new IndicatorColumnType <Example>());
            table.AddColumn(new BasicColumnType <Example>("Name", e => e.Name));
            table.AddColumn(new ColorColumnType());
            par.AddComponent(table, BorderStrategy.Center);

            return(par);
        }
Esempio n. 2
0
        public ViuDemo()
        {
            var mainContainer = new Parent {
                ClearAreaBeforePrint = true
            };
            var cons = new ConsoleParent(mainContainer);

            cons.SetTitle("Viu/SCFE Demo");
            var switcher = new SwitcherStrategy(mainContainer);

            mainContainer.Strategy = switcher;


            var menu = new Parent(new LineStrategy {
                Centered = true
            });

            mainContainer.AddComponent(menu);
            menu.AddComponent(new TextComponent("~ SCFE Demo ~")
            {
                Foreground = ConsoleColor.Yellow, HAlign = HorizontalAlignment.Centered
            });
            menu.AddComponent(new Separator());
            switcher.SwitchToComponent(menu, null);

            var table = new TableComponent <ViuDemoType> {
                Data = _demos
            };

            menu.AddComponent(table);
            table.AddColumn(new IndicatorColumnType <ViuDemoType>());
            table.AddColumn(
                new BasicColumnType <ViuDemoType>("Choose a demo to get started. Exit a demo with the Escape key.",
                                                  vdt => vdt.Name));
            table.ActionOnListElement += (sender, args) =>
            {
                switcher.SwitchToComponent(args.Item.Parent, args.Graphics);
                mainContainer.Validate();
                mainContainer.Print(args.Graphics);
            };

            foreach (var vdt in _demos)
            {
                mainContainer.AddComponent(vdt.Parent);
            }

            mainContainer.ActionMap.Put(StandardActionNames.CancelAction, (o, args) =>
            {
                mainContainer.SetFocused(false, args.Graphics);
                switcher.SwitchToComponent(menu, args.Graphics);
                mainContainer.Validate();
                mainContainer.SetFocused(true, args.Graphics);
                mainContainer.Print(args.Graphics);
            });

            cons.Validate();
            cons.FocusFirst();
            cons.Print();
        }
Esempio n. 3
0
        public FileOptionsPanel(ImmutableList <File> f, AbstractHierarchicalDictionary <KeyStroke, string> inputMap)
        {
            TextComponent fileName;

            Strategy = new BorderStrategy();

            var topParent = new Parent(new LineStrategy {
                Orientation = Orientation.Vertical
            });

            AddComponent(topParent, BorderStrategy.Top);
            fileName = new TextComponent(f == null ? "Current directory options" :
                                         f.Count == 1 ? f[0].GetFileName() : f.Count + " files...")
            {
                HAlign = HorizontalAlignment.Centered
            };
            topParent.AddComponent(fileName);
            topParent.AddComponent(new Separator());

            var table = new TableComponent <FileOption>
            {
                Data = new ObservableCollection <FileOption>(f == null
                    ? FileOption.OptionsForCurrentDirectory
                                                             .Where(opt => opt.CanActionBeApplied?.Invoke(null, null) ?? true).ToList()
                    : FileOption.Options
                                                             .Where(opt => opt.CanActionBeApplied(f, null)).ToList()),
                ShowHeader = false
            };

            table.AddColumn(new IndicatorColumnType <FileOption>());
            table.AddColumn(new BasicColumnType <FileOption>("", option => option.Title)
            {
                GrowPriority = 1
            });
            table.AddColumn(
                new BasicColumnType <FileOption>("", option => SearchForShortcut(option.ActionName, inputMap))
            {
                HAlign = HorizontalAlignment.Right
            });
            table.ActionOnListElement += (sender, args) => { RemovalCallback(args.Item.ActionName, args.Graphics); };
            AddComponent(table, BorderStrategy.Center);

            var btn = new Button("Back");

            btn.ActionOnComponent += (sender, args) => RemovalCallback?.Invoke(null, args.Graphics);
            AddComponent(btn, BorderStrategy.Bottom);

            ActionMap.Put(StandardActionNames.CancelAction, (o, args) => RemovalCallback?.Invoke(null, args.Graphics));
        }
    private void GUI_InitTableComponent()
    {
        int idColumnWidth     = 20;
        int countColumnWidth  = 60;
        int nameColumnWidth   = 70;
        int simpleColumnWidth = 100;

        tableComponent.Clear();
        tableComponent.AddColumn("ID", idColumnWidth);
        tableComponent.AddColumn("Count", countColumnWidth);
        tableComponent.AddColumn("Name", nameColumnWidth);
        tableComponent.AddColumn("Simple", simpleColumnWidth);
        tableComponent.AddColumn("Count2", countColumnWidth);
        tableComponent.OnGUI();
    }
Esempio n. 5
0
        public static Parent TestTable()
        {
            var par = new Parent(new BorderStrategy())
            {
                ClearAreaBeforePrint = false
            };

            var data = new ObservableCollection <string[]>
            {
                new[] { "Hello!", "This is a table", "A nice one" },
                new[] { "hey", "bonjour", "buon giorno" },
                new[] { "who", "are", "you?" }
            };

            var table = new TableComponent <string[]>
            {
                Data = data
            };

            //table.AddColumn(new BasicColumnInformationType<string[]>("Test.", s => s[0]));
            //table.AddColumn(new BasicColumnInformationType<string[]>("Zboui zboui zboui.", s => s[1]));
            //table.AddColumn(new BasicColumnInformationType<string[]>("Test...", s => s[2]));
            table.AddColumn(new IndicatorColumnType <string[]>());
            table.AddColumn(new MultistateColumnType <string[]>(new[] { "This is a screenshot", "Screenshot" },
                                                                x => new[] { x[0], x[0].Split(' ')[0], x[0].ToCharArray()[0] + "" }
                                                                )
            {
                Priority = 1, GrowPriority = 10
            });
            table.AddColumn(new MultistateColumnType <string[]>(
                                new[] { "A fairly long column name", "A shorter one", "A" },
                                x => new[]
                                { x[1], x[1].Split(' ')[0], x[1].ToCharArray()[0] + "" }
                                )
            {
                Priority = 2, GrowPriority = 20
            });
            table.AddColumn(new MultistateColumnType <string[]>(new[] { "I am running out of ideas", "Ideas", "I" },
                                                                x => new[] { x[2], x[2].Split(' ')[0], x[2].ToCharArray()[0] + "" }
                                                                )
            {
                Priority = 2, GrowPriority = 10
            });
            par.AddComponent(table, BorderStrategy.Center);

            return(par);
        }
    private void GUI_InitTableComponent()
    {
        int idColumnWidth     = 20;
        int sceneColumnWidth  = 50;
        int countColumnWidth  = 60;
        int parentColumnWidth = 150;
        int nameColumnWidth   = 70;
        int nodeColumnWidth   = 120;

        tableComponent.Clear();
        tableComponent.AddColumn("ID", idColumnWidth);
        tableComponent.AddColumn("Scene", sceneColumnWidth);
        tableComponent.AddColumn("Count", countColumnWidth);
        tableComponent.AddColumn("Parent", parentColumnWidth);
        tableComponent.AddColumn("Name", nameColumnWidth);
        tableComponent.AddColumn("Node", nodeColumnWidth);
        tableComponent.OnGUI();
    }
Esempio n. 7
0
        public ScfeApp(File startingFile, string[] columnsToAdd)
        {
            CurrentDir = startingFile ?? new File(Directory.GetCurrentDirectory());
            _filter    = new AndFilter <File>(
                new BoolFilter <File>(f => ShowHiddenFiles || !f.IsHidden()),
                new BranchingFilter <File>(() => _filterOnBoxInput && TextBoxHandler == null,
                                           new StringFilter <File>(file => file.GetFileName().ToLowerInvariant(),
                                                                   () => TextBox.Text.ToLowerInvariant()),
                                           new TrueFilter <File>()));
            FileSorting = FileSorters[0];

            _noSearchFilter = new BoolFilter <File>(f => ShowHiddenFiles || !f.IsHidden());

            Tasks = new TaskPool <string>((task, tresult) =>
            {
                _cons?.DoGraphicsLater(g =>
                {
                    if (tresult.Message != null)
                    {
                        ShowHelpMessage(tresult.Message, g, tresult.Success ? ConsoleColor.Green : ConsoleColor.Red);
                    }
                });
            });

            _main = new Parent(new BorderStrategy());
            AddMainBindings();

            var p = new Parent(new LineStrategy());

            _main.AddComponent(p, BorderStrategy.Top);

            var p2 = new Parent(new BorderStrategy());

            p.AddComponent(p2);

            p2.AddComponent(new TextComponent("dir: ")
            {
                Foreground = ConsoleColor.DarkGray
            }, BorderStrategy.Left);

            _filePath = new TextComponent(CurrentDir.Path)
            {
                CutOverflowFrom = HorizontalAlignment.Centered, ClearBlankSpaceOnReprint = true
            };
            p2.AddComponent(_filePath, BorderStrategy.Center);

            _elementsCount = new TextComponent("[...]")
            {
                ClearBlankSpaceOnReprint = true
            };
            p2.AddComponent(_elementsCount, BorderStrategy.Right);

            p.AddComponent(new Separator {
                Foreground = ConsoleColor.DarkGray
            });

            p = new Parent(new LineStrategy());
            _main.AddComponent(p, BorderStrategy.Bottom);

            p.AddComponent(new Separator {
                Foreground = ConsoleColor.DarkGray
            });

            p2 = new Parent(new BorderStrategy());
            p.AddComponent(p2);

            var p3 = new Parent(new FlowStrategy(1));

            p2.AddComponent(p3, BorderStrategy.Left);

            _mode = new TextComponent("xxx");
            p3.AddComponent(_mode);

            p3.AddComponent(new Separator {
                Orientation = Orientation.Vertical, Foreground = ConsoleColor.DarkGray
            });
            p3.AddComponent(new TextComponent("")); // To have an extra separator at the end

            _help = new TextComponent("Welcome to SCFE!")
            {
                ClearBlankSpaceOnReprint = true
            };
            p2.AddComponent(_help, BorderStrategy.Center);

            p2 = new Parent(new BorderStrategy());
            p.AddComponent(p2);
            p2.AddComponent(new TextComponent("~> "), BorderStrategy.Left);

            TextBox = new TextField
            {
                PlaceholderText =
                    "Press E or M (in NAV mode, with Ctrl in SEA mode) to switch modes. Ctrl+Enter or (Ctrl+)Shift+M for COM mode.",
                ShowLine = false
            };
            TextBox.OnTextChanged += (sender, args) =>
            {
                if (_filterOnBoxInput && TextBoxHandler == null)
                {
                    SwitchToFolder(CurrentDir, args.Graphics);
                }
            };
            TextBox.ActionOnComponent += (sender, args) =>
            {
                if (TextBoxHandler != null)
                {
                    TextBoxHandler(sender, args);
                }
                else if (_filterOnBoxInput)
                {
                    if (_table.Data.Count == 1 && _table.Data[0] != null)
                    {
                        HandlerOpenFileInTable(_table.Data[0], args.Graphics);
                    }

                    TextBox.SetFocused(false, args.Graphics);
                    _table.SetFocused(true, args.Graphics);
                }
            };
            TextBox.ActionMap.Put(StandardActionNames.CancelAction, (o, args) =>
            {
                args.Graphics.SetCursorVisible(false);
                if (TextBoxHandler != null)
                {
                    CancelTextBoxHandler(args.Graphics);
                }
                else if (_filterOnBoxInput)
                {
                    ResetTextBox(args.Graphics);
                    SwitchToFolder(CurrentDir, args.Graphics);
                    ResetFocusableStates(args.Graphics);
                }
            });
            p2.AddComponent(TextBox, BorderStrategy.Center);

            _wrapper = new Parent {
                ClearAreaBeforePrint = true
            };
            _wrapper.Strategy = new SwitcherStrategy(_wrapper);
            _main.AddComponent(_wrapper, BorderStrategy.Center);

            _extensions.Add(new BaseExtension(this));
            _extensions.Add(new ComExtension(this));

            var gitExt = new GitExtension(this);

            ColorScheme = gitExt;
            _extensions.Add(gitExt);

            _extensions.Add(new FileWatchExtension(this));

            _table = new ScfeTable(this);
            InstallOnActionMap(_table.ActionMap);
            _table.ActionOnComponent += (o, args) => HandlerOpenFileInTable(_table.FocusedElement, args.Graphics);

            _table.AddColumn(new IndicatorColumnType <File>());

            var columnsAvailable = _extensions.SelectMany(e => e.GetColumns()).ToList();

            foreach (var colName in columnsToAdd)
            {
                var col = columnsAvailable.FirstOrDefault(c => c.GetTitle(_table, int.MaxValue) == colName);
                if (col != null)
                {
                    _table.AddColumn(col);
                }
            }

            _wrapper.AddComponent(_table, 0);
            ((SwitcherStrategy)_wrapper.Strategy).SwitchToComponentWithHint(0, null);

            _tableInputMap  = new SwappableAddinHierDic <KeyStroke, string>(_table.InputMap);
            _table.InputMap = _tableInputMap;

            InstallExtensionsOnFileOptionsPanel();

            SwitchToFolder(CurrentDir);

            ChangeModeTo(NavigationMode.NavMode, null);
        }