dfd
This commit is contained in:
59
pipeline.py
59
pipeline.py
@@ -52,9 +52,11 @@ _PIPELINE_LAST_ITEMS: List[Any] = []
|
||||
# Store the last result table for @ selection syntax (e.g., @2, @2-5, @{1,3,5})
|
||||
_LAST_RESULT_TABLE: Optional[Any] = None
|
||||
_LAST_RESULT_ITEMS: List[Any] = []
|
||||
# Subject for the current result table (e.g., the file whose tags/URLs are displayed)
|
||||
_LAST_RESULT_SUBJECT: Optional[Any] = None
|
||||
|
||||
# History of result tables for @.. navigation (LIFO stack, max 20 tables)
|
||||
_RESULT_TABLE_HISTORY: List[tuple[Optional[Any], List[Any]]] = []
|
||||
_RESULT_TABLE_HISTORY: List[tuple[Optional[Any], List[Any], Optional[Any]]] = []
|
||||
_MAX_RESULT_TABLE_HISTORY = 20
|
||||
|
||||
# Current stage table for @N expansion (separate from history)
|
||||
@@ -70,6 +72,8 @@ _DISPLAY_ITEMS: List[Any] = []
|
||||
# Table for display-only commands (overlay)
|
||||
# Used when a command wants to show a specific table formatting but not affect history
|
||||
_DISPLAY_TABLE: Optional[Any] = None
|
||||
# Subject for overlay/display-only tables (takes precedence over _LAST_RESULT_SUBJECT)
|
||||
_DISPLAY_SUBJECT: Optional[Any] = None
|
||||
|
||||
# Track the indices the user selected via @ syntax for the current invocation
|
||||
_PIPELINE_LAST_SELECTION: List[int] = []
|
||||
@@ -262,7 +266,7 @@ def reset() -> None:
|
||||
"""Reset all pipeline state. Called between pipeline executions."""
|
||||
global _PIPE_EMITS, _PIPE_ACTIVE, _PIPE_IS_LAST, _PIPELINE_VALUES
|
||||
global _LAST_PIPELINE_CAPTURE, _PIPELINE_REFRESHED, _PIPELINE_LAST_ITEMS
|
||||
global _PIPELINE_COMMAND_TEXT
|
||||
global _PIPELINE_COMMAND_TEXT, _LAST_RESULT_SUBJECT, _DISPLAY_SUBJECT
|
||||
|
||||
_PIPE_EMITS = []
|
||||
_PIPE_ACTIVE = False
|
||||
@@ -272,6 +276,8 @@ def reset() -> None:
|
||||
_PIPELINE_LAST_ITEMS = []
|
||||
_PIPELINE_VALUES = {}
|
||||
_PIPELINE_COMMAND_TEXT = ""
|
||||
_LAST_RESULT_SUBJECT = None
|
||||
_DISPLAY_SUBJECT = None
|
||||
|
||||
|
||||
def get_emitted_items() -> List[Any]:
|
||||
@@ -419,7 +425,7 @@ def trigger_ui_library_refresh(library_filter: str = 'local') -> None:
|
||||
print(f"[trigger_ui_library_refresh] Error calling refresh callback: {e}", file=sys.stderr)
|
||||
|
||||
|
||||
def set_last_result_table(result_table: Optional[Any], items: Optional[List[Any]] = None) -> None:
|
||||
def set_last_result_table(result_table: Optional[Any], items: Optional[List[Any]] = None, subject: Optional[Any] = None) -> None:
|
||||
"""Store the last result table and items for @ selection syntax.
|
||||
|
||||
This should be called after displaying a result table, so users can reference
|
||||
@@ -433,11 +439,12 @@ def set_last_result_table(result_table: Optional[Any], items: Optional[List[Any]
|
||||
result_table: The ResultTable object that was displayed (or None)
|
||||
items: List of items that populated the table (optional)
|
||||
"""
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _RESULT_TABLE_HISTORY, _DISPLAY_ITEMS, _DISPLAY_TABLE
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _LAST_RESULT_SUBJECT
|
||||
global _RESULT_TABLE_HISTORY, _DISPLAY_ITEMS, _DISPLAY_TABLE, _DISPLAY_SUBJECT
|
||||
|
||||
# Push current table to history before replacing
|
||||
if _LAST_RESULT_TABLE is not None:
|
||||
_RESULT_TABLE_HISTORY.append((_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS.copy()))
|
||||
_RESULT_TABLE_HISTORY.append((_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS.copy(), _LAST_RESULT_SUBJECT))
|
||||
# Keep history size limited
|
||||
if len(_RESULT_TABLE_HISTORY) > _MAX_RESULT_TABLE_HISTORY:
|
||||
_RESULT_TABLE_HISTORY.pop(0)
|
||||
@@ -445,11 +452,13 @@ def set_last_result_table(result_table: Optional[Any], items: Optional[List[Any]
|
||||
# Set new current table and clear any display items/table
|
||||
_DISPLAY_ITEMS = []
|
||||
_DISPLAY_TABLE = None
|
||||
_DISPLAY_SUBJECT = None
|
||||
_LAST_RESULT_TABLE = result_table
|
||||
_LAST_RESULT_ITEMS = items or []
|
||||
_LAST_RESULT_SUBJECT = subject
|
||||
|
||||
|
||||
def set_last_result_table_overlay(result_table: Optional[Any], items: Optional[List[Any]] = None) -> None:
|
||||
def set_last_result_table_overlay(result_table: Optional[Any], items: Optional[List[Any]] = None, subject: Optional[Any] = None) -> None:
|
||||
"""Set a result table as an overlay (display only, no history).
|
||||
|
||||
Used for commands like get-tag that want to show a formatted table but
|
||||
@@ -459,13 +468,14 @@ def set_last_result_table_overlay(result_table: Optional[Any], items: Optional[L
|
||||
result_table: The ResultTable object to display
|
||||
items: List of items for @N selection
|
||||
"""
|
||||
global _DISPLAY_ITEMS, _DISPLAY_TABLE
|
||||
global _DISPLAY_ITEMS, _DISPLAY_TABLE, _DISPLAY_SUBJECT
|
||||
|
||||
_DISPLAY_TABLE = result_table
|
||||
_DISPLAY_ITEMS = items or []
|
||||
_DISPLAY_SUBJECT = subject
|
||||
|
||||
|
||||
def set_last_result_table_preserve_history(result_table: Optional[Any], items: Optional[List[Any]] = None) -> None:
|
||||
def set_last_result_table_preserve_history(result_table: Optional[Any], items: Optional[List[Any]] = None, subject: Optional[Any] = None) -> None:
|
||||
"""Update the last result table WITHOUT adding to history.
|
||||
|
||||
Used for action commands (delete-tag, add-tag, etc.) that modify data but shouldn't
|
||||
@@ -475,11 +485,12 @@ def set_last_result_table_preserve_history(result_table: Optional[Any], items: O
|
||||
result_table: The ResultTable object that was displayed (or None)
|
||||
items: List of items that populated the table (optional)
|
||||
"""
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _LAST_RESULT_SUBJECT
|
||||
|
||||
# Update current table WITHOUT pushing to history
|
||||
_LAST_RESULT_TABLE = result_table
|
||||
_LAST_RESULT_ITEMS = items or []
|
||||
_LAST_RESULT_SUBJECT = subject
|
||||
|
||||
|
||||
def set_last_result_items_only(items: Optional[List[Any]]) -> None:
|
||||
@@ -494,13 +505,14 @@ def set_last_result_items_only(items: Optional[List[Any]]) -> None:
|
||||
Args:
|
||||
items: List of items to select from
|
||||
"""
|
||||
global _DISPLAY_ITEMS, _DISPLAY_TABLE
|
||||
global _DISPLAY_ITEMS, _DISPLAY_TABLE, _DISPLAY_SUBJECT
|
||||
|
||||
# Store items for immediate @N selection, but DON'T modify _LAST_RESULT_ITEMS
|
||||
# This ensures history contains original search data, not display transformations
|
||||
_DISPLAY_ITEMS = items or []
|
||||
# Clear display table since we're setting items only (CLI will generate table if needed)
|
||||
_DISPLAY_TABLE = None
|
||||
_DISPLAY_SUBJECT = None
|
||||
|
||||
|
||||
def restore_previous_result_table() -> bool:
|
||||
@@ -509,22 +521,32 @@ def restore_previous_result_table() -> bool:
|
||||
Returns:
|
||||
True if a previous table was restored, False if history is empty
|
||||
"""
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _RESULT_TABLE_HISTORY, _DISPLAY_ITEMS, _DISPLAY_TABLE
|
||||
global _LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _LAST_RESULT_SUBJECT
|
||||
global _RESULT_TABLE_HISTORY, _DISPLAY_ITEMS, _DISPLAY_TABLE, _DISPLAY_SUBJECT
|
||||
|
||||
# If we have an active overlay (display items/table), clear it to "go back" to the underlying table
|
||||
if _DISPLAY_ITEMS or _DISPLAY_TABLE:
|
||||
if _DISPLAY_ITEMS or _DISPLAY_TABLE or _DISPLAY_SUBJECT is not None:
|
||||
_DISPLAY_ITEMS = []
|
||||
_DISPLAY_TABLE = None
|
||||
_DISPLAY_SUBJECT = None
|
||||
return True
|
||||
|
||||
if not _RESULT_TABLE_HISTORY:
|
||||
return False
|
||||
|
||||
# Pop from history and restore
|
||||
_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS = _RESULT_TABLE_HISTORY.pop()
|
||||
prev = _RESULT_TABLE_HISTORY.pop()
|
||||
if isinstance(prev, tuple) and len(prev) >= 3:
|
||||
_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _LAST_RESULT_SUBJECT = prev[0], prev[1], prev[2]
|
||||
elif isinstance(prev, tuple) and len(prev) == 2:
|
||||
_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS = prev
|
||||
_LAST_RESULT_SUBJECT = None
|
||||
else:
|
||||
_LAST_RESULT_TABLE, _LAST_RESULT_ITEMS, _LAST_RESULT_SUBJECT = None, [], None
|
||||
# Clear display items so get_last_result_items() falls back to restored items
|
||||
_DISPLAY_ITEMS = []
|
||||
_DISPLAY_TABLE = None
|
||||
_DISPLAY_SUBJECT = None
|
||||
return True
|
||||
|
||||
|
||||
@@ -537,6 +559,17 @@ def get_display_table() -> Optional[Any]:
|
||||
return _DISPLAY_TABLE
|
||||
|
||||
|
||||
def get_last_result_subject() -> Optional[Any]:
|
||||
"""Get the subject associated with the current result table or overlay.
|
||||
|
||||
Overlay subject (from display-only tables) takes precedence; otherwise returns
|
||||
the subject stored with the last result table.
|
||||
"""
|
||||
if _DISPLAY_SUBJECT is not None:
|
||||
return _DISPLAY_SUBJECT
|
||||
return _LAST_RESULT_SUBJECT
|
||||
|
||||
|
||||
def get_last_result_table() -> Optional[Any]:
|
||||
"""Get the current last result table.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user