Skip to content

refactor(program): use shared ownership and graceful signal shutdown - #29

Merged
rfprod merged 1 commit into
mainfrom
refactor-pointers
Nov 7, 2026
Merged

rfprod merged 1 commit into
mainfrom
refactor-pointers

Conversation

@rfprod

@rfprod rfprod commented Nov 7, 2026

Copy link
Copy Markdown
Owner
  • use std::shared_ptr for UserInterface, ProgressSpinner, and component ownership;
  • store the UserInterface singleton as std::weak_ptr, add create() factory overloads;
  • create UserInterface through create() and allocate components with std::make_shared;
  • initialize OllamaClient and its members through constructor initializer lists;
  • accept shared pointers in CurlUtils, EmbeddingUtils, RetrievingUtils, SystemUtils;
  • replace the SIGINT handler's direct exit with a graceful interrupt flag;
  • make resize and interrupt flags static volatile sig_atomic_t members;
  • add a terminal_restored flag and guard terminal cleanup against repeated calls;
  • prevent self-join in stop_render_thread;
  • add static ui_running() helper and use it for UI state checks in all components;
  • add a default exit code to end_session() and rename its parameter;
  • replace exit() calls with std::exit(EXIT_SUCCESS) or std::exit(EXIT_FAILURE);
  • return EXIT_SUCCESS from main and end UI sessions with EXIT_FAILURE on fatal errors;
  • hold CURL easy handles and header lists in unique_ptr with custom deleters;
  • add CurlUtils::add_header() to append headers to a curl_slist safely;
  • use reset() on owned CURL pointers in place of manual cleanup calls;
  • initialize WebContent::error_buffer with {} so it starts zeroed;
  • remove DEBUG-only theme logging from init_ncurses();
  • add doc comments for client, CurlUtils, EmbeddingUtils, and RetrievingUtils methods;
  • document fetch_web_content_stream() and fix the @throws note in fetch_web_content();
  • remove the is_running() note from catch_error() documentation;

- [x] use `std::shared_ptr` for `UserInterface`, `ProgressSpinner`, and component ownership;
- [x] store the `UserInterface` singleton as `std::weak_ptr`, add `create()` factory overloads;
- [x] create `UserInterface` through `create()` and allocate components with `std::make_shared`;
- [x] initialize `OllamaClient` and its members through constructor initializer lists;
- [x] accept shared pointers in `CurlUtils`, `EmbeddingUtils`, `RetrievingUtils`, `SystemUtils`;
- [x] replace the `SIGINT` handler's direct exit with a graceful interrupt flag;
- [x] make resize and interrupt flags static `volatile sig_atomic_t` members;
- [x] add a `terminal_restored` flag and guard terminal cleanup against repeated calls;
- [x] prevent self-join in `stop_render_thread`;
- [x] add static `ui_running()` helper and use it for UI state checks in all components;
- [x] add a default exit code to `end_session()` and rename its parameter;
- [x] replace `exit()` calls with `std::exit(EXIT_SUCCESS)` or `std::exit(EXIT_FAILURE)`;
- [x] return `EXIT_SUCCESS` from `main` and end UI sessions with `EXIT_FAILURE` on fatal errors;
- [x] hold CURL easy handles and header lists in `unique_ptr` with custom deleters;
- [x] add `CurlUtils::add_header()` to append headers to a `curl_slist` safely;
- [x] use `reset()` on owned CURL pointers in place of manual cleanup calls;
- [x] initialize `WebContent::error_buffer` with `{}` so it starts zeroed;
- [x] remove DEBUG-only theme logging from `init_ncurses()`;
- [x] add doc comments for client, `CurlUtils`, `EmbeddingUtils`, and `RetrievingUtils` methods;
- [x] document `fetch_web_content_stream()` and fix the `@throws` note in `fetch_web_content()`;
- [x] remove the `is_running()` note from `catch_error()` documentation;
@rfprod rfprod self-assigned this Nov 7, 2026
@rfprod rfprod added Documentation Improvements or additions to documentation. Refactor Refactoring related changes. Program Main program logic related changes. labels Nov 7, 2026
@rfprod
rfprod enabled auto-merge (squash) November 7, 2026 18:34
@rfprod
rfprod merged commit 7c14eae into main Nov 7, 2026
3 checks passed
@rfprod
rfprod deleted the refactor-pointers branch November 7, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation. Program Main program logic related changes. Refactor Refactoring related changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant