Coder Social home page Coder Social logo
go-elastictable

pjcdawkins / go-elastictable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rdsubhas/go-elastictable

0.0 0.0 0.0 17 KB

Elastic terminal table that resizes to adapt terminal width

Home Page: https://godoc.org/github.com/rdsubhas/go-elastictable

License: MIT License

Go 95.39% Dockerfile 4.61%

go-elastictable's Introduction

go-elastictable Build Status Go Report Card godoc

Go command line tables with elastic column resizing to adapt terminal width.

Approach

Naive algorithms simply take width-of-table/width-of-terminal and apply a uniform factor to grow/shrink the columns. This results in shoddy output, small columns become worse when wrapped.

This library optimizes for visual balance by doing the following:

  • Closely pack wrapped lines:

    # don't:
    | don't waste whitespace in the second |
    | line                                 |
    
    # do:
    | when wrapping a column |
    | try to pack the lines  |
    | as closely as possible |
    
  • Balance row heights:

    # don't:
    | COL-1       | COL-2       | COL-3       |
    +-------------+-------------+-------------+
    | small col   | small col   | really big  |
    |             |             | column that |
    |             |             | spans many  |
    |             |             | rows        |
    
    # do:
    | COL-1 | COL-2 | COL-3                   |
    +-------+-------+-------------------------+
    | small | small | really big column that  |
    | col   | col   | spans many rows         |
    
  • Number of lines depends on wrapping behavior and is hard to predict in advance. So instead of fully computing expensive re-wraps for every pass, it rather just guesses the number of lines using simple rune widths. This works well in most cases, except there will be some trade-offs in certain scenarios.

Compatibility Note

This library is currently under active development. Please use a dependency manager (like godep) to pin specific commit versions.

go-elastictable's People

Contributors

rdsubhas avatar

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.