Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added Terminal User Interface (TUI) for Sugar #165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akshayw1
Copy link

Pull Request description

This PR adds a new Terminal User Interface (TUI) for Sugar, providing a visual and interactive way to manage containers directly from the terminal. The design was inspired by k9s for Kubernetes and aims to make Sugar's functionality more accessible through an intuitive interface.

Solves #42

How to test these changes

  • Install the package in development mode: pip install -e .
  • Run the TUI: sugar tui
  • Navigate between screens using keyboard shortcuts shown in the footer
  • Test different screens:
    • Main dashboard (default view)
    • Profile management screen (press p)
    • Services management screen (press s)
    • Logs viewer (press l)
  • Test auto-refresh and following logs in the logs screen
  • Test filtering in the logs screen

I have added screenshots demonstrating UI and functionality.
image
image
image
image

Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more complexity.
  • New and old tests passed locally.

Additional information

Currently, the TUI uses mock data for development and demonstration purposes. Integration with the actual Sugar backend will be implemented in future updates.

The new TUI features include:

  • Dashboard for overview of profiles and services
  • Profile management screen with detailed configuration view
  • Services management with status and control capabilities
  • Real-time log viewer with filtering and auto-refresh functionality
  • Clean dark UI theme with consistent styling across screens

Implement a TUI for Sugar using the Textual library to provide a visual and
interactive way to manage containers. The interface includes:

- Dashboard for overview of profiles and services
- Profile management screen with detailed configuration view
- Services management with status and control capabilities
- Real-time log viewer with filtering and auto-refresh functionality
- Clean dark UI theme with consistent styling across screens

Currently uses mock data for development and demonstration purposes.
Integration with the Sugar backend will be implemented in future updates.

This feature allows users to manage their containers with a more intuitive
interface directly from the terminal, similar to k9s for Kubernetes.
@akshayw1
Copy link
Author

@xmnlab Please review

@sanjay7178
Copy link
Contributor

sanjay7178 commented Mar 10, 2025

Hey @akshayw1 , Ivan is planning to make stats.py ( ie .. there is a extra is available under poetry install named tui) to integrate into tui command , might be useful to you , kindly check it

@@ -7,6 +7,8 @@
from sugar.extensions.base import SugarBase
from sugar.extensions.compose import SugarCompose
from sugar.extensions.compose_ext import SugarComposeExt
from sugar.extensions.tui import TUIExtension # Add this import
Copy link
Member

Choose a reason for hiding this comment

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

Please don't add unnecessary comments

Copy link
Member

@xmnlab xmnlab left a comment

Choose a reason for hiding this comment

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

@akshayw1 , thanks for working on that.

I added a few comments here, but I realized that there are a bunch of small issues, so please fix that first and ping me again for a new round of review.

from sugar.extensions.base import SugarBase


class TUIExtension(SugarBase):
Copy link
Member

Choose a reason for hiding this comment

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

Please, rename it to SugarTUI

print("Starting Sugar TUI...")
try:
from sugar.tui.app import run
print("Successfully imported run function")
Copy link
Member

Choose a reason for hiding this comment

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

avoid using prints inside the code.

@docparams({}) # Empty dict since we don't have parameters
def _cmd_tui(self) -> None:
"""Launch the Sugar Terminal User Interface."""
print("Starting Sugar TUI...")
Copy link
Member

Choose a reason for hiding this comment

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

avoid using prints inside the code.

run()
print("TUI has completed") # This will only print if run() completes/exits
except Exception as e:
print(f"Error launching TUI: {e}")
Copy link
Member

Choose a reason for hiding this comment

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

instead of using print, please use the proper method from logs.py

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.

3 participants