Journal Dispositio, une bibliothèque Shell POSIX pour afficher des tables de données

Posté par  (site web personnel) . Licence CC By‑SA.
Étiquettes :
7
8
août
2025

Si, comme moi, vous avez eu à reprendre et adapter du script shell pour afficher des tableaux avec mise en forme dans le terminal ou dans des script générant des syntaxes Markdown ou Textile (Génération automatique de ticket Redmine), alors vous serez sans doute intéressé par Dispositio.
Dispositio est un script shell conforme POSIX qui permet l'affichage des tables de données provenant de fichiers CSV, JSON et YAML dans le terminal. Il offre un formatage avancé, un support des couleurs, et peut être utilisé comme un outil en ligne de commande autonome ou comme une bibliothèque shell pour la génération de tableaux.

Fonctionnalités clés :
- Formats d'entrée multiples (CSV, YAML et JSON)
- Utilisation en CLI ou en bibliothèque (dans ce cas, utilisation de fonctions dispositio_add_* pour ajouter des colonnes, lignes ou cellules)
- Formatage de la sortie (couleurs, mise en forme, style de texte et alignments)
- Sortie en format Terminal, Markdown (avec CSS, non-compatible Github) et Textile (Redmine)

Exemples avec ce fichier JSON

{
  "title": [
    "JSON",
    "Essai"
  ],
  "display": "top",
  "color": "",
  "align": "center",
  "columns": [
    {
      "title": [
        "Header1",
        ""
      ],
      "color": "red",
      "align": ""
    },
    {
      "title": [
        "Header2",
        "Essai"
      ],
      "color": "",
      "align": ""
    },
    {
      "title": [
        "Header3",
        ""
      ],
      "color": "",
      "align": ""
    }
  ],
  "rows": [
    {
      "title": [],
      "color": "green",
      "align": "",
      "valign": "top",
      "separator": 1,
      "cells": [
        {
          "lines": [
            "Row1",
            "Cell1",
            "essai"
          ],
          "color": "",
          "align": ""
        },
        {
          "lines": [
            "",
            "Row1 - Cell2",
            ""
          ],
          "color": "",
          "align": ""
        },
        {
          "lines": [
            "",
            "Row1 - Cell3",
            ""
          ],
          "color": "",
          "align": ""
        }
      ]
    },
    {
      "title": [],
      "color": "",
      "align": "",
      "separator": 0,
      "cells": [
        {
          "lines": [
            "Row2 - Cell1"
          ],
          "color": "",
          "align": ""
        },
        {
          "lines": [
            "Row2 - Cell2"
          ],
          "color": "",
          "align": ""
        },
        {
          "lines": [
            "Row2 - Cell3"
          ],
          "color": "",
          "align": ""
        }
      ]
    }
  ]
}
Sortie Terminal

Terminal

Sortie Markdown
<style>
    .dpo table{margin: 0px auto;}
    .dpo_title{
        text-align: center;
        font-style: bold;
        font-size: 24px;
    }
    .dpo th{
        background: grey;
        text-align: center;
        vertical-align: top;
        font-style: bold;
    }
    .dpo td:nth-child(1){
        background: red;
    }
    .dpo th:nth-child(1){
        background: brown;
    }
    .dpo tr:nth-child(1){
        background: green;
        vertical-align: top;
    }
    .dpo  tr:nth-child(1) td:nth-child(1){
        background: olive !important;
    }
</style>

<div class='dpo'>
<div class='dpo_title'>
JSON<br>Essai<br>
</div>

| Header1 | Header2<br>Essai | Header3 |
|-|-|-|
| Row1<br>Cell1<br>essai | Row1 - Cell2 | Row1 - Cell3 |
| Row2 - Cell1 | Row2 - Cell2 | Row2 - Cell3 |


</div>

Markdown

Sortie Textile
h1{text-align:center; font-size:24px}. *JSON<br>Essai<br>*

table{margin: 0px auto}.
|^.
|_={background-color:brown}. Header1 |_=. Header2<br/>Essai |_=. Header3 |
|={background-color:olive; vertical-align:top}. Row1<br/>Cell1<br/>essai |={background-color:green; vertical-align:top}. Row1 - Cell2 |={background-color:green; vertical-align:top}. Row1 - Cell3 |
|={background-color:red; vertical-align:middle}. Row2 - Cell1 |={vertical-align:middle}. Row2 - Cell2 |={vertical-align:middle}. Row2 - Cell3 |

Textile

Envoyer un commentaire

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.