Example #1
0
        protected override void EndInit()
        {
            base.EndInit();

            var lines = Message
                        .Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var maxLineLength = lines
                                .Select(x => x.Length)
                                .Max();

            if (maxLineLength > MinWidth)
            {
                Width = maxLineLength + 10;
            }
            else
            {
                Width = MinWidth;
            }

            Height = lines.Length <= 10 ? lines.Length + 7 : Dim.Fill(8);

            var textView = new TextView()
            {
                Text     = Message,
                ReadOnly = true,
                X        = 1,
                Y        = 1,
                Width    = Dim.Fill(2),
                Height   = Dim.Height(this) - 6
            };

            Add(textView);
        }
Example #2
0
        public void PosCombine_Will_Throws()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = Dim.Width(t) - 2,
                Height = Dim.Height(t) - 2
            };
            var f  = new FrameView("f");
            var v1 = new View("v1")
            {
                Width  = Dim.Width(w) - 2,
                Height = Dim.Height(w) - 2
            };
            var v2 = new View("v2")
            {
                Width  = Dim.Width(v1) - 2,
                Height = Dim.Height(v1) - 2
            };

            f.Add(v1);              // v2 not added
            w.Add(f);
            t.Add(w);

            f.Width  = Dim.Width(t) - Dim.Width(v2);
            f.Height = Dim.Height(t) - Dim.Height(v2);

            Assert.Throws <InvalidOperationException> (() => Application.Run());
            Application.Shutdown();
        }
Example #3
0
        protected override void EndInit()
        {
            Height         = Dim.Fill(5);
            plugins.Width  = Dim.Fill(1);
            plugins.Height = Dim.Height(this) - 6;

            Add(plugins);

            base.EndInit();

            Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1), _ => UpdateProgress());
            Task.Run(async() => await LoadPlugins());
        }
        /// <summary>
        /// Perform initialization.
        /// </summary>
        public JobButtonsFrame Initialize()
        {
            Height = Dim.Height(startJobsButton.Initialize()) + 2;
            Width  = Dim.Fill();

            Add(startJobsButton);

            stopJobsButton
            .Initialize()
            .WithHorizontalOffset(Pos.Right(startJobsButton) + 1)
            .To(Add);

            return(this);
        }
