예제 #1
0
        private static TermInfoDesc LoadTermInfoDesc(Settings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.Name))
            {
                return(TermInfoDesc.Load(settings.Name));
            }

            return(TermInfoDesc.Load());
        }
예제 #2
0
        public void Should_Consider_Extended_Caps_Case_Sensitive(string key, bool?expected)
        {
            // Given
            var stream = EmbeddedResourceReader.LoadResourceStream("TermInfo.Tests/Data/linux");

            // When
            var info = TermInfoDesc.Load(stream);

            // Then
            info.Extended.GetBoolean(key).ShouldBe(expected);
        }
예제 #3
0
        public void Should_Read_MaxColors(string terminfo, int expected)
        {
            // Given
            var stream = EmbeddedResourceReader.LoadResourceStream($"TermInfo.Tests/Data/{terminfo}");

            // When
            var info = TermInfoDesc.Load(stream);

            // Then
            info.MaxColors.ShouldBe(expected);
        }
예제 #4
0
        private static void RenderExtendedCapabilitiesTable(TermInfoDesc desc)
        {
            var table = new Table();

            table.Expand();
            table.Title("[green]Extended capabilities[/]");
            table.AddColumns("Name", "Type", "Value");

            foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.Num))
            {
                var value = desc.Extended.GetNum(key);
                if (value != null)
                {
                    table.AddRow(
                        "[yellow]" + key + "[/]",
                        "[grey]num[/]",
                        value.ToString().EscapeMarkup());
                }
            }

            foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.String))
            {
                var value = desc.Extended.GetString(key);
                if (value != null)
                {
                    value = value.Replace("\u001b", "ESC")
                            .Replace("\u000e", "")
                            .Replace("\u000f", "")
                            .Replace("\t", "\\t")
                            .Replace("\r", "\\r")
                            .Replace("\a", "\\a")
                            .Replace("\n", "\\n");
                    table.AddRow(
                        "[yellow]" + key.EscapeMarkup() + "[/]",
                        "[grey]string[/]",
                        value.EscapeMarkup());
                }
            }

            foreach (var key in desc.Extended.GetNames(TermInfoCapsKind.Boolean))
            {
                var value = desc.Extended.GetBoolean(key);
                if (value != null)
                {
                    table.AddRow(
                        "[yellow]" + key.EscapeMarkup() + "[/]",
                        "[grey]boolean[/]",
                        value.ToString().EscapeMarkup());
                }
            }

            AnsiConsole.Render(table);
        }
예제 #5
0
        public void Should_Read_Standard_Format()
        {
            // Given
            var stream = EmbeddedResourceReader.LoadResourceStream($"TermInfo.Tests/Data/windows-ansi");

            // When
            var info = TermInfoDesc.Load(stream);

            // Then
            info.Names.Length.ShouldBe(2);
            info.Names[0].ShouldBe("ansi");
            info.Names[1].ShouldBe("ansi/pc-term compatible with color");
            info.ClearScreen.ShouldBe("");
        }
예제 #6
0
        public void Should_Read_Extended_Capabilities()
        {
            // Given
            var stream = EmbeddedResourceReader.LoadResourceStream("TermInfo.Tests/Data/eterm-256color");

            // When
            var info = TermInfoDesc.Load(stream);

            // Then
            info.Names.Length.ShouldBe(2);
            info.Names[0].ShouldBe("Eterm-256color");
            info.Names[1].ShouldBe("Eterm with xterm 256-colors");
            info.Extended.Count.ShouldBe(26);
            info.Extended.GetBoolean("AX").ShouldBe(true);
            info.Extended.GetBoolean("XT").ShouldBe(true);
            info.Extended.GetString("kUP").ShouldBe("\u001b[a");
        }
예제 #7
0
        public void Should_Read_Extended__Capabilities_Without_String_Values()
        {
            // Given
            var stream = EmbeddedResourceReader.LoadResourceStream("TermInfo.Tests/Data/linux");

            // When
            var info = TermInfoDesc.Load(stream);

            // Then
            info.Names.Length.ShouldBe(2);
            info.Names[0].ShouldBe("linux");
            info.Names[1].ShouldBe("linux console");
            info.Extended.Count.ShouldBe(10);
            info.Extended.GetBoolean("AX").ShouldBe(true);
            info.Extended.GetBoolean("G0").ShouldBe(false);
            info.Extended.GetBoolean("XT").ShouldBe(false);
            info.Extended.GetNum("U8").ShouldBe(1);
        }
예제 #8
0
        private static void RenderCapabilitiesTable(TermInfoDesc desc)
        {
            var table = new Table();

            table.Expand();
            table.Title("[green]Default capabilities[/]");
            table.AddColumns("Name", "Type", "Value");

            foreach (int key in System.Enum.GetValues(typeof(TermInfoCaps.Num)))
            {
                var value = desc.GetNum((TermInfoCaps.Num)key);
                if (value != null)
                {
                    table.AddRow(
                        "[yellow]" + ((TermInfoCaps.Num)key).ToString() + "[/]",
                        "[grey]num[/]",
                        value.ToString().EscapeMarkup());
                }
            }

            foreach (int key in System.Enum.GetValues(typeof(TermInfoCaps.String)))
            {
                var value = desc.GetString((TermInfoCaps.String)key);
                if (value != null)
                {
                    if (key == 38 || key == 39)
                    {
                        if (!Debugger.IsAttached)
                        {
                            //Debugger.Launch();
                        }
                    }

                    value = value.Replace("\u001b", "ESC")
                            .Replace("\u000e", "")
                            .Replace("\u000f", "")
                            .Replace("\t", "\\t")
                            .Replace("\r", "\\r")
                            .Replace("\a", "\\a")
                            .Replace("\n", "\\n");
                    table.AddRow(
                        "[yellow]" + ((TermInfoCaps.String)key).ToString().EscapeMarkup() + "[/]",
                        "[grey]string[/]",
                        value.EscapeMarkup());
                }
            }

            foreach (int key in System.Enum.GetValues(typeof(TermInfoCaps.Boolean)))
            {
                var value = desc.GetBoolean((TermInfoCaps.Boolean)key);
                if (value != null)
                {
                    table.AddRow(
                        "[yellow]" + ((TermInfoCaps.Boolean)key).ToString() + "[/]",
                        "[grey]boolean[/]",
                        value.ToString().EscapeMarkup());
                }
            }

            AnsiConsole.Render(table);
        }