Skip to content

feat: Double Ctrl+C to close pgxcli#95

Merged
balajz merged 4 commits into
balajz:mainfrom
LeeFred3042U:feat/Double-Ctrl+C-to-close-pgxcli
Jun 18, 2026
Merged

feat: Double Ctrl+C to close pgxcli#95
balajz merged 4 commits into
balajz:mainfrom
LeeFred3042U:feat/Double-Ctrl+C-to-close-pgxcli

Conversation

@LeeFred3042U

Copy link
Copy Markdown
Contributor

Closes #75

Changes

internal/app/ui/model.go

  • Added ctrlcSeq int field to Model to track the current Ctrl+C seq generated
  • In Update():
    • updated the StatePending guard to also exclude Interrupt key
    • updated seqTimeoutMsg case to also check ctrlcSeq
    • updated Interrupt handler inside tea.KeyMsg block:
      • first Ctrl+C in StateInput sets StatePending and fires a tea.Tick
      • second Ctrl+C within 500ms dispatches QuitRequestMsg and returns to StateInput
      • Ctrl+C during StateExecuting remains instant cancel, no double press required

Notes

@balajz

balajz commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Hi, since both share the same state, pressing Esc and Ctrl+C will close the pgxcli.

How about using a global sequence counter and splitting the states?

escSeq   int
ctrlcSeq int

to

pendingSeq int
const (
    StateInput State = iota
    StateExecuting
    StatePendingClear
    StatePendingQuit
)

@LeeFred3042U

Copy link
Copy Markdown
Contributor Author

@balajz ok

@balajz balajz marked this pull request as draft June 13, 2026 09:28
@LeeFred3042U LeeFred3042U force-pushed the feat/Double-Ctrl+C-to-close-pgxcli branch from 5511f78 to 701f59f Compare June 15, 2026 16:06
@LeeFred3042U

Copy link
Copy Markdown
Contributor Author

@balajz

Changes

internal/app/ui/model.go

  • Replaced StatePending with StatePendingClear and StatePendingQuit in the State iota
  • Replaced escSeq int and ctrlcSeq int with a single pendingSeq int field on Model
  • In Update() I updated:
    • the pending guard to check StatePendingClear || StatePendingQuit instead of StatePending
    • the seqTimeoutMsg case which is now simplified to a single msg.seq == m.pendingSeq check since states no longer overlap
    • the Interrupt handler:
      • first Ctrl+C in StateInput sets StatePendingQuit and fires a tea.Tick
      • second Ctrl+C within 500ms dispatches QuitRequestMsg and returns to StateInput
      • Ctrl+C during StateExecuting remains instant cancel, no double press required
    • the Clear handler to use StatePendingClear instead of StatePending

Note: When running select pg_sleep(5);, when ctrl+c is pressed it stops the program, heres the statement, what should be done here?

postgres@localhost:postgres> select pg_sleep(5);                       
✗ ERROR: canceling statement due to user request (SQLSTATE 57014)

@LeeFred3042U LeeFred3042U marked this pull request as ready for review June 15, 2026 16:09
@balajz

balajz commented Jun 17, 2026

Copy link
Copy Markdown
Owner

It looks like you might have forgotten to push the changes you mentioned in your latest comment!

@LeeFred3042U

Copy link
Copy Markdown
Contributor Author

@balajz mb
some conflicts occurred but now it works
Should i squash the commits?

@balajz

balajz commented Jun 18, 2026

Copy link
Copy Markdown
Owner

@balajz mb some conflicts occurred but now it works Should i squash the commits?

thanks for the contributions. I will squash the commits.

@balajz balajz merged commit ff87bd6 into balajz:main Jun 18, 2026
8 checks passed
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.

feat: Double Ctrl+C to close pgxcli

2 participants