dataframe-textual 3.0.0__tar.gz → 3.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/PKG-INFO +1 -1
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/pyproject.toml +1 -1
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_table.py +184 -67
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/loading_screen.py +5 -1
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/uv.lock +1 -1
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/.gitignore +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/LICENSE +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/README.md +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/main.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/__init__.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/__main__.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/commands.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/common.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/console_panel.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_viewer.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/file_picker_screen.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/help_panel.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/keybindings.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/run_command_screen.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/status_bar.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/table_screen.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/text_screen.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/theme_screen.py +0 -0
- {dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/yes_no_screen.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dataframe-textual
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1.1
|
|
4
4
|
Summary: Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc.
|
|
5
5
|
Project-URL: Homepage, https://github.com/need47/dataframe-textual
|
|
6
6
|
Project-URL: Repository, https://github.com/need47/dataframe-textual.git
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dataframe-textual"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.1.1"
|
|
8
8
|
description = "Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
{dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_table.py
RENAMED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
import io
|
|
4
4
|
import sys
|
|
5
5
|
from collections import defaultdict, deque
|
|
6
|
-
from dataclasses import dataclass
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
7
|
from functools import partial
|
|
8
8
|
from itertools import zip_longest
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from threading import Event
|
|
11
|
+
from types import MethodType
|
|
11
12
|
from typing import TYPE_CHECKING, Any, Callable
|
|
12
13
|
|
|
13
14
|
if TYPE_CHECKING:
|
|
@@ -393,25 +394,101 @@ class DataFrameTable(DataTable):
|
|
|
393
394
|
return wrapper
|
|
394
395
|
|
|
395
396
|
def with_busy_screen(func: Callable) -> Callable:
|
|
396
|
-
"""Decorator that
|
|
397
|
+
"""Decorator that runs expensive work in a thread while showing BusyScreen.
|
|
397
398
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
and
|
|
399
|
+
The wrapped function executes on a worker thread. UI-affecting calls that
|
|
400
|
+
commonly follow data mutations (``setup_table``, ``move_cursor``, and
|
|
401
|
+
``notify``) are deferred and replayed on the main thread after the busy
|
|
402
|
+
modal closes.
|
|
401
403
|
"""
|
|
402
404
|
|
|
405
|
+
@dataclass
|
|
406
|
+
class _BusyState:
|
|
407
|
+
"""Deferred UI actions collected during worker execution."""
|
|
408
|
+
|
|
409
|
+
needs_setup_table: bool = False
|
|
410
|
+
pending_move_cursor: tuple[tuple, dict] | None = None
|
|
411
|
+
pending_notifies: list[tuple[tuple, dict]] = field(default_factory=list)
|
|
412
|
+
|
|
413
|
+
def _patch_ui_methods(self, state: _BusyState) -> tuple[Callable, Callable, Callable]:
|
|
414
|
+
"""Patch UI-affecting methods to defer execution while worker thread is running."""
|
|
415
|
+
original_setup_table = self.setup_table
|
|
416
|
+
original_move_cursor = self.move_cursor
|
|
417
|
+
original_notify = self.notify
|
|
418
|
+
|
|
419
|
+
def defer_setup_table(_self, *setup_args, **setup_kwargs) -> None:
|
|
420
|
+
"""Record table rebuild request for replay on the main thread."""
|
|
421
|
+
state.needs_setup_table = True
|
|
422
|
+
|
|
423
|
+
def defer_move_cursor(_self, *move_args, **move_kwargs) -> None:
|
|
424
|
+
"""Keep only the latest cursor move request for replay."""
|
|
425
|
+
state.pending_move_cursor = (move_args, move_kwargs)
|
|
426
|
+
|
|
427
|
+
def defer_notify(_self, *notify_args, **notify_kwargs) -> None:
|
|
428
|
+
"""Queue notifications to preserve order when replayed."""
|
|
429
|
+
state.pending_notifies.append((notify_args, notify_kwargs))
|
|
430
|
+
|
|
431
|
+
self.setup_table = MethodType(defer_setup_table, self)
|
|
432
|
+
self.move_cursor = MethodType(defer_move_cursor, self)
|
|
433
|
+
self.notify = MethodType(defer_notify, self)
|
|
434
|
+
|
|
435
|
+
return (original_setup_table, original_move_cursor, original_notify)
|
|
436
|
+
|
|
437
|
+
def _apply_deferred_ui(
|
|
438
|
+
self,
|
|
439
|
+
state: _BusyState,
|
|
440
|
+
original_setup_table: Callable,
|
|
441
|
+
original_move_cursor: Callable,
|
|
442
|
+
original_notify: Callable,
|
|
443
|
+
) -> None:
|
|
444
|
+
"""Apply deferred UI actions on the main thread after the worker completes."""
|
|
445
|
+
if state.needs_setup_table:
|
|
446
|
+
original_setup_table()
|
|
447
|
+
|
|
448
|
+
if state.pending_move_cursor is not None:
|
|
449
|
+
move_args, move_kwargs = state.pending_move_cursor
|
|
450
|
+
original_move_cursor(*move_args, **move_kwargs)
|
|
451
|
+
|
|
452
|
+
for notify_args, notify_kwargs in state.pending_notifies:
|
|
453
|
+
original_notify(*notify_args, **notify_kwargs)
|
|
454
|
+
|
|
403
455
|
@work(thread=True)
|
|
404
|
-
def _worker(self, *args, **kwargs):
|
|
456
|
+
def _worker(self, state: _BusyState, *args, **kwargs):
|
|
405
457
|
"""Execute the wrapped function in a background thread."""
|
|
458
|
+
original_setup_table, original_move_cursor, original_notify = _patch_ui_methods(self, state)
|
|
459
|
+
|
|
406
460
|
try:
|
|
407
461
|
func(self, *args, **kwargs)
|
|
408
462
|
finally:
|
|
409
463
|
self.task_done = True
|
|
464
|
+
# Restore original methods after the worker completes
|
|
465
|
+
self.setup_table = original_setup_table
|
|
466
|
+
self.move_cursor = original_move_cursor
|
|
467
|
+
self.notify = original_notify
|
|
410
468
|
|
|
411
469
|
def wrapper(self, *args, **kwargs):
|
|
412
470
|
"""Set up BusyScreen and dispatch work to a background thread."""
|
|
471
|
+
state = _BusyState()
|
|
472
|
+
original_setup_table = self.setup_table
|
|
473
|
+
original_move_cursor = self.move_cursor
|
|
474
|
+
original_notify = self.notify
|
|
475
|
+
on_done = partial(
|
|
476
|
+
_apply_deferred_ui,
|
|
477
|
+
self,
|
|
478
|
+
state,
|
|
479
|
+
original_setup_table,
|
|
480
|
+
original_move_cursor,
|
|
481
|
+
original_notify,
|
|
482
|
+
)
|
|
483
|
+
|
|
413
484
|
self.task_done = False
|
|
414
|
-
self.app.push_screen(
|
|
485
|
+
self.app.push_screen(
|
|
486
|
+
BusyScreen(
|
|
487
|
+
self,
|
|
488
|
+
task=partial(_worker, self, state, *args, **kwargs),
|
|
489
|
+
on_done=on_done,
|
|
490
|
+
)
|
|
491
|
+
)
|
|
415
492
|
|
|
416
493
|
return wrapper
|
|
417
494
|
|
|
@@ -1242,50 +1319,86 @@ class DataFrameTable(DataTable):
|
|
|
1242
1319
|
# self.app._set_status_context(self)
|
|
1243
1320
|
|
|
1244
1321
|
def determine_column_widths(self) -> dict[str, int]:
|
|
1245
|
-
"""Determine optimal width for each column based on data type and content.
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
-
|
|
1322
|
+
"""Determine optimal width for each visible column based on data type and sampled content.
|
|
1323
|
+
|
|
1324
|
+
Algorithm (two phases):
|
|
1325
|
+
|
|
1326
|
+
**Phase 1 - initial widths:**
|
|
1327
|
+
- The column label width is always the floor (label is never clipped).
|
|
1328
|
+
- Bar columns are fixed to BAR_COLUMN_WIDTH.
|
|
1329
|
+
- User-overridden columns (positive width) are fixed to ``max(label, override)``.
|
|
1330
|
+
- URL-only string columns are skipped (let Textual auto-size so they stay clickable).
|
|
1331
|
+
- String columns whose sampled max exceeds COLUMN_WIDTH_CAP are capped at
|
|
1332
|
+
``max(label_width, COLUMN_WIDTH_CAP)`` and queued for phase 2.
|
|
1333
|
+
- All other columns (numeric, bool, temporal, short strings, expanded columns)
|
|
1334
|
+
use their natural sampled max width.
|
|
1335
|
+
|
|
1336
|
+
**Phase 2 - expand capped columns with leftover space:**
|
|
1337
|
+
- Columns are processed in visible order.
|
|
1338
|
+
- If a column's ideal width fits in the remaining available space, expand it
|
|
1339
|
+
exactly to that width and move on.
|
|
1340
|
+
- If a column needs more than the remaining available space (it is "too wide"),
|
|
1341
|
+
distribute the remaining available space **evenly** among it and all
|
|
1342
|
+
subsequent capped columns, then stop.
|
|
1254
1343
|
|
|
1255
1344
|
Returns:
|
|
1256
|
-
dict[str, int]: Mapping of column name to width
|
|
1345
|
+
dict[str, int]: Mapping of column name to display width.
|
|
1257
1346
|
"""
|
|
1258
|
-
col_widths,
|
|
1347
|
+
col_widths: dict[str, int] = {}
|
|
1348
|
+
col_label_widths: dict[str, int] = {}
|
|
1349
|
+
col_ideal_widths: dict[str, int] = {} # uncapped natural max from sampled data
|
|
1350
|
+
capped_cols: list[str] = [] # string cols capped in phase 1, in visible order
|
|
1259
1351
|
|
|
1352
|
+
# Pre-set bar columns
|
|
1260
1353
|
for col in self.bar_columns:
|
|
1261
1354
|
col_widths[col] = BAR_COLUMN_WIDTH
|
|
1262
1355
|
|
|
1263
|
-
#
|
|
1356
|
+
# Available terminal width
|
|
1264
1357
|
init_available_width = self.scrollable_content_region.width or self.app.size.width
|
|
1265
|
-
available_width = init_available_width
|
|
1266
1358
|
|
|
1267
|
-
# Sample
|
|
1359
|
+
# Sample rows for width estimation
|
|
1268
1360
|
sample_size = min(self.BATCH_SIZE, len(self.df))
|
|
1269
1361
|
sample_lf = self.df.lazy().head(sample_size)
|
|
1270
1362
|
|
|
1271
|
-
#
|
|
1363
|
+
# ── Phase 1: initial width for every visible column ───────────────────
|
|
1272
1364
|
for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
|
|
1273
|
-
#
|
|
1365
|
+
# Label width is the hard minimum
|
|
1274
1366
|
label_text = self._build_column_label(col, col_idx)
|
|
1275
|
-
label_width = measure(self.app.console, label_text, 1)
|
|
1367
|
+
label_width = measure(self.app.console, label_text, 1)
|
|
1276
1368
|
col_label_widths[col] = label_width
|
|
1277
1369
|
|
|
1278
|
-
|
|
1279
|
-
|
|
1370
|
+
# Bar columns: already fixed
|
|
1371
|
+
if col in self.bar_columns:
|
|
1372
|
+
col_ideal_widths[col] = col_widths[col]
|
|
1373
|
+
continue
|
|
1374
|
+
|
|
1375
|
+
# User-set fixed width: respect it
|
|
1376
|
+
if col in self.column_widths:
|
|
1377
|
+
override = self.column_widths[col]
|
|
1378
|
+
if override > 0:
|
|
1379
|
+
col_widths[col] = max(label_width, override)
|
|
1380
|
+
col_ideal_widths[col] = col_widths[col]
|
|
1381
|
+
continue
|
|
1382
|
+
# override == -1 means "expanded": fall through and skip the cap below
|
|
1383
|
+
# override == 0 means hidden: excluded from visible_columns already
|
|
1384
|
+
|
|
1385
|
+
dc = DtypeConfig(dtype)
|
|
1386
|
+
is_string = dc.gtype == "string"
|
|
1387
|
+
is_expanded = self.column_widths.get(col) == -1
|
|
1280
1388
|
|
|
1281
1389
|
try:
|
|
1282
|
-
# Get sample values from the column
|
|
1283
1390
|
sample_values = sample_lf.select(col).collect().get_column(col).drop_nulls().to_list()
|
|
1284
|
-
if dtype == pl.String and any(val.startswith(("https://", "http://")) for val in sample_values):
|
|
1285
|
-
continue # Skip link columns so they can auto-size and be clickable
|
|
1286
1391
|
|
|
1287
|
-
#
|
|
1288
|
-
|
|
1392
|
+
# URL columns: leave for Textual auto-sizing so links stay clickable
|
|
1393
|
+
if (
|
|
1394
|
+
is_string
|
|
1395
|
+
and sample_values
|
|
1396
|
+
and any(val.startswith(("https://", "http://")) for val in sample_values)
|
|
1397
|
+
):
|
|
1398
|
+
col_widths[col] = label_width
|
|
1399
|
+
col_ideal_widths[col] = label_width
|
|
1400
|
+
continue
|
|
1401
|
+
|
|
1289
1402
|
max_cell_width = max(
|
|
1290
1403
|
(
|
|
1291
1404
|
measure(self.app.console, str(val[:3]) if isinstance(val, list) else str(val), 1)
|
|
@@ -1293,46 +1406,50 @@ class DataFrameTable(DataTable):
|
|
|
1293
1406
|
),
|
|
1294
1407
|
default=label_width,
|
|
1295
1408
|
)
|
|
1296
|
-
|
|
1297
|
-
# Set column width to max of label and sampled data (capped at reasonable max)
|
|
1298
|
-
max_width = max(label_width, max_cell_width)
|
|
1299
1409
|
except Exception as e:
|
|
1300
|
-
# If any error, let Textual auto-size
|
|
1301
|
-
max_width = label_width
|
|
1302
1410
|
self.log(f"Error determining width for column `{col}`: {e}")
|
|
1411
|
+
max_cell_width = label_width
|
|
1303
1412
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
# If there's still available width, distribute it proportionally to columns that are above the cap
|
|
1326
|
-
if available_width > BUFFER_SIZE:
|
|
1327
|
-
flexible_cols = [
|
|
1328
|
-
col for col in col_widths if col not in self.column_widths and col_widths[col] >= COLUMN_WIDTH_CAP
|
|
1413
|
+
ideal_width = max(label_width, max_cell_width)
|
|
1414
|
+
col_ideal_widths[col] = ideal_width
|
|
1415
|
+
|
|
1416
|
+
if is_string and not is_expanded and ideal_width > COLUMN_WIDTH_CAP:
|
|
1417
|
+
# Cap and queue for phase 2
|
|
1418
|
+
col_widths[col] = max(label_width, COLUMN_WIDTH_CAP)
|
|
1419
|
+
capped_cols.append(col)
|
|
1420
|
+
else:
|
|
1421
|
+
# Numeric / bool / temporal / short string / expanded: natural width
|
|
1422
|
+
col_widths[col] = ideal_width
|
|
1423
|
+
|
|
1424
|
+
# ── Phase 2: expand capped columns sequentially with leftover space ──
|
|
1425
|
+
available_width = init_available_width - sum(col_widths.values())
|
|
1426
|
+
|
|
1427
|
+
if available_width > 0 and capped_cols:
|
|
1428
|
+
# Only columns that can still grow
|
|
1429
|
+
expandable = [
|
|
1430
|
+
(col, col_ideal_widths[col] - col_widths[col])
|
|
1431
|
+
for col in capped_cols
|
|
1432
|
+
if col_ideal_widths.get(col, 0) > col_widths.get(col, 0)
|
|
1329
1433
|
]
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1434
|
+
|
|
1435
|
+
i = 0
|
|
1436
|
+
while i < len(expandable) and available_width > 0:
|
|
1437
|
+
col, needed = expandable[i]
|
|
1438
|
+
|
|
1439
|
+
if needed <= available_width:
|
|
1440
|
+
# Enough room: give the column exactly what it needs
|
|
1441
|
+
col_widths[col] += needed
|
|
1442
|
+
available_width -= needed
|
|
1443
|
+
i += 1
|
|
1444
|
+
else:
|
|
1445
|
+
# Column is too wide for remaining space: distribute
|
|
1446
|
+
# available_width evenly among this and all remaining capped columns
|
|
1447
|
+
remaining = expandable[i:]
|
|
1448
|
+
share = available_width // len(remaining)
|
|
1449
|
+
for rcol, _ in remaining:
|
|
1450
|
+
col_widths[rcol] += share
|
|
1451
|
+
available_width = 0
|
|
1452
|
+
break
|
|
1336
1453
|
|
|
1337
1454
|
return col_widths
|
|
1338
1455
|
|
|
@@ -81,16 +81,18 @@ class BusyScreen(ModalScreen):
|
|
|
81
81
|
}
|
|
82
82
|
"""
|
|
83
83
|
|
|
84
|
-
def __init__(self, dftable: "DataFrameTable", task: Callable) -> None:
|
|
84
|
+
def __init__(self, dftable: "DataFrameTable", task: Callable, on_done: Callable | None = None) -> None:
|
|
85
85
|
"""Initialize the busy screen.
|
|
86
86
|
|
|
87
87
|
Args:
|
|
88
88
|
dftable: The DataFrameTable associated with the running task.
|
|
89
89
|
task: Callable to invoke on mount that starts the background work.
|
|
90
|
+
on_done: Optional callback invoked on the main thread after the modal is dismissed.
|
|
90
91
|
"""
|
|
91
92
|
super().__init__()
|
|
92
93
|
self.dftable = dftable
|
|
93
94
|
self.run_task = task
|
|
95
|
+
self.on_done = on_done
|
|
94
96
|
|
|
95
97
|
def compose(self) -> ComposeResult:
|
|
96
98
|
"""Compose the loading indicator widget."""
|
|
@@ -105,6 +107,8 @@ class BusyScreen(ModalScreen):
|
|
|
105
107
|
"""Check the loading progress of the dataframe."""
|
|
106
108
|
if self.dftable.task_done:
|
|
107
109
|
self.dismiss()
|
|
110
|
+
if self.on_done:
|
|
111
|
+
self.call_later(self.on_done)
|
|
108
112
|
|
|
109
113
|
def action_cancel(self) -> None:
|
|
110
114
|
self.dismiss()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_viewer.py
RENAMED
|
File without changes
|
{dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/file_picker_screen.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dataframe_textual-3.0.0 → dataframe_textual-3.1.1}/src/dataframe_textual/run_command_screen.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|