Giter Site home page Giter Site logo

athari / csconsoleformat Goto Github PK

View Code? Open in Web Editor NEW
363.0 17.0 32.0 707 KB

.NET C# library for advanced formatting of console output [Apache]

License: Other

C# 99.04% Batchfile 0.66% Smalltalk 0.30%
dotnet dotnet-standard dotnet-framework c-sharp library xaml console terminal shell formatting

csconsoleformat's Introduction

CsConsoleFormat: advanced formatting of console output for .NET

PM> Install-Package Alba.CsConsoleFormat

GitHub license GitHub license GitHub license Badges
AppVeyor build master AppVeyor tests master
GitHub release version GitHub release date GitHub commits since release GitHub open issues GitHub closed issues GitHub pull requests
NuGet release version NuGet downloads MyGet pre-release version MyGet downloads
FOSSA license scan CII best practices Libraries.io Dependencies kandi X-Ray

CsConsoleFormat is a library for formatting text in console based on documents resembling a mix of WPF and HTML: tables, lists, paragraphs, colors, word wrapping, lines etc. Like this:

<Document>
    <Span Color="Red">Hello</Span>
    <Br/>
    <Span Color="Yellow">world!</Span>
</Document>

or like this:

new Document(
    new Span("Hello") { Color = ConsoleColor.Red },
    "\n",
    new Span("world!") { Color = ConsoleColor.Yellow }
);

or even like this:

Colors.WriteLine("Hello".Red(), "\n", "world!".Yellow());

Why?

.NET Framework includes only very basic console formatting capabilities. If you need to output a few strings, it's fine. If you want to output a table, you have to calculate column widths manually, often hardcode them. If you want to color output, you have to intersperse writing strings with setting and restoring colors. If you want to wrap words properly or combine all of the above...

The code quickly becomes an unreadable mess. It's just not fun! In GUI, we have MV*, bindings and all sorts of cool stuff. Writing console applications feels like returning to the Stone Age.

CsConsoleFormat to the rescue!

Imagine you have the usual Order, OrderItem and Customer classes. Let's create a document which prints the order. There're two major syntaxes, you can use either.

XAML (like WPF):

<Document xmlns="urn:alba:cs-console-format"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Span Background="Yellow" Text="Order #"/>
    <Span Text="{Get OrderId}"/>
    <Br/>
    <Span Background="Yellow" Text="Customer: "/>
    <Span Text="{Get Customer.Name}"/>

    <Grid Color="Gray">
        <Grid.Columns>
            <Column Width="Auto"/>
            <Column Width="*"/>
            <Column Width="Auto"/>
        </Grid.Columns>
        <Cell Stroke="Single Double" Color="White">Id</Cell>
        <Cell Stroke="Single Double" Color="White">Name</Cell>
        <Cell Stroke="Single Double" Color="White">Count</Cell>
        <Repeater Items="{Get OrderItems}">
            <Cell>
                <Span Text="{Get Id}"/>
            </Cell>
            <Cell>
                <Span Text="{Get Name}"/>
            </Cell>
            <Cell Align="Right">
                <Span Text="{Get Count}"/>
            </Cell>
        </Repeater>
    </Grid>
</Document>
// Assuming Order.xaml is stored as an Embedded Resource in the Views folder.
Document doc = ConsoleRenderer.ReadDocumentFromResource(GetType(), "Views.Order.xaml", Order);
ConsoleRenderer.RenderDocument(doc);

C# (like LINQ to XML):

using static System.ConsoleColor;

var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

var doc = new Document(
    new Span("Order #") { Color = Yellow }, Order.Id, "\n",
    new Span("Customer: ") { Color = Yellow }, Order.Customer.Name,
    new Grid {
        Color = Gray,
        Columns = { GridLength.Auto, GridLength.Star(1), GridLength.Auto },
        Children = {
            new Cell("Id") { Stroke = headerThickness },
            new Cell("Name") { Stroke = headerThickness },
            new Cell("Count") { Stroke = headerThickness },
            Order.OrderItems.Select(item => new[] {
                new Cell(item.Id),
                new Cell(item.Name),
                new Cell(item.Count) { Align = Align.Right },
            })
        }
    }
);

