Skip to content

tui code clean up#89

Merged
ponbac merged 1 commit intomasterfrom
tui-cleanup
Feb 28, 2026
Merged

tui code clean up#89
ponbac merged 1 commit intomasterfrom
tui-cleanup

Conversation

@ponbac
Copy link
Owner

@ponbac ponbac commented Feb 26, 2026

Greptile Summary

This PR refactors the TUI codebase for significantly improved modularity and maintainability by extracting a 1500+ line main.rs into focused, single-responsibility modules.

Key architectural improvements:

  • Extracted event loop logic into runtime/ module with separate action handling and view management
  • Split monolithic API client into modular api/ directory with DTOs and dev backend separated
  • Created dedicated session_store module with secure file permissions for credential management
  • Introduced RAII TerminalGuard pattern for robust terminal cleanup on panic or early exit
  • Replaced manual CLI arg parsing with clap for better user experience
  • Added workspace-level dependency management for consistency across crates
  • Enhanced config module to support environment variable overrides

The refactoring maintains identical functionality while dramatically improving code organization, testability, and future maintainability.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • This is a well-executed refactoring that improves code organization without altering functionality. The changes follow Rust best practices including RAII patterns, proper error handling, and secure credential storage. All logic was carefully extracted into appropriate modules maintaining the same behavior.
  • No files require special attention

Important Files Changed

Filename Overview
toki-tui/src/main.rs Massive simplification from 1520+ lines to 115 lines by extracting logic into dedicated modules
toki-tui/src/runtime/event_loop.rs Clean event loop implementation with action queue for async operations
toki-tui/src/runtime/actions.rs Centralized action handling extracted from main event loop for better modularity
toki-tui/src/api/client.rs API client refactored from monolithic api_client.rs with automatic cookie syncing
toki-tui/src/session_store.rs New module for session management extracted from config with secure file permissions on Unix
toki-tui/src/terminal.rs RAII guard pattern ensures terminal cleanup on panic or early exit
toki-tui/src/bootstrap.rs App initialization logic extracted from main for cleaner separation of concerns
toki-tui/src/cli.rs Replaces manual arg parsing with clap-based CLI for better UX
toki-tui/src/config.rs Simplified by removing session management responsibilities, now supports environment variables
toki-tui/Cargo.toml Migrated to workspace dependencies and added clap for CLI parsing

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Start[main] --> ParseCLI[Parse CLI with clap]
    ParseCLI --> CheckCmd{Command?}
    
    CheckCmd -->|ConfigPath| ConfigPath[ensure_exists & print path]
    CheckCmd -->|Login| Login[run_login via OAuth]
    CheckCmd -->|Logout| Logout[clear session & cookies]
    CheckCmd -->|Dev| DevMode[run_dev_mode]
    CheckCmd -->|Run| RealMode[run_real_mode]
    
    DevMode --> CreateDevClient[Create DevBackend client]
    RealMode --> LoadSession[Load session from session_store]
    LoadSession --> CreateClient[Create ApiClient with session]
    
    CreateDevClient --> InitApp[run_ui]
    CreateClient --> CheckCookies{Milltime cookies exist?}
    CheckCookies -->|No| PromptAuth[prompt_milltime_authentication]
    CheckCookies -->|Yes| InitApp
    PromptAuth --> InitApp
    
    InitApp --> Bootstrap[bootstrap::initialize_app_state]
    Bootstrap --> LoadHistory[Fetch time entries]
    Bootstrap --> LoadProjects[Fetch projects]
    Bootstrap --> LoadTimer[Restore active timer]
    Bootstrap --> LoadTimeInfo[Fetch time info]
    
    LoadTimeInfo --> CreateTerminal[TerminalGuard::new]
    CreateTerminal --> EventLoop[runtime::run_app]
    
    EventLoop --> Poll[Poll events 100ms]
    Poll --> CheckEvent{Event?}
    CheckEvent -->|Key| HandleKey[handle_view_key]
    CheckEvent -->|None| CheckRefresh{60s elapsed?}
    
    HandleKey --> QueueAction[Enqueue Action]
    CheckRefresh -->|Yes| QueueRefresh[Queue RefreshHistoryBackground]
    CheckRefresh -->|No| ProcessQueue
    QueueAction --> ProcessQueue[Process action_rx queue]
    QueueRefresh --> ProcessQueue
    
    ProcessQueue --> RunAction[run_action]
    RunAction --> CheckQuit{app.running?}
    CheckQuit -->|Yes| Poll
    CheckQuit -->|No| Cleanup[TerminalGuard Drop cleanup]
    
    Cleanup --> End[Exit]
Loading

Last reviewed commit: 0d0aa06

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
toki2 Ready Ready Preview, Comment Feb 28, 2026 10:04am

Request Review

@ponbac
Copy link
Owner Author

ponbac commented Feb 26, 2026

@greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

40 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ponbac
Copy link
Owner Author

ponbac commented Feb 27, 2026

@greptile

@ponbac
Copy link
Owner Author

ponbac commented Feb 28, 2026

@greptile

@ponbac
Copy link
Owner Author

ponbac commented Feb 28, 2026

@codex

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f7191f14c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ponbac ponbac merged commit 95aaa51 into master Feb 28, 2026
6 checks passed
@ponbac ponbac deleted the tui-cleanup branch February 28, 2026 10:06
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.

1 participant