Example #5
0
        public void DimCombine_Do_Not_Throws()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = Dim.Width(t) - 2,
                Height = Dim.Height(t) - 2
            };
            var f  = new FrameView("f");
            var v1 = new View("v1")
            {
                Width  = Dim.Width(w) - 2,
                Height = Dim.Height(w) - 2
            };
            var v2 = new View("v2")
            {
                Width  = Dim.Width(v1) - 2,
                Height = Dim.Height(v1) - 2
            };

            f.Add(v1, v2);
            w.Add(f);
            t.Add(w);

            f.Width  = Dim.Width(t) - Dim.Width(v2);
            f.Height = Dim.Height(t) - Dim.Height(v2);

            t.Ready += () => {
                Assert.Equal(80, t.Frame.Width);
                Assert.Equal(25, t.Frame.Height);
                Assert.Equal(78, w.Frame.Width);
                Assert.Equal(23, w.Frame.Height);
                Assert.Equal(6, f.Frame.Width);
                Assert.Equal(6, f.Frame.Height);
                Assert.Equal(76, v1.Frame.Width);
                Assert.Equal(21, v1.Frame.Height);
                Assert.Equal(74, v2.Frame.Width);
                Assert.Equal(19, v2.Frame.Height);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #6
0
        public void Height_SetsValue()
        {
            var dim = Dim.Height(null);

            Assert.Throws <NullReferenceException> (() => dim.ToString());

            var testVal = Rect.Empty;

            testVal = Rect.Empty;
            dim     = Dim.Height(new View(testVal));
            Assert.Equal($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString());

            testVal = new Rect(1, 2, 3, 4);
            dim     = Dim.Height(new View(testVal));
            Assert.Equal($"DimView(side=Height, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString());
        }
Example #7
0
        protected override void EndInit()
        {
            Height = Dim.Fill(5);

            AddButton("Commit To", OnNewBranchClicked);

            textView.X      = 1;
            textView.Y      = 1;
            textView.Width  = Dim.Fill(1);
            textView.Height = Dim.Height(this) - 7;
            textView.Text   = message ?? string.Empty;

            Add(textView);

            // Set IsInitialized and raise Initialized at the end.
            base.EndInit();
        }
        /// <summary>
        /// Perform initialization.
        /// </summary>
        public GeneralButtonFrame Initialize()
        {
            Height = Dim.Height(calculateButton.Initialize())
                     + Dim.Height(exportButton.Initialize())
                     + Dim.Height(applyButton.Initialize())
                     + 4;

            Width = Dim.Fill();

            Add(calculateButton);

            exportButton
            .WithVerticalOffset(Pos.Bottom(calculateButton) + 1)
            .To(Add);

            applyButton
            .WithVerticalOffset(Pos.Bottom(exportButton) + 1)
            .To(Add);

            return(this);
        }
Example #9
0
        public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height()
        {
            // Testing with the Button because it properly handles the Dim class.

            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = 100,
                Height = 100
            };

            var f1 = new FrameView("f1")
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Percent(50),
                Height = 5
            };

            var f2 = new FrameView("f2")
            {
                X      = Pos.Right(f1),
                Y      = 0,
                Width  = Dim.Fill(),
                Height = 5
            };

            var v1 = new Button("v1")
            {
                X      = Pos.X(f1) + 2,
                Y      = Pos.Bottom(f1) + 2,
                Width  = Dim.Width(f1) - 2,
                Height = Dim.Fill() - 2
            };

            var v2 = new Button("v2")
            {
                X      = Pos.X(f2) + 2,
                Y      = Pos.Bottom(f2) + 2,
                Width  = Dim.Width(f2) - 2,
                Height = Dim.Fill() - 2
            };

            var v3 = new Button("v3")
            {
                Width  = Dim.Percent(10),
                Height = Dim.Percent(10)
            };

            var v4 = new Button("v4")
            {
                Width  = Dim.Sized(50),
                Height = Dim.Sized(50)
            };

            var v5 = new Button("v5")
            {
                Width  = Dim.Width(v1) - Dim.Width(v3),
                Height = Dim.Height(v1) - Dim.Height(v3)
            };

            var v6 = new Button("v6")
            {
                X      = Pos.X(f2),
                Y      = Pos.Bottom(f2) + 2,
                Width  = Dim.Percent(20, true),
                Height = Dim.Percent(20, true)
            };

            w.Add(f1, f2, v1, v2, v3, v4, v5, v6);
            t.Add(w);

            t.Ready += () => {
                Assert.Equal("Dim.Absolute(100)", w.Width.ToString());
                Assert.Equal("Dim.Absolute(100)", w.Height.ToString());
                Assert.Equal(100, w.Frame.Width);
                Assert.Equal(100, w.Frame.Height);

                Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f1.Height.ToString());
                Assert.Equal(49, f1.Frame.Width);                  // 50-1=49
                Assert.Equal(5, f1.Frame.Height);

                Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f2.Height.ToString());
                Assert.Equal(49, f2.Frame.Width);                  // 50-1=49
                Assert.Equal(5, f2.Frame.Height);

                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v1.Width.ToString());
                Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v1.Height.ToString());
                Assert.Equal(47, v1.Frame.Width);                  // 49-2=47
                Assert.Equal(89, v1.Frame.Height);                 // 98-5-2-2=89


                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=49,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v2.Width.ToString());
                Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v2.Height.ToString());
                Assert.Equal(47, v2.Frame.Width);                  // 49-2=47
                Assert.Equal(89, v2.Frame.Height);                 // 98-5-2-2=89

                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString());
                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Height.ToString());
                Assert.Equal(9, v3.Frame.Width);                  // 98*10%=9
                Assert.Equal(9, v3.Frame.Height);                 // 98*10%=9

                Assert.Equal("Dim.Absolute(50)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(50)", v4.Height.ToString());
                Assert.Equal(50, v4.Frame.Width);
                Assert.Equal(50, v4.Frame.Height);

                Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Width.ToString());
                Assert.Equal("Dim.Combine(DimView(side=Height, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Height, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Height.ToString());
                Assert.Equal(38, v5.Frame.Width);                  // 47-9=38
                Assert.Equal(80, v5.Frame.Height);                 // 89-9=80

                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString());
                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Height.ToString());
                Assert.Equal(9, v6.Frame.Width);                  // 47*20%=9
                Assert.Equal(18, v6.Frame.Height);                // 89*20%=18


                w.Width  = 200;
                w.Height = 200;
                t.LayoutSubviews();

                Assert.Equal("Dim.Absolute(200)", w.Width.ToString());
                Assert.Equal("Dim.Absolute(200)", w.Height.ToString());
                Assert.Equal(200, w.Frame.Width);
                Assert.Equal(200, w.Frame.Height);

                f1.Text = "Frame1";
                Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f1.Height.ToString());
                Assert.Equal(99, f1.Frame.Width);                  // 100-1=99
                Assert.Equal(5, f1.Frame.Height);

                f2.Text = "Frame2";
                Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f2.Height.ToString());
                Assert.Equal(99, f2.Frame.Width);                  // 100-1=99
                Assert.Equal(5, f2.Frame.Height);

                v1.Text = "Button1";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v1.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v1.Height.ToString());
                Assert.Equal(97, v1.Frame.Width);                  // 99-2=97
                Assert.Equal(1, v1.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v2.Text = "Button2";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=99,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v2.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v2.Height.ToString());
                Assert.Equal(97, v2.Frame.Width);                  // 99-2=97
                Assert.Equal(1, v2.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v3.Text = "Button3";
                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v3.Height.ToString());
                Assert.Equal(19, v3.Frame.Width);                  // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
                Assert.Equal(1, v3.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v4.Text     = "Button4";
                v4.AutoSize = false;
                Assert.Equal("Dim.Absolute(50)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v4.Height.ToString());
                v4.AutoSize = true;
                Assert.Equal("Dim.Absolute(11)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v4.Height.ToString());
                Assert.Equal(11, v4.Frame.Width);                  // 11 is the text length and because is Dim.DimAbsolute
                Assert.Equal(1, v4.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v5.Text = "Button5";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=97,Height=1}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=19,Height=1})))", v5.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v5.Height.ToString());
                Assert.Equal(78, v5.Frame.Width);                  // 97-19=78
                Assert.Equal(1, v5.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v6.Text = "Button6";
                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v6.Height.ToString());
                Assert.Equal(19, v6.Frame.Width);                  // 99*20%=19
                Assert.Equal(1, v6.Frame.Height);                  // 1 because is Dim.DimAbsolute
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #10
0
        public override void Setup()
        {
            var frame = new FrameView("Dialog Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the Dialog will size to 80% of container.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(titleEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit)
                           + Dim.Height(numButtonsEdit) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 5,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            //var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
            var showDialogButton = new Button("Show Dialog")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showDialogButton.Clicked += () => {
                try {
                    int width      = int.Parse(widthEdit.Text.ToString());
                    int height     = int.Parse(heightEdit.Text.ToString());
                    int numButtons = int.Parse(numButtonsEdit.Text.ToString());

                    var buttons = new List <Button> ();
                    var clicked = -1;
                    for (int i = 0; i < numButtons; i++)
                    {
                        var buttonId = i;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                    }

                    // This tests dynamically adding buttons; ensuring the dialog resizes if needed and
                    // the buttons are laid out correctly
                    var dialog = new Dialog(titleEdit.Text, width, height,
                                            buttons.ToArray());
                    var add = new Button("Add a button")
                    {
                        X = Pos.Center(),
                        Y = Pos.Center()
                    };
                    add.Clicked += () => {
                        var buttonId = buttons.Count;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                        dialog.AddButton(button);
                        button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1;
                    };
                    dialog.Add(add);

                    Application.Run(dialog);
                    buttonPressedLabel.Text = $"{clicked}";
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showDialogButton);

            Win.Add(buttonPressedLabel);
        }
Example #11
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the MessageBox will be sized automatically.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextView()
            {
                Text        = "Message",
                X           = Pos.Right(label) + 1,
                Y           = Pos.Top(label),
                Width       = Dim.Fill(),
                Height      = 5,
                ColorScheme = Colors.Dialog,
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(messageEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                           + Dim.Height(numButtonsEdit) + Dim.Height(styleRadioGroup) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 2,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label("")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 4,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
                Clicked   = () => {
                    try {
                        int width      = int.Parse(widthEdit.Text.ToString());
                        int height     = int.Parse(heightEdit.Text.ToString());
                        int numButtons = int.Parse(numButtonsEdit.Text.ToString());

                        var btns = new List <ustring> ();
                        for (int i = 0; i < numButtons; i++)
                        {
                            btns.Add(btnText[i % 10]);
                        }
                        if (styleRadioGroup.SelectedItem == 0)
                        {
                            buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                        else
                        {
                            buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                    } catch (FormatException) {
                        buttonPressedLabel.Text = "Invalid Options";
                    }
                },
            };

            Win.Add(showMessageBoxButton);

            Win.Add(buttonPressedLabel);
        }
Example #12
0
            internal ProgressDemo(ustring title) : base(title)
            {
                ColorScheme = Colors.Dialog;

                LeftFrame = new FrameView("Settings")
                {
                    X      = 0,
                    Y      = 0,
                    Height = Dim.Percent(100),
                    Width  = Dim.Percent(25)
                };
                var lbl = new Label(1, 1, "Tick every (ms):");

                LeftFrame.Add(lbl);
                Speed = new TextField("")
                {
                    X     = Pos.X(lbl),
                    Y     = Pos.Bottom(lbl),
                    Width = 7,
                };
                LeftFrame.Add(Speed);

                Add(LeftFrame);

                var startButton = new Button("Start Timer")
                {
                    X = Pos.Right(LeftFrame) + 1,
                    Y = 0,
                };

                startButton.Clicked += () => Start();
                var pulseButton = new Button("Pulse")
                {
                    X = Pos.Right(startButton) + 2,
                    Y = Pos.Y(startButton),
                };

                pulseButton.Clicked += () => Pulse();
                var stopbutton = new Button("Stop Timer")
                {
                    X = Pos.Right(pulseButton) + 2,
                    Y = Pos.Top(pulseButton),
                };

                stopbutton.Clicked += () => Stop();

                Add(startButton);
                Add(pulseButton);
                Add(stopbutton);

                ActivityProgressBar = new ProgressBar()
                {
                    X           = Pos.Right(LeftFrame) + 1,
                    Y           = Pos.Bottom(startButton) + 1,
                    Width       = Dim.Fill(),
                    Height      = 1,
                    Fraction    = 0.25F,
                    ColorScheme = Colors.Error
                };
                Add(ActivityProgressBar);

                PulseProgressBar = new ProgressBar()
                {
                    X           = Pos.Right(LeftFrame) + 1,
                    Y           = Pos.Bottom(ActivityProgressBar) + 1,
                    Width       = Dim.Fill(),
                    Height      = 1,
                    ColorScheme = Colors.Error
                };
                Add(PulseProgressBar);

                _startedLabel = new Label("Stopped")
                {
                    X = Pos.Right(LeftFrame) + 1,
                    Y = Pos.Bottom(PulseProgressBar),
                };
                Add(_startedLabel);


                // Set height to height of controls + spacing + frame
                Height = 2 + _verticalSpace + Dim.Height(startButton) + _verticalSpace + Dim.Height(ActivityProgressBar) + _verticalSpace + Dim.Height(PulseProgressBar) + _verticalSpace;
            }
Example #13
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the MessageBox will be sized automatically.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextView()
            {
                Text        = "Message",
                X           = Pos.Right(label) + 1,
                Y           = Pos.Top(label),
                Width       = Dim.Fill(),
                Height      = 5,
                ColorScheme = Colors.Dialog,
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(messageEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Default Button:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var defaultButtonEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(defaultButtonEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            var border = new Border()
            {
                Effect3D    = true,
                BorderStyle = BorderStyle.Single
            };
            var ckbEffect3D = new CheckBox("Effect3D", true)
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label) + 2
            };

            ckbEffect3D.Toggled += (e) => {
                border.Effect3D = !e;
            };
            frame.Add(ckbEffect3D);

            void Top_Loaded()
            {
                frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                               + Dim.Height(numButtonsEdit) + Dim.Height(defaultButtonEdit) + Dim.Height(styleRadioGroup) + 2 + Dim.Height(ckbEffect3D);
                Top.Loaded -= Top_Loaded;
            }

            Top.Loaded += Top_Loaded;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 5,
                Width         = 25,
                Height        = 1,
                ColorScheme   = Colors.Error,
                TextAlignment = Terminal.Gui.TextAlignment.Centered
            };

            //var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showMessageBoxButton.Clicked += () => {
                try {
                    int width         = int.Parse(widthEdit.Text.ToString());
                    int height        = int.Parse(heightEdit.Text.ToString());
                    int numButtons    = int.Parse(numButtonsEdit.Text.ToString());
                    int defaultButton = int.Parse(defaultButtonEdit.Text.ToString());

                    var btns = new List <ustring> ();
                    for (int i = 0; i < numButtons; i++)
                    {
                        //btns.Add(btnText[i % 10]);
                        btns.Add(NumberToWords.Convert(i));
                    }
                    if (styleRadioGroup.SelectedItem == 0)
                    {
                        buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                    else
                    {
                        buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showMessageBoxButton);

            Win.Add(buttonPressedLabel);
        }
Example #14
0
        public override void Setup()
        {
            var s         = "TAB to jump between text fields.";
            var textField = new TextField(s)
            {
                X     = 1,
                Y     = 1,
                Width = Dim.Percent(50),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(textField);

            var labelMirroringTextField = new Label(textField.Text)
            {
                X     = Pos.Right(textField) + 1,
                Y     = Pos.Top(textField),
                Width = Dim.Fill(1)
            };

            Win.Add(labelMirroringTextField);

            textField.TextChanged += (prev) => {
                labelMirroringTextField.Text = textField.Text;
            };

            var textView = new TextView()
            {
                X           = 1,
                Y           = 3,
                Width       = Dim.Percent(50),
                Height      = Dim.Percent(30),
                ColorScheme = Colors.Dialog
            };

            textView.Text = s;
            Win.Add(textView);

            var labelMirroringTextView = new Label(textView.Text)
            {
                X      = Pos.Right(textView) + 1,
                Y      = Pos.Top(textView),
                Width  = Dim.Fill(1),
                Height = Dim.Height(textView),
            };

            Win.Add(labelMirroringTextView);

            textView.TextChanged += () => {
                labelMirroringTextView.Text = textView.Text;
            };

            var btnMultiline = new Button("Toggle Multiline")
            {
                X = Pos.Right(textView) + 1,
                Y = Pos.Top(textView) + 1
            };

            btnMultiline.Clicked += () => textView.Multiline = !textView.Multiline;
            Win.Add(btnMultiline);

            // BUGBUG: 531 - TAB doesn't go to next control from HexView
            var hexView = new HexView(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                X      = 1,
                Y      = Pos.Bottom(textView) + 1,
                Width  = Dim.Fill(1),
                Height = Dim.Percent(30),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(hexView);

            var dateField = new DateField(System.DateTime.Now)
            {
                X     = 1,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };

            Win.Add(dateField);

            var labelMirroringDateField = new Label(dateField.Text)
            {
                X      = Pos.Right(dateField) + 1,
                Y      = Pos.Top(dateField),
                Width  = Dim.Width(dateField),
                Height = Dim.Height(dateField),
            };

            Win.Add(labelMirroringDateField);

            dateField.TextChanged += (prev) => {
                labelMirroringDateField.Text = dateField.Text;
            };

            _timeField = new TimeField(DateTime.Now.TimeOfDay)
            {
                X     = Pos.Right(labelMirroringDateField) + 5,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };
            Win.Add(_timeField);

            _labelMirroringTimeField = new Label(_timeField.Text)
            {
                X      = Pos.Right(_timeField) + 1,
                Y      = Pos.Top(_timeField),
                Width  = Dim.Width(_timeField),
                Height = Dim.Height(_timeField),
            };
            Win.Add(_labelMirroringTimeField);

            _timeField.TimeChanged += TimeChanged;

            // MaskedTextProvider
            var netProviderLabel = new Label(".Net MaskedTextProvider [ 999 000 LLL >LLL| AAA aaa ]")
            {
                X = Pos.Left(dateField),
                Y = Pos.Bottom(dateField) + 1
            };

            Win.Add(netProviderLabel);

            var netProvider = new NetMaskedTextProvider("999 000 LLL > LLL | AAA aaa");

            var netProviderField = new TextValidateField(netProvider)
            {
                X = Pos.Right(netProviderLabel) + 1,
                Y = Pos.Y(netProviderLabel)
            };

            Win.Add(netProviderField);

            // TextRegexProvider
            var regexProvider = new Label("Gui.cs TextRegexProvider [ ^([0-9]?[0-9]?[0-9]|1000)$ ]")
            {
                X = Pos.Left(netProviderLabel),
                Y = Pos.Bottom(netProviderLabel) + 1
            };

            Win.Add(regexProvider);

            var provider2 = new TextRegexProvider("^([0-9]?[0-9]?[0-9]|1000)$")
            {
                ValidateOnInput = false
            };
            var regexProviderField = new TextValidateField(provider2)
            {
                X             = Pos.Right(regexProvider) + 1,
                Y             = Pos.Y(regexProvider),
                Width         = 30,
                TextAlignment = TextAlignment.Centered
            };

            Win.Add(regexProviderField);
        }
Example #15
0
        public override void Setup()
        {
            var s         = "TAB to jump between text fields.";
            var textField = new TextField(s)
            {
                X     = 1,
                Y     = 1,
                Width = Dim.Percent(50),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(textField);

            var labelMirroringTextField = new Label(textField.Text)
            {
                X     = Pos.Right(textField) + 1,
                Y     = Pos.Top(textField),
                Width = Dim.Fill(1)
            };

            Win.Add(labelMirroringTextField);

            textField.TextChanged += (prev) => {
                labelMirroringTextField.Text = textField.Text;
            };

            var textView = new TextView()
            {
                X           = 1,
                Y           = 3,
                Width       = Dim.Percent(50),
                Height      = Dim.Percent(30),
                ColorScheme = Colors.Dialog
            };

            textView.Text = s;
            Win.Add(textView);

            var labelMirroringTextView = new Label(textView.Text)
            {
                X      = Pos.Right(textView) + 1,
                Y      = Pos.Top(textView),
                Width  = Dim.Fill(1),
                Height = Dim.Height(textView),
            };

            Win.Add(labelMirroringTextView);

            textView.TextChanged += () => {
                labelMirroringTextView.Text = textView.Text;
            };

            // BUGBUG: 531 - TAB doesn't go to next control from HexView
            var hexView = new HexView(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                X      = 1,
                Y      = Pos.Bottom(textView) + 1,
                Width  = Dim.Fill(1),
                Height = Dim.Percent(30),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(hexView);

            var dateField = new DateField(System.DateTime.Now)
            {
                X     = 1,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };

            Win.Add(dateField);

            var labelMirroringDateField = new Label(dateField.Text)
            {
                X      = Pos.Right(dateField) + 1,
                Y      = Pos.Top(dateField),
                Width  = Dim.Width(dateField),
                Height = Dim.Height(dateField),
            };

            Win.Add(labelMirroringDateField);

            dateField.TextChanged += (prev) => {
                labelMirroringDateField.Text = dateField.Text;
            };

            _timeField = new TimeField(DateTime.Now.TimeOfDay)
            {
                X     = Pos.Right(labelMirroringDateField) + 5,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };
            Win.Add(_timeField);

            _labelMirroringTimeField = new Label(_timeField.Text)
            {
                X      = Pos.Right(_timeField) + 1,
                Y      = Pos.Top(_timeField),
                Width  = Dim.Width(_timeField),
                Height = Dim.Height(_timeField),
            };
            Win.Add(_labelMirroringTimeField);

            _timeField.TimeChanged += TimeChanged;
        }
Example #16
0
        public ReplApp()
            : base($"{nameof(CSharpScriptRunner)} REPL, {BuildInfo.ReleaseTag}, EXPERIMENTAL")
        {
            ColorScheme = new()
            {
                Normal    = new(Color.White, Color.Black),
                Focus     = new(Color.White, Color.Black),
                Disabled  = new(Color.White, Color.Black),
                HotNormal = new(Color.White, Color.Black),
                HotFocus  = new(Color.White, Color.Black)
            };

            Label labelInput = new() { X = 0, Y = Pos.AnchorEnd() - 1, Height = 1, Text = "> " };

            _ctrlInput = new() { X = Pos.Right(labelInput), Y = Pos.AnchorEnd() - 1, Width = Dim.Fill(), Height = 1 };

            _ctrlHistory = new() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() - Dim.Height(_ctrlInput), ReadOnly = true };

            _ctrlIntellisense             = new() { X = 0, Y = 0, Height = MaxIntellisenseHeight, Visible = false };
            _ctrlIntellisense.ColorScheme = new()
            {
                Normal    = new(Color.White, Color.DarkGray),
                HotNormal = new(Color.White, Color.Blue),
                Focus     = new(Color.White, Color.DarkGray),
                HotFocus  = new(Color.White, Color.Blue)
            };

            Add(_ctrlHistory, _ctrlIntellisense, labelInput, _ctrlInput);

            _ctrlInput.SetFocus();

            _ctrlHistory.KeyPress  += OnKeyPressHistory;
            _ctrlInput.KeyPress    += OnKeyPressInput;
            _ctrlInput.KeyUp       += OnKeyUpInput;
            _ctrlInput.TextChanged += OnTextChangedInput;

            _script = CSharpScript.Create(string.Empty);

            // https://www.strathweb.com/2018/12/using-roslyn-c-completion-service-programmatically/
            var host = MefHostServices.DefaultHost;

            _ws        = new AdhocWorkspace(host);
            _projectId = ProjectId.CreateNewId();
            var projectInfo = ProjectInfo.Create(_projectId, VersionStamp.Default, "Script", "Script", LanguageNames.CSharp, isSubmission: true)
                              .WithCompilationOptions(_script.GetCompilation().Options)
                              .WithMetadataReferences(_script.GetCompilation().References);

            var project = _ws.AddProject(projectInfo);
            var docInfo = DocumentInfo.Create(DocumentId.CreateNewId(_projectId), "Script", sourceCodeKind: SourceCodeKind.Script);

            _doc = _ws.AddDocument(docInfo);
        }

        void OnKeyPressHistory(View.KeyEventEventArgs args)
        {
            if (args.KeyEvent.Key == Key.Tab)
            {
                args.Handled = true;
                _ctrlInput.SetFocus();
            }
        }

        void OnKeyPressInput(View.KeyEventEventArgs args)
        {
            if (_ctrlIntellisense.Visible)
            {
                switch (args.KeyEvent.Key)
                {
                default: return;

                case Key.CursorDown:
                    if (_ctrlIntellisense.SelectedItem == _ctrlIntellisense.Source.Count - 1)
                    {
                        _ctrlIntellisense.MoveHome();
                    }
                    else
                    {
                        _ctrlIntellisense.MoveDown();
                    }
                    break;

                case Key.CursorUp:
                    if (_ctrlIntellisense.SelectedItem == 0)
                    {
                        _ctrlIntellisense.MoveEnd();
                    }
                    else
                    {
                        _ctrlIntellisense.MoveUp();
                    }
                    break;

                case Key.Tab:
                    var item       = _ctrlIntellisense.Source.ToList()[_ctrlIntellisense.SelectedItem].ToString();
                    var text       = _ctrlInput.Text.ToString();
                    var cursorsPos = text.Length + item.Length;
                    text                      = text.Substring(0, _idxIntellisense) + item;
                    _ctrlInput.Text           = text;
                    _ctrlInput.CursorPosition = cursorsPos;
                    _ctrlIntellisense.Visible = false;
                    break;
                }

                _ctrlIntellisense.SetNeedsDisplay();
                args.Handled = true;
            }
        }

        async void OnKeyUpInput(View.KeyEventEventArgs args)
        {
            if (args.KeyEvent.Key == Key.Enter)
            {
                if (_ctrlInput.Text.IsEmpty || _isProcessing)
                {
                    return;
                }

                _isProcessing = true;
                var code        = _ctrlInput.Text.ToString().TrimEnd();
                var newScript   = _script.ContinueWith(code);
                var diagnostics = newScript.Compile();

                var output = new List <string>();
                output.Add($"> {code}");
                var success = true;
                foreach (var diag in diagnostics)
                {
                    if (diag.Severity == DiagnosticSeverity.Error)
                    {
                        success = false;
                    }
                    var loc = diag.Location.GetLineSpan();
                    output.Add($"{diag.Severity} ({loc.StartLinePosition.Line}, {loc.StartLinePosition.Character}): {diag.GetMessage()}");
                }

                if (success)
                {
                    var result = await newScript.RunAsync();

                    if (result.ReturnValue is string value)
                    {
                        value = SymbolDisplay.FormatLiteral(value, true);
                    }
                    else
                    {
                        value = result.ReturnValue?.ToString();
                    }
                    if (!string.IsNullOrEmpty(value))
                    {
                        output.Add(value);
                    }
                    _script = newScript;
                    if (!code.EndsWith(';'))
                    {
                        code += ';';
                    }
                    _scriptCode += code;
                }

                output.Add(string.Empty);
                _ctrlHistory.Text += string.Join(Environment.NewLine, output);
                _ctrlHistory.MoveEnd();
                _ctrlInput.Text = string.Empty;
                _isProcessing   = false;
            }
            else if (args.KeyEvent.Key == Key.CursorLeft || args.KeyEvent.Key == Key.CursorRight)
            {
                OnTextChangedInput(_ctrlInput.Text);
            }
        }

        async void OnTextChangedInput(NStack.ustring oldText)
        {
            if (_ctrlInput.Text.IsEmpty)
            {
                _ctrlIntellisense.Visible = false;
                return;
            }

            var code       = _scriptCode + _ctrlInput.Text.ToString();
            var doc        = _doc.WithText(SourceText.From(code));
            var service    = CompletionService.GetService(doc);
            var completion = await service.GetCompletionsAsync(doc, Math.Min(_ctrlInput.CursorPosition + _scriptCode.Length, code.Length));

            if (completion == null)
            {
                _ctrlIntellisense.Visible = false;
                return;
            }

            var items = completion.Items;

            if (items != null)
            {
                var filter = code.Substring(0, Math.Min(_ctrlInput.CursorPosition + _scriptCode.Length, code.Length));
                var idx    = filter.LastIndexOfAny(completion.Rules.DefaultCommitCharacters.ToArray());
                if (idx > -1)
                {
                    filter = filter.Substring(idx);
                }
                items            = service.FilterItems(doc, items, filter);
                _idxIntellisense = idx + 1 - _scriptCode.Length;
            }

            if (items.Length == 0)
            {
                _ctrlIntellisense.Visible = false;
            }
            else
            {
                var completionItems = items.Select(x => x.DisplayText).ToList();
                _ctrlIntellisense.SetSource(completionItems);
                _ctrlIntellisense.X = Pos.Left(_ctrlInput) + _idxIntellisense;


                _ctrlIntellisense.Y     = Pos.Top(_ctrlInput) - Math.Min(completionItems.Count, MaxIntellisenseHeight);
                _ctrlIntellisense.Width = _ctrlIntellisense.Maxlength;
                // _ctrlIntellisense.Height = height;
                _ctrlIntellisense.Visible = true;
            }
        }
    }
}
Example #17
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("Width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("50")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("Height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("6")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextField("Message")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                           + Dim.Height(numButtonsEdit) + Dim.Height(styleRadioGroup) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 2,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label("")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 4,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
                Clicked   = () => {
                    try {
                        int width      = int.Parse(widthEdit.Text.ToString());
                        int height     = int.Parse(heightEdit.Text.ToString());
                        int numButtons = int.Parse(numButtonsEdit.Text.ToString());
                        var btns       = new List <string> ();
                        for (int i = 0; i < numButtons; i++)
                        {
                            btns.Add($"Btn {i}");
                        }
                        if (styleRadioGroup.Selected == 0)
                        {
                            buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                        else
                        {
                            buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                    } catch {
                        buttonPressedLabel.Text = "Invalid Options";
                    }
                },
            };

            Win.Add(showMessageBoxButton);
            Win.Add(buttonPressedLabel);
        }