ConsoleRenderer.RenderDocument(doc);

C# (like npm/colors):

using Alba.CsConsoleFormat.Fluent;

Colors.WriteLine(
    "Order #".Yellow(), Order.Id, "\n",
    "Customer: ".Yellow(), Order.Customer.Name,
    // the rest is the same
);

Features

  • HTML-like elements: paragraphs, spans, tables, lists, borders, separators.
  • Layouts: grid, stacking, docking, wrapping, absolute.
  • Text formatting: foreground and background colors, character wrapping, word wrapping.
  • Unicode formatting: hyphens, soft hyphens, no-break hyphens, spaces, no-break spaces, zero-width spaces.
  • Multiple syntaxes (see examples above):
    • Like WPF: XAML with one-time bindings, resources, converters, attached properties, loading documents from assembly resources.
    • Like LINQ to XML: C# with object initializers, setting attached properties via extension methods or indexers, adding children elements by collapsing enumerables and converting objects and strings to elements.
    • Like npm/colors: Limited to writing colored strings, but very concise. Can be combined with the general syntax above.
  • Drawing: geometric primitives (lines, rectangles) using box-drawing characters, color transformations (dark, light), text, images.
  • Internationalization: cultures are respected on every level and can be customized per-element.
  • Export to many formats: ANSI text, unformatted text, HTML; RTF, XPF, WPF FixedDocument, WPF FlowDocument.
  • JetBrains ReSharper annotations: CanBeNull, NotNull, ValueProvider, Pure etc.
  • WPF document control, document converter.

Getting started

  1. Install NuGet package Alba.CsConsoleFormat using Package Manager:

     PM> Install-Package Alba.CsConsoleFormat
    

    or .NET CLI:

     > dotnet add package Alba.CsConsoleFormat
    
  2. Add using Alba.CsConsoleFormat; to your .cs file.

  3. If you're going to use ASCII graphics on Windows, set Console.OutputEncoding = Encoding.UTF8;.

  4. If you want to use XAML:

    1. Add XAML file to your project. Set its build action to "Embedded Resource".
    2. Load XAML using ConsoleRenderer.ReadDocumentFromResource.
  5. If you want to use pure C#:

    1. Build a document in code starting with Document element as a root.
  6. Call ConsoleRenderer.RenderDocument on the generated document.

Choosing syntax

XAML (like WPF) forces clear separation of views and models which is a good thing. However, it isn't strongly typed, so it's easy to get runtime errors if not careful. Syntax-wise it's a combination of XML verbosity (<Grid><Grid.Columns><Column/></Grid.Columns></Grid>) and conciseness of short enums (Color="White") and converters (Stroke="Single Double").

XAML library in Mono is currently very buggy. If you want to build a cross-platform application, using XAML may be problematic. However, if you need to support only Windows and are experienced in WPF, XAML should feel natural.

XAML is only partially supported by Visual Studio + ReSharper: syntax highlighting and code completion work, but library-specific markup extensions are't understood by code completion, so incorrect errors may be displayed.

C# (like LINQ to XML) allows performing all sorts of transformations with objects right in the code, thanks to LINQ and collapsing of enumerables when adding children elements. When using C# 6, which supports using static, accessing some of enumerations can be shortened. The only place with loose typing is adding of children using collection initializer of Element.Children (or constructor of Element).

Building documents in code is fully supported by IDE, but code completion may cause lags if documents are built with huge single statements.

Framework Compatibility

