Skip to content

feat: add Close method to UI interface and implement resource cleanup in REPL#452

Open
prasad89 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
prasad89:issue#439-revised
Open

feat: add Close method to UI interface and implement resource cleanup in REPL#452
prasad89 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
prasad89:issue#439-revised

Conversation

@prasad89
Copy link
Contributor

@prasad89 prasad89 commented Aug 3, 2025

In this PR I have addressed #439 (comment) by adding Close method to UI interface and implement resource cleanup in REPL

Closes #439

@mikebz mikebz requested a review from Copilot August 4, 2025 15:36
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 a Close method to the UI interface to enable proper resource cleanup when the REPL terminates. The implementation ensures that UI resources are properly released when the application exits.

  • Added Close() error method to the UI interface for resource cleanup
  • Implemented the Close method in the TUI struct to quit the underlying program
  • Added cleanup call in the REPL function to ensure resources are freed on exit

Reviewed Changes

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

File Description
pkg/ui/interfaces.go Added Close method to UI interface with documentation
pkg/ui/tui.go Implemented Close method to quit the program if it exists
cmd/main.go Added UI cleanup call in REPL function with error logging


func (u *TUI) Close() error {
if u.program != nil {
u.program.Quit()
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The Quit() method may not immediately stop the program and could leave resources in an inconsistent state. Consider using Kill() instead for more forceful termination, or check if the program is still running after Quit() and handle accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@noahlwest noahlwest left a comment

Choose a reason for hiding this comment

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

Hey, I cloned this pr to manually test and I wasn't able to get it to work in a way that would close #439. To close 439, I would expect exit or quit to take me out of the terminal. I also tried with --ui-type tui since I see you have changes in tui, and still had the same non-closing behavior. I'll attach demos to this comment.

I made #453 before I saw this pr, though it closes the terminal on exit or quit, it does not clean up any resources like your PR does. Mike brought up a good point on that PR about adding a regression test since we've run into this problem more than once.

I think the changes in this PR are still good and help us follow best practices, I just didn't see the behavior I expected. If you could possibly demo the behavior that #439 expects, then feel free to resolve/ignore this.

terminal: https://github.com/user-attachments/assets/2a90f00a-ae50-4292-a453-7ad207950a86
tui: https://github.com/user-attachments/assets/820143c7-791a-4cc7-a69b-f651a190d224

func (u *TUI) ClearScreen() {
}

func (u *TUI) Close() error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(this may be out of scope of this pr, feel free to resolve or ignore if it is): Do we need a function like this to clean up web ui resources too? If we do, but it's out of scope for this pr, we can make an issue requesting it in a later pr.

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.

[Bug]: exit doesn't exit

2 participants