feat: support live-reload tui when file is changed#68
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how the application manages configuration by replacing lifetime parameters with shared ownership via Rc to support live-reload functionality. Key changes include:
- Removing explicit lifetime annotations in UI and tree-related modules in favor of Rc-based configuration.
- Updating constructors and method calls across multiple files to clone Rc as needed.
- Adjusting configuration access in data rendering and parser invocations to accommodate the new Rc usage.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/ui/tree_overview.rs | Removed lifetime parameters and adjusted constructors to accept Rc. |
| src/ui/popup.rs | Updated Popup to use Rc instead of borrowed references. |
| src/ui/header.rs | Changed Header to operate with Rc; consider revisiting unnecessary cloning. |
| src/ui/footer.rs | Refactored Footer to accept Rc. |
| src/ui/data_block.rs | Updated DataBlock to work with Rc and modified data rendering accordingly. |
| src/ui/app.rs | Updated App to utilize Rc across components and adjusted Edit initialization. |
| src/tree.rs | Modified tree parsing and conversion to support Rc usage. |
| src/main.rs | Initialized configuration as Rc and propagated it to the application components. |
Files not reviewed (1)
- src/live_reload.rs: Language not supported
Comments suppressed due to low confidence (1)
src/ui/header.rs:55
- [nitpick] The explicit cfg.clone() may be redundant since cfg is already an Rc; consider using cfg.header.format directly to simplify the code.
let header_format = &cfg.clone().header.format;
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for live-reloading the TUI when the underlying file is changed. It refactors the UI modules to use shared configuration via Rc, integrates a new live_reload module with a FileWatcher, and updates the application logic to reload the tree upon file updates.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/ui/tree_overview.rs | Replaces lifetime parameters with Rc and updates tree reload logic. |
| src/ui/popup.rs | Converts configuration reference to Rc. |
| src/ui/header.rs | Updates header construction to use a cloned Rc. |
| src/ui/footer.rs | Refactors to use Rc instead of lifetimes. |
| src/ui/data_block.rs | Updates configuration handling and rendering to adopt Rc. |
| src/ui/app.rs | Integrates FileWatcher into the app, adjusts refresh logic, and renames copy message to foot_message. |
| src/tree.rs | Removes lifetime annotations and propagates Rc usage in tree parsing. |
| src/main.rs | Adjusts config usage with Rc, integrates live_reload, and passes FileWatcher to App. |
| src/live_reload.rs | Introduces file watching functionality using the notify crate and updates live-reload behavior. |
| src/debug.rs | Minor update to ensure logs include a newline. |
| src/cmd.rs | Adds command-line support for live reloading. |
| Cargo.toml | Adds the notify crate as a dependency. |
| data_lock.set_data(s); | ||
| drop(data_lock); | ||
| } | ||
| EventKind::Remove(_) => bail!("the file {} was removed by user", path.display()), |
There was a problem hiding this comment.
Handling file removal by bailing out of the watcher thread may interrupt live-reload functionality unexpectedly. Consider handling file removal gracefully (for example, by notifying the user and optionally attempting to re-establish the watcher) rather than exiting the watcher thread.
| EventKind::Remove(_) => bail!("the file {} was removed by user", path.display()), | |
| EventKind::Remove(_) => { | |
| debug!("the file {} was removed by user, attempting to re-watch", path.display()); | |
| watcher.watch(&path, RecursiveMode::NonRecursive)?; | |
| }, |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [ubi:fioncat/otree](https://github.com/fioncat/otree) | minor | `0.3.1` -> `0.4.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>fioncat/otree (ubi:fioncat/otree)</summary> ### [`v0.4.0`](https://github.com/fioncat/otree/releases/tag/v0.4.0) [Compare Source](fioncat/otree@v0.3.1...v0.4.0) ##### Features - Command: Add new flag `--debug`, to write some debug logs to a file. - UI: Add `--live-reload` option, to watch file changes and update tui ([#​63](fioncat/otree#63)). - Release: Add Windows prebuilt binary (**unstable**, require more testing). #### What's Changed - feat(cmd): support `--debug` flag to write debug logs by [@​fioncat](https://github.com/fioncat) in fioncat/otree#67 - feat: support live-reload tui when file is changed by [@​fioncat](https://github.com/fioncat) in fioncat/otree#68 **Full Changelog**: fioncat/otree@v0.3.1...v0.4.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC4zMi43IiwidXBkYXRlZEluVmVyIjoiNDAuMzIuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
No description provided.