The library contains the following packages:

  • Alba.CsConsoleFormat: main library with XAML and bindings support.
  • Alba.CsConsoleFormat-NoXaml: main library without XAML and bindings support (also without Repeater element).
  • Alba.CsConsoleFormat.Presentation: WPF-dependent features, including WPF control, export to RTF etc.
  • Alba.CsConsoleFormat.ColorfulConsole: support for Coloful.Console's FIGlet fonts.
  • Alba.CsConsoleFormat.ColorfulConsole-NoXaml: Alba.CsConsoleFormat.ColorfulConsole which depends on Alba.CsConsoleFormat-NoXaml.

The library supports the following targets:

  • .NET Standard 2.0 (Windows Vista; Core 2.0; Mono 5.4)
    • Alba.CsConsoleFormat (depends in Portable.Xaml)
    • Alba.CsConsoleFormat-NoXaml
    • Alba.CsConsoleFormat.ColorfulConsole
    • Alba.CsConsoleFormat.ColorfulConsole-NoXaml
  • .NET Standard 1.3 (Windows Vista; Core 1.0; Mono 4.6)
    • Alba.CsConsoleFormat (depends in Portable.Xaml)
    • Alba.CsConsoleFormat-NoXaml
    • Alba.CsConsoleFormat.ColorfulConsole
    • Alba.CsConsoleFormat.ColorfulConsole-NoXaml
  • .NET Framework 4.0 (Windows Vista)
    • Alba.CsConsoleFormat (depends in System.Xaml)
    • Alba.CsConsoleFormat-NoXaml
    • Alba.CsConsoleFormat.Presentation
    • Alba.CsConsoleFormat.ColorfulConsole
    • Alba.CsConsoleFormat.ColorfulConsole-NoXaml
  • .NET Framework 3.5 (Windows XP)
    • Alba.CsConsoleFormat-NoXaml

Notes:

  1. Alba.CsConsoleFormat can be ported to .NET Framework 3.5 if someone actually needs it. It's just not worth the hassle otherwise as it requires changes to Portable.Xaml library.
  2. Alba.CsConsoleFormat-NoXaml can be supported on .NET Standard 1.0, Windows Phone 8.0 and other platforms, but they don't support console. WPF control belongs to the "just for fun" genre, but if somebody actually needs something like this on other platforms, it can be ported.

License

Copyright © 2014–2018 Alexander "Athari" Prokhorov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Some parts of the library are based on ConsoleFramework © Igor Kostomin under MIT license.

