Skip to content

Conversation

@devadathanmb
Copy link

@devadathanmb devadathanmb commented Jan 24, 2026

Description

Adds support for displaying transaction status in the prompt via the \T escape sequence, similar to psql's %x

Behavior:

  • * — inside a valid transaction block
  • ! — inside a failed transaction block
  • ? — connection is closed/indeterminate
  • (empty) — idle, not in a transaction

Example usage in ~/.config/pgcli/config:

prompt = '\u@\h:\d>\T '

This produces prompts like (as shown in the attached screenshot below):

user@localhost:mydb>  SELECT 1;      -- idle

user@localhost:mydb>* BEGIN;         -- in transaction

user@localhost:mydb>! ...            -- failed transaction

user@localhost:mydb>? ...            -- if connection is closed
image image

NOTE: Uses \T instead of \x to avoid conflicts with ANSI escape sequences (\x1b) processing done in the codebase.

Closes #1552

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@devadathanmb devadathanmb marked this pull request as ready for review January 24, 2026 15:11
Copilot AI review requested due to automatic review settings January 24, 2026 15:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for a transaction status indicator escape (\T) in the prompt, analogous to psql’s %x, so users can see transaction state directly in their prompt.

Changes:

  • Introduces PGExecute.transaction_indicator (and is_connection_closed) to derive a single-character transaction state marker (*, !, ?, or empty).
  • Extends PGCli.get_prompt and the default pgclirc configuration to support a new \T prompt escape for transaction status.
  • Adds tests for \T prompt rendering and updates AUTHORS.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pgcli/pgexecute.py Adds is_connection_closed and the transaction_indicator property, reusing existing transaction status helpers to compute the * / ! / ? / empty marker.
pgcli/main.py Extends get_prompt to replace \T with pgexecute.transaction_indicator, wiring the new indicator into prompt rendering.
pgcli/pgclirc Documents the new \T prompt escape and its behavior alongside existing prompt placeholders.
tests/test_main.py Adds tests covering \T in simple and full prompts; currently sets transaction_indicator via PropertyMock on MagicMock’s type, which mutates global MagicMock state.
AUTHORS Adds a new contributor entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Use direct attribute assignment on MagicMock instead of type()
to avoid polluting the global MagicMock class state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: show transaction status in pgcli prompt (%x, like psql)

1 participant