feat(tui): persistent preferences - #9512
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| - [Repositories to test with](#repositories-to-test-with) | ||
| - [Debugging tips](#debugging-tips) | ||
| - [Verbose logging](#verbose-logging) | ||
| - [Verbose logging](#verbose-logging) |
| )?; | ||
| let tasks_started = app.tasks_by_status.tasks_started(); | ||
| app.persist_tasks(tasks_started)?; | ||
| app.preferences.flush_to_disk().ok(); |
There was a problem hiding this comment.
@chris-olszewski, this was smart. Kudos.
| Stdin { name: String, e: std::io::Error }, | ||
| #[error(transparent)] | ||
| Io(#[from] std::io::Error), | ||
| #[error("Unable to persist preferences")] |
There was a problem hiding this comment.
Would it make sense to do:
| #[error("Unable to persist preferences")] | |
| #[error("Unable to persist preferences. Please file a bug report.")] |
|
|
||
| let (sender, receiver) = TuiSender::new(); | ||
| let color_config = self.color_config; | ||
| let repo_root = self.repo_root.clone(); |
There was a problem hiding this comment.
We can just borrow here instead of cloning
| let repo_root = self.repo_root.clone(); | |
| let repo_root = &self.repo_root; |
| }) | ||
| } | ||
|
|
||
| fn update_sidebar_toggle(&mut self) { |
There was a problem hiding this comment.
I feel like toggle implies an update, up to you if this is better name 🤷
| fn update_sidebar_toggle(&mut self) { | |
| fn toggle_sidebar(&mut self) { |
| pub fn set_active_task(&mut self, value: Option<String>) -> Result<(), Error> { | ||
| self.config.active_task = value; | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
No need to lie to the caller that this could fail. We can propagate this change up to callers that now no longer need to handle the error case.
| pub fn set_active_task(&mut self, value: Option<String>) -> Result<(), Error> { | |
| self.config.active_task = value; | |
| Ok(()) | |
| } | |
| pub fn set_active_task(&mut self, value: Option<String>) { | |
| self.config.active_task = value; | |
| } |
| loader | ||
| .file_path | ||
| .ensure_dir() | ||
| .expect("Failed to create directory"); | ||
|
|
||
| let preferences = Preferences { | ||
| active_task: Some("web#dev".to_owned()), | ||
| is_task_list_visible: Some(false), | ||
| }; | ||
|
|
||
| loader | ||
| .file_path | ||
| .create_with_contents( | ||
| serde_json::to_string_pretty(&preferences) | ||
| .expect("Failed to serialize preferences"), | ||
| ) | ||
| .expect("Failed to create file"); |
There was a problem hiding this comment.
I think it would be fine to use the methods instead of creating the file manually
| loader | |
| .file_path | |
| .ensure_dir() | |
| .expect("Failed to create directory"); | |
| let preferences = Preferences { | |
| active_task: Some("web#dev".to_owned()), | |
| is_task_list_visible: Some(false), | |
| }; | |
| loader | |
| .file_path | |
| .create_with_contents( | |
| serde_json::to_string_pretty(&preferences) | |
| .expect("Failed to serialize preferences"), | |
| ) | |
| .expect("Failed to create file"); | |
| loader.set_is_task_list_visible(Some(false)); | |
| loader.set_active_task(Some("web#dev".to_owned())); | |
| loader.flush_to_disk().expect("failed to create file); |
| loader | ||
| .file_path | ||
| .ensure_dir() | ||
| .expect("Failed to create directory"); | ||
|
|
||
| let preferences = Preferences { | ||
| active_task: Some("web#dev".to_owned()), | ||
| is_task_list_visible: Some(false), | ||
| }; | ||
|
|
||
| loader | ||
| .file_path | ||
| .create_with_contents( | ||
| serde_json::to_string_pretty(&preferences) | ||
| .expect("Failed to serialize preferences"), | ||
| ) | ||
| .expect("Failed to create file"); |
There was a problem hiding this comment.
Same feedback as above
| self.preferences.set_active_task( | ||
| self.is_task_selection_pinned | ||
| .then(|| active_task.to_owned()), | ||
| )?; |
There was a problem hiding this comment.
This isn't doing FS anymore so it shouldn't have a failure
| )?; | |
| ); |
| fn update_task_selection_pinned_state(&mut self) -> Result<(), Error> { | ||
| // Preferences assume a pinned state when there is an active task. | ||
| // This `None` creates "un-pinned-ness" on the next TUI startup. | ||
| self.preferences.set_active_task(None)?; | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
I find this name a little confusing. Does clear_pinned_task express the behavior better?
| fn update_task_selection_pinned_state(&mut self) -> Result<(), Error> { | |
| // Preferences assume a pinned state when there is an active task. | |
| // This `None` creates "un-pinned-ness" on the next TUI startup. | |
| self.preferences.set_active_task(None)?; | |
| Ok(()) | |
| } | |
| fn update_task_selection_pinned_state(&mut self) { | |
| // Preferences assume a pinned state when there is an active task. | |
| // This `None` creates "un-pinned-ness" on the next TUI startup. | |
| self.preferences.set_active_task(None); | |
| } |
Description
Users have expressed that they find themselves repeatedly having to select out the task that they want to use. This ends up being annoying when invoking
turbo, shutting down, invokingturbo, shutting down...You end up having to reselect the task you care about every re-invoke.To improve on this, we're going to hold some state in
.turbo/preferences/tui.jsonso that users pick up where they left off from their previous TUI invocation. State we'll keep around is:Testing Instructions
Wrote tests but you should also try it out by hand. You should be able to run
turboinvocations, pick out tasks, and see the state persist across invocations. You also should be able to delete the.turbo/preferences/tui.jsonfile and it'll feel like the first invocation (no preferences).Small note
One thing that I noticed while hand-testing is that this implementation tolerates extra fields fine, but doesn't tolerate the wrong types for a field. It will crash for in the latter scenario.
Personally, I think this is fine. You'd have to purposefully go and edit the file to get the wrong types into there.