Related Projects

  • ConsoleFramework — fully-featured cross-platform console user interface framework. Using ConsoleFramework, you can create interactive user interface with mouse input, but its formatting capabilities are limited.

    CsConsoleFormat includes more formatting features: inline text with support for Unicode, more layouts, more everything, so if you only need to output text, CsConsoleFormat is more appropriate. However, if you want an interactive user interface with windows, menus and buttons, ConsoleFramework is the only library out there which supports it.

  • Colorful.Console — library for coloring text in console and ASCII-art fonts. Supports RGB colors on Windows, falls back to 16 colors on other platforms.

    Colorful.Console offers more coloring features: RGB colors, text highlighting based on regular expressions, gradients. However, it falls flat if anything beyond coloring is required as its output is based on calling Console.WriteLine variations, so it suffers from the same basic problems as the standard System.Console. FIGlet fonts are supported by CsConsoleFormat through Colorful.Console, but there's no integration beyond that.

  • ConsoleTables — simple library for printing tables. (There're several alternatives, but this one is the most popular.)

    Almost all features of ConsoleTables are trivial to implement with CsConsoleFormat. ConsoleTables is limited to single-line cells and a few fixed formatting styles.

Links

TODO

csconsoleformat's People

Contributors

athari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csconsoleformat's Issues

Investigate adding file templates

File templates for XAML files could be useful as it isn't easy to add them and put all namespaces.

If it requires adding adding VS extensions, that's probably too much hassle both on development and consumption side, but R# seems to have lightweight code templates, maybe at least this can be used. That new common project system may have extensibility points too.

Render using default foreground and background colors

In the version 1.0 if foreground or background colors are not specified, the white and black colors are used for them. It looks unnatural if other colors are used in the terminal by default, like in Mas OS X Terminal.

It would be nice if it is possible to render the user interface using default colors.

As a workaround, it is possible to set Color to Console.ForegroundColor and Background to Console.BackgroundColor but it works only on Windows. On Linux and Mas OS these properties return (ConsoleColor)(-1) and it looks like there is no easy and universal way to determine the actual colors.

Optimize number of API calls in ConsoleRenderTarget

Calling Console.Write for every line seems to be unoptimal compared to writing one big block of text. Probably caused by too much interop. See #21 (comment).

Optimize number of API calls in ConsoleRenderTarget for specific cases, like lack of color formating in the document or disabled formatting like discussed in #22.

Optimizations from #11 should make that unnecessary for modern platforms, but generic fallback console writing should be fast too.

5 min example (similar to ConsoleTable library's example)

I needed to get a nice table fast but CsConsoleFormat appeared too complicated. It would help a lot if there was a simple fully working and copy-pastable example to start with, right on the front page. Something like this:

using ConsoleTables;
					
public class Color
{
	public string Name { get; set; }
	public string Code { get; set; }
}

public class Program
{
	public static void Main()
	{
		var colors = new[] {
			new Color { Name = "Blue", Code = "#0000FF" },
			new Color { Name = "Yellow", Code = "#FFFF00" },
			new Color { Name = "Cyan", Code = "#00FFFF" }};
		
		var table = new ConsoleTable(
			"Name",
			"Code");
		
		foreach (var color in colors)
		{
			table.AddRow(color.Name, color.Code);
		}

		table.Write();
	}
}

And the result of the program, of course:

 -------------------- 
 | Name   | Code    |
 -------------------- 
 | Blue   | #0000FF |
 -------------------- 
 | Yellow | #FFFF00 |
 -------------------- 
 | Cyan   | #00FFFF |
 -------------------- 

 Count: 3

Support current operating system's ANSI codes in AnsiRenderTarget

The current choice of escape codes used by AnsiRenderTarget is pretty much random. Try detecting current system's/terminal's actual escape codes. Investigate what .NET Core does to detect them for switching console colors.

Windows 10 supports escape codes too now. Needs to be enabled with ENABLE_VIRTUAL_TERMINAL_PROCESSING flag in SetConsoleMode. Find out what codes are supported. All related issues are discussed in symfony/symfony#19520.

Also give meaningful names to the commented out color maps and allow to customize them.

Grid Element Does Not Support No Border

I have been trying to render a grid with no border and it seems to resort to using LineThickness.Single instead.

I have tried the following:

  • Stroke = LineThickness.None;
  • Stroke = new LineThickness(0);

It will render with a border every time.

ConsoleTest in new Windows Terminal

Hello,
I was able to execute the ConsoleTest application to see how it performed with the new Windows Terminal. It appears you are setting the terminal width prior to rendering the text which is not being honored by the new Windows Terminal. Because of that the text rendering does not line up properly and word wraps. Do you expect this library to work well in the new Windows Terminal? Can any tweaks be done to make it compatible? Classic command console seems to be fine.

Also, do you expect the library to perform well in a dotnet core / linux environment?

My goal is to add this library to a console application I am building which will run on dotnet core and non-windows machines. I have a lot of tables and formatting in my output and would very much like to use a library like this.

Thank you.

RenderDocumentToText adds an extra newline

If I do this ConsoleRenderer.RenderDocument(doc); I get the output as expected.
But if I do this:
StringWriter sw = new StringWriter();
vs ConsoleRenderer.RenderDocumentAsText(doc, sw);
and then Console.WriteLine(sw.StringBuilder().toString());
There is an extra "\r\n" between each line.

Using a Negative Margin on a BlockElement Breaks Height Calculation

I've tried using a negative top margin on a block element like this:

var div = new Div { Margin = new Thickness(0, -1, 0, 0) };

I've added some children to this element that should span 6 lines in height. Using the -1 top margin causes the element to only have a height of 1 line and the other lines are missing.

It will only render with the correct height if I remove the negative margin. It also seems to work okay if I use a bottom margin like this, but this causes an extra line to render after my div which is not what I want:

var div = new Div { Margin = new Thickness(0, -1, 0, 1) };

Can CsConsoleFormat write the table with pagination?

I need to generate a table to be used in a fixed lines per page scenario. If the table should continue onto multiple pages, I want to repeat the header at the top of those pages:

| header1                    | header2   | header 3 |
--------------------------------------------------
| one                        | two       | three |
| 1                          | 2         | 3     |
| this line should be longer | yes it is | oh    |

...more rows
--------------------------------------------------

--page 2---
| header1                    | header2   | header 3 |
--------------------------------------------------

Can CsConsoleFormat do this?

Also, I don't want any delimiters, like "|" and "----------------------". Can the table be configured to output no column and row delimiters?

Support CsConsoleFormat-specific DSL

AmmyUI supports custom XAML syntax. It's implemented using Nitra. Look into implementing DSL better than XAML, specific to CsConsoleFormat.

If Nitra and Nemerle turn out to be unreliable and not future-proof, consider good old ANTLR and maybe manually implemented syntax highlighter.

Spam /s Help users on StackOverflow

There're probably quite a few questions on StackOverflow about formatting in console, tables, colors and word wrap. Find them and help people find the one and only correct solution.

And don't copy-paste answers like the last time. Don't be that stupid, you dirty rep whore. You have 25K rep, it's time to pretend you have brains.

Add Roslyn Analyzers for LINQ DSL

  1. Check arguments of all constructors and methods that accept object and params object[] as an argument and check values only at runtime. Check block-inline hierarchy, check elements that can't have children etc.

  2. Suggesting to always set Color and BackgroundColor on Document may also be a good idea.

  3. Avoid use of LineWidth.Heavy (limited font support). Check that combinations on line widths in LineChar are valid (heavy and double can't be combined).

  4. Double assignment of the same attached property (the last assignment wins).

If Roslyn can access XAML, check element hierarchy there too.

Markdown support?

I'm new to programming, dunno if there are good tools for this out there but most things I'm finding has all this HTML stuff that I don't want to learn or fuss with.

Instead of .Yellow(), can I just use markdown instead?

Extension methods to color strings like in npm.colors for JS

Colors module extends string prototype with color properties which generate escape sequences, which creates conscise API for colored console output.

Something like this can be done with CsConsoleFormat. A dirty hacky version can be found in my answer Using colors in console, how to store in a simplified notation, but it doesn't support background colors. Supporting both foreground and background colors would require extension methods for both strings and spans.

Looks like it's a very common use case, so implement this API properly.

Rendered output is always empty on the Rider IDE unit test

I want to render the grid on test output context, but there is nothing.
I wrote a sample with xunit.

public class DocumentDraftServiceTests
{
    private readonly ITestOutputHelper _output;

    public DocumentDraftServiceTests(ITestOutputHelper output)
    {
        _output = output;
    }
    
    [Fact]
    public async Task Test()
    {
        _output.WriteLine("--------- Console Info -----------");
        _output.WriteLine($"WindowWidth={Console.WindowWidth}");
        _output.WriteLine($"WindowHeight={Console.WindowHeight}");
        _output.WriteLine($"WindowLeft={Console.WindowLeft}");
        _output.WriteLine($"WindowTop={Console.WindowTop}");
        
        var document = new Alba.CsConsoleFormat.Document(
            new Grid
            {
                Columns = { GridLength.Auto },
                Children =
                {
                    new Cell("ID"),
                    new Cell("1")
                }
            }
        );
        
        // I want to render the grid on test output context, but there is nothing.
        _output.WriteLine("--------- Grid -----------");
        _output.WriteLine(ConsoleRenderer.RenderDocumentToText(document, new TextRenderTarget()));
        _output.WriteLine("--------------------------");
    }
}

Output:

--------- Console Info -----------
WindowWidth=0
WindowHeight=0
WindowLeft=0
WindowTop=0
--------- Grid -----------

--------------------------

But it's well on terminal.

dotnet test --logger:"console;verbosity=detailed"

--------- Console Info -----------
 WindowWidth=217
 WindowHeight=16
 WindowLeft=0
 WindowTop=0
 --------- Grid -----------
 ╔══╗                                                                                                                                                                                                                     
 ║ID║                                                                                                                                                                                                                     
 ╟──╢                                                                                                                                                                                                                     
 ║1 ║                                                                                                                                                                                                                     
 ╚══╝                                                                                                                                                                                                                     
 
 --------------------------

I want to show rendered text on the Rider IDE unit test.
Are these bugs?

Integrate with popular NuGet packages for parsing command line

Integrate with popular command-line parsers to allow:

  1. Zero-effort improvement to formatting of help texts. Should match the original tool's formatting closely, but improve upon it.

  2. Easy customization options like colors, offsets, headers, padding etc.

  3. Deep customization by providing source data in a ready-to-use form if the original tool doesn't. Code for generating documents from the points above should serve as a sample in this case.

Likely candidates:

Evaluate command line packages:

Improve table styling by imitating Word's table styles

Customizing borders of tables is a mess. Removing table outer borders requires customizing every cell.

Look into supporting table styles like in Microsoft Word, at least for borders, but possibly for colors and alignment.

Example Word style:

<w:style w:type="table" w:styleId="InfoTable">
  <w:pPr>
    <w:spacing w:after="0pt" w:line="12pt" w:lineRule="auto"/>
  </w:pPr>
  <w:rPr>
    <w:rFonts w:ascii="Arial Narrow" w:hAnsi="Arial Narrow"/>
    <w:sz w:val="19"/>
  </w:rPr>
  <w:tblPr>
    <w:tblBorders>
      <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
      <w:start w:val="single" w:sz="4" w:space="0" w:color="auto"/>
      <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
      <w:end w:val="single" w:sz="4" w:space="0" w:color="auto"/>
      <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
    </w:tblBorders>
  </w:tblPr>
  <w:tcPr>
    <w:vAlign w:val="center"/>
  </w:tcPr>
  <w:tblStylePr w:type="firstCol">
    <w:pPr>
      <w:jc w:val="start"/>
    </w:pPr>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:tblPr/>
    <w:tcPr>
      <w:tcBorders>
        <w:top w:val="nil"/>
        <w:start w:val="nil"/>
        <w:bottom w:val="nil"/>
        <w:end w:val="single" w:sz="4" w:space="0" w:color="auto"/>
        <w:insideH w:val="nil"/>
        <w:insideV w:val="nil"/>
        <w:tl2br w:val="nil"/>
        <w:tr2bl w:val="nil"/>
      </w:tcBorders>
      <w:vAlign w:val="top"/>
    </w:tcPr>
  </w:tblStylePr>
</w:style>

Example Word style usage:

<w:tblPr>
  <w:tblStyle w:val="InfoTable"/>
  <w:tblLook w:firstRow="0" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="1" w:noVBand="1"/>
</w:tblPr>

TextAlign property doesn't work on single-line blocks

TextAlign=Right seems to be ignored if text is shorter than width available for containing block.

<Div TextAlign="Right">
    <Span Text="Hello world!">
</Div>

The workaround is to add Align=Right, but it shouldn't be this way. Block should always occupy all available width to make text alignment work in this case. Look like for some reason it doesn't.

Add Coverity badge /s static analysis on CI

Free Coverity seems to be down. When it isn't, check out whether it's possible to get it to do something useful, like providing a badge for ReadMe.

Last time I checked, it was ages late on supporting a recent version of Visual Studio, so don't expect much, especially with Core stuff being not 10 years old and the project being built on the latest VS with the latest C#. Even ReSharper fails.

Add true support for FIGlet fonts - port FIGlet for Unix to C#

Apparently FIGlet font implementation from Colorful.Console is a joke which doesn't support any FIGlet features like smushing and transforms. Slanted fonts look like crap because they're designed to be smushed. All FIGlet implementations in C# and Java seem to be based on the same ancestor from which Colorful.Console's implementation descended too (also almost nobody cares about linking to source, apparently). There're forks with basic smushing, but they're far from complete.

According to FIGlet,org, the reference imlementation is FIGlet for Unix (ftp://ftp.figlet.org/pub/figlet/program/unix/) written in C, which also includes FIGlet specification (which is anything but OSS thanks to non-commercial requirements btw) and "intergation-y" tests. There's also FIGwin (ftp://ftp.figlet.org/pub/figlet/program/windows/) written in VB (and compiled to 16-bit NE .exe file) with a somewhat different feature set (see feature comparison in the "spec"), sources of which are lost in the nether.

The whole FIGlet program is 2K LOC of C, half of which are low-level C utilities, so no longer relevant. Should be pretty easy to port. FIGlet also switched to normal open-source license, New BSD. (It contradicts the requirements from the "spec"... Let's assume it's dual-licensed. Nobody is going to sue over FIGlet anyway.)

Dotnet Core?

Will this library compile well with dotnet core? Is there a newer dotnet core version of this library? Thanks for your attention

Extend line characters

Currently LineChar supports only 4 bits of information which isn't enough to completely describe all box-drawing characters. While it works for separate tables, it requires guessing and causes lines of two adjacent tables to join.

  1. Extend LineChar to None/Single/Wide in all 4 directions.
  2. Extend ConsoleBuffer line-drawing methods to allow specifying sub-character lengths.

Various errors while building the example

Hi,
Trying to compile examples in VS2012 and have an errors : first project won't load looking for .net 4.6 framework installed, then it shows a list of errors:

Error   15  Identifier expected; 'static' is a keyword  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\GridLengthConverter.cs   4   7   Alba.CsConsoleFormat
Error   16  Identifier expected; 'static' is a keyword  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\ConsoleColorConverter.cs 4   7   Alba.CsConsoleFormat
Error   17  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\VectorConverter.cs   4   14  Alba.CsConsoleFormat
Error   18  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\ThicknessConverter.cs    4   14  Alba.CsConsoleFormat
Error   19  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\SizeConverter.cs 4   14  Alba.CsConsoleFormat
Error   20  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\RectConverter.cs 4   14  Alba.CsConsoleFormat
Error   21  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\PointConverter.cs    4   14  Alba.CsConsoleFormat
Error   22  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\LineThicknessConverter.cs    4   14  Alba.CsConsoleFormat
Error   23  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\LengthConverter.cs   4   14  Alba.CsConsoleFormat
Error   24  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\GridLengthConverter.cs   4   14  Alba.CsConsoleFormat
Error   25  Expected class, delegate, enum, interface, or struct    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\ConsoleColorConverter.cs 4   14  Alba.CsConsoleFormat
Error   26  ; expected  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\LayoutInfo.cs  12  35  Alba.CsConsoleFormat
Error   27  Invalid token ')' in class, struct, or interface member declaration C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\LayoutInfo.cs  12  49  Alba.CsConsoleFormat
Error   28  Method must have a return type  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\LayoutInfo.cs  12  50  Alba.CsConsoleFormat
Error   29  ; expected  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\XmlLanguageConverter.cs  16  94  Alba.CsConsoleFormat
Error   30  Invalid token '==' in class, struct, or interface member declaration    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\XmlLanguageConverter.cs  16  108 Alba.CsConsoleFormat
Error   31  Invalid token ')' in class, struct, or interface member declaration C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\XmlLanguageConverter.cs  16  124 Alba.CsConsoleFormat
Error   32  ; expected  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\Enums\LineWidth.cs 17  61  Alba.CsConsoleFormat
Error   33  Invalid token '==' in class, struct, or interface member declaration    C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\Enums\LineWidth.cs 17  70  Alba.CsConsoleFormat
Error   34  Invalid token '0' in class, struct, or interface member declaration C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Core\Enums\LineWidth.cs 17  90  Alba.CsConsoleFormat
Error   35  ; expected  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\LengthConverter.cs   17  94  Alba.CsConsoleFormat
Error   36  ; expected  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\ConsoleColorConverter.cs 17  94  Alba.CsConsoleFormat
Error   37  Method must have a return type  C:\Users\Administrator\Documents\Visual Studio 2012\Projects\CsConsoleFormat-master\CsConsoleFormat-master\Alba.CsConsoleFormat\Converters\LengthConverter.cs   17  97  Alba.CsConsoleFormat

errors log.txt

Was wondering what might be causing this issue.

Thanks
Alex

Text Color not working on Linux

Hi,
Is it possible to display colors for text on Linux (RHEL)?

I formatted some documents with colored text on Windows and everything works fine

CipheConsoleWIn
This is how it looks on Windows

but when I run it on Linux (Redhat Enterprise Linux) no colors are displayed as you can see in the following picture.
CipheConsoleRHEL

To note, the system is able to show colors, as seen in the above picture, with the ls command files and directories are listed using colors.

So why it does not show correctly the colors? Do I have to do something special?

Can CsConsoleFormat support output chinese words?

If I output chinese words,the grid will broken,I think the problem is in the character calculation of Chinese characters.
My code is like this:

static void Main(string[] args)
        {
            var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

            Console.WriteLine("outpt Chinese");
            var doc = new Document(
                new Span("Order #") { Color = Yellow }, "Id", "\n",
                new Span("Customer: ") { Color = Yellow }, "Name",
                new Grid
                {
                    Color = Gray,
                    Columns = { GridLength.Char(10), GridLength.Char(20), GridLength.Char(70) },
                    Children = {
                        new Cell("Id") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Name") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Assembly") { Stroke = headerThickness,TextAlign =TextAlign.Center },
                        new[] {
                            new Cell("AAAAA"),
                            new Cell("这里是中文,有错误!"),
                            new Cell("BBBBBBBBBBBBBBBBBBBBBBBB"),
                        }
                    }
                }
            );

            ConsoleRenderer.RenderDocument(doc);
            Console.WriteLine("outpt English");
            doc = new Document(
                new Span("Order #") { Color = Yellow }, "Id", "\n",
                new Span("Customer: ") { Color = Yellow }, "Name",
                new Grid
                {
                    Color = Gray,
                    Columns = { GridLength.Char(10), GridLength.Char(20), GridLength.Char(70) },
                    Children = {
                        new Cell("Id") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Name") { Stroke = headerThickness ,TextAlign =TextAlign.Center},
                        new Cell("Assembly") { Stroke = headerThickness,TextAlign =TextAlign.Center },
                        new[] {
                            new Cell("AAAAA"),
                            new Cell("This is English,And it is OK"),
                            new Cell("BBBBBBBBBBBBBBBBBBBBBBBB"),
                        }
                    }
                }
            );

            ConsoleRenderer.RenderDocument(doc);
        }

the output is the follow.
image

Add CodeCov badge /s code coverage on CI

Add CodeCov badge. As a bonus, it shows pretty diagrams of code coverage.

Use example CodeCov C# repository as an example.

Code coverage apparently requires debug(?) build with full non-portable PDBs, so switch to Build Debug -> Test & Coverage -> Build Release -> Deploy sequence? There're no parallel builds on free AppVeyour plan, so no point in separating build jobs even if it's possible. Symbol Packages for .NET Standard libraries are probably supposed to contain portable PDBs, so there's no way around double build, I guess.

Could also be a good time to find out why the heck only 1 set of tests is executed on AppVeyor instead of 6 ( { XAML, No-XAML } x { Core 1.1, Core 2.0, .NET 4.6 } ).

Related:

P. S. Coveralls to CodeCov is like SensioLabs Insight to Scrutinizer. Don't bother with it. Not worth the badge. Well, maybe. If it's one line of code in the build script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.