-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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(tui): persistent preferences #9512
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -730,6 +761,7 @@ fn cleanup<B: Backend + io::Write>( | |||
)?; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chris-olszewski, this was smart. Kudos.
crates/turborepo-ui/src/tui/mod.rs
Outdated
@@ -36,4 +37,6 @@ pub enum Error { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to do:
#[error("Unable to persist preferences")] | |
#[error("Unable to persist preferences. Please file a bug report.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LFG
@@ -262,8 +262,9 @@ impl Run { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just borrow here instead of cloning
let repo_root = self.repo_root.clone(); | |
let repo_root = &self.repo_root; |
@@ -126,6 +131,18 @@ impl<W> App<W> { | |||
}) | |||
} | |||
|
|||
fn update_sidebar_toggle(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.json
so 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
turbo
invocations, pick out tasks, and see the state persist across invocations. You also should be able to delete the.turbo/preferences/tui.json
file 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.