# How Outfancy's Priority System Decides Which Columns to Hide First

> Discover how Outfancy's priority system intelligently hides columns starting with low priority data like descriptions and dates to preserve essential identifiers and numeric values on limited terminal widths.

- Repository: [Carlos A. Planchón/outfancy](https://github.com/carlosplanchon/outfancy)
- Tags: internals
- Published: 2026-02-26

---

**Outfancy hides columns starting from the lowest priority data types—such as descriptions, times, and dates—while preserving high-priority identifiers and numeric values whenever terminal width is insufficient to display all columns.**

Outfancy is a Python library designed for rendering formatted tables in constrained terminal environments. When the available screen width cannot accommodate every column, the library employs an intelligent priority system that automatically ranks columns by their detected data types to determine which fields to conceal first, ensuring the most critical information remains visible.

## How the Priority System Works

The rendering engine in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py) follows a four-step workflow to determine column visibility. This process balances automatic type detection with configurable width constraints.

### Step 1: Automatic Data Type Detection

First, the method `check_data_type_list_integrity` analyzes a sample of rows from the dataset to classify each column. Located around line 1000 in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py), this function categorizes columns into specific types: `id`, `value`, `name`, `date`, `time`, `desc` (description), or `None` for uncategorised data. This classification forms the foundation for the priority ranking.

### Step 2: Building the Priority List

Next, the `check_priority_list` method (approximately line 967 in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py)) receives the list of detected types and constructs an `ordered_priority_list`. This list contains column indices sorted by importance: `id` and `value` indices appear first, followed by `name`, then `date`, `time`, and `desc`. Any uncategorised columns are appended at the end, ensuring they are the first candidates for removal if space is tight.

### Step 3: Width Allocation and Re-balancing

Finally, the `assign_column_width` method (around line 1249 in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py)) attempts to allocate space for every column. If the total required width exceeds the available terminal width (`screen_x`), the function enters a re-balancing loop. Inside this loop, the algorithm checks whether any column’s allocated width falls below the `show_width_threshold` (defaulting to 5 characters). When columns are too narrow to display meaningfully, the engine removes the last element of the `ordered_priority_list`—representing the lowest priority column—and strips it from the rendering order, maximum width, and width lists. This process repeats until all remaining columns satisfy the minimum width threshold or only one column remains.

## Priority Order Hierarchy

Outfancy ranks column importance in the following strict order, from highest to lowest priority:

1. **`id` / `value`** – Primary keys and numeric metrics that are essential for data identification
2. **`name`** – Columns containing mostly alphabetical characters resembling proper names
3. **`date`** – Recognized date string formats
4. **`time`** – Recognized time string formats
5. **`desc`** – Free-form descriptive text with lower informational density
6. **Uncategorised** – Any column that failed to match the known type patterns

Consequently, when the table must drop columns due to narrow screens, it first conceals description fields, then time and date columns, and only as a last resort will it hide identifiers or values.

## Practical Code Examples

### Inspecting Auto-Generated Priorities

You can examine how Outfancy ranks your columns by calling `check_priority_list` directly:

```python
from outfancy import Table

tbl = Table()

# Simulating auto-detected types: id, name, date, description

data_types = ['id', 'name', 'date', 'desc']
priority_indices = tbl.check_priority_list(rearranged_data_type_list=data_types)
print(priority_indices)  # Output: [0, 1, 2, 3]

```

In this output, index `3` (the `desc` column) occupies the last position and will be the first hidden when space constraints trigger column removal.

### Rendering on Narrow Screens

To force column hiding in practice, constrain the terminal width using the `screen_x` parameter:

```python
from outfancy import Table, example_dataset

tbl = Table()

# Force a 30-character width to trigger priority-based removal

output = tbl.render(
    data=example_dataset.dataset,
    screen_x=30
)
print(output)

```

When executed, this code hides low-priority columns (such as descriptions and dates) while preserving the `id` and `name` columns that appear at the front of the priority list.

### Overriding with Custom Priorities

You can bypass automatic detection by supplying a custom `priority_list` to ensure specific columns survive even on narrow displays:

```python
tbl = Table()

# Force column 2 (date) to highest priority, followed by columns 0 and 1

custom_priority = [2, 0, 1]
output = tbl.render(
    data=example_dataset.dataset,
    priority_list=custom_priority,
    screen_x=40
)
print(output)

```

Now the date column remains visible even when other columns would typically be removed, because it appears first in your custom priority ordering.

## Key Implementation Details

The core logic resides in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py), which contains the `check_data_type_list_integrity`, `check_priority_list`, and `assign_column_width` methods that implement the priority and hiding mechanics. Supporting utilities such as `compress_list` and `printed_length`—used during width calculations—are located in [`outfancy/widgets.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/widgets.py). The library also provides sample data in [`outfancy/example_dataset.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/example_dataset.py) for testing these rendering behaviors.

## Summary

- Outfancy automatically classifies columns into data types using `check_data_type_list_integrity` in [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py) (around line 1000).
- The `check_priority_list` function (line 967) constructs a ranked index list where `id` and `value` columns receive highest priority, followed by `name`, `date`, `time`, and `desc`.
- When rendering, `assign_column_width` (line 1249) iteratively removes columns starting from the lowest priority index until all remaining columns exceed the `show_width_threshold` of 5 characters.
- Users can override the automatic priority system by passing a custom `priority_list` to the `render()` method.

## Frequently Asked Questions

### What data types does Outfancy recognize for priority ranking?

Outfancy recognizes six distinct categories: `id` and `value` (highest priority), `name`, `date`, `time`, `desc` (description), and `None` for uncategorised columns that do not match known patterns. These classifications determine the order in which columns are hidden when terminal space is limited.

### How can I prevent specific columns from being hidden?

Pass a custom `priority_list` parameter to the `Table.render()` method, placing the indices of your critical columns at the beginning of the list. Columns appearing earlier in this list are treated as high priority and will only be hidden after all lower-priority columns have been removed.

### What is the minimum width threshold for showing a column?

The default minimum width threshold is **5 characters**, controlled by the `show_width_threshold` attribute (default value `5`). Any column allocated less width than this threshold during the re-balancing process is automatically hidden, triggering the priority-based removal loop until all remaining columns meet this minimum size.

### Where is the column hiding logic implemented?

The hiding logic is implemented in the `assign_column_width` method within [`outfancy/table.py`](https://github.com/carlosplanchon/outfancy/blob/main/outfancy/table.py), specifically between lines 1249 and 1265. This function manages the re-balancing loop that removes the lowest-priority column indices from `ordered_priority_list` when screen real estate is insufficient.