-
-
Notifications
You must be signed in to change notification settings - Fork 588
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
Custom Styles #1785
Custom Styles #1785
Conversation
Just as an extra note if this is agreed as an approach, next steps would presumably be
|
atuin-client/src/settings.rs
Outdated
@@ -303,6 +304,107 @@ impl Default for Stats { | |||
} | |||
} | |||
|
|||
#[derive(Clone, Debug, Default, Deserialize)] | |||
pub struct Styles { |
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 know this isn't the only thing here, but would you be open to the following
- Split settings into a module
- Break the style stuff into it's own file
Don't worry about the rest for now, but settings.rs
is getting fairly unwieldy now imo!
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.
Yeah, settings.rs
is a bit on the chunky side, and another hundred lines hasn't helped, clearly. When you say another module, are you thinking about a settings.rs
as a root, containing only top-level construction-type code and then a settings/
dir containing things like styles.rs
for example? That probably wouldn't be too much work I think, and I could probably do that as part of this PR as housekeeping.
If you are thinking about a bit of a crate re-org, how would you see it looking longer term? As far as I can tell at the moment, Settings
is only actually created (new()
) within atuin
generally anyway, and then passed to client, etc. I wonder whether having the root type for Settings
be part of atuin
and then having atuin-client
specific settings be defined in atuin-client
and composed as part of the root settings type (and then passed back to atuin-client
) might be a better long-term way? That way each component (client, and any future components) only get passed the config that's relevant to them, avoiding dependencies on things they don't care about, while still being able to have a single config management point. Just thinking out loud though at the moment.
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.
When you say another module, are you thinking about a settings.rs as a root, containing only top-level construction-type code and then a settings/ dir containing things like styles.rs for example?
Exactly that!
And yes, the re-org I was considering is more-or-less what you say. However, I'd also like to break all "history" specific stuff out into an atuin-history
crate. Then, we can make the main atuin
binary just connect a few things together. Kinda like atuin-config
.
Still a bit of a fuzzy idea though, and I'd like to see how other things shake out first. I'd also like to consider moving to KDL for config.
(gone way beyond the scope of this PR now, but just context setting)
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.
That makes sense, I'll have a quick play around and see how dramatic it would be to include that in this set of changes. Just taking the struct members out shouldn't mean any changes to consumers, if we wanted to group some of the current settings into new types (e.g. paths) then code consumers would need updating and that might get quite extensive (shouldn't have a problem with the config file itself if new structs are serde flattened). Will see how it looks!
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 mean the settings module rather than a re-org! That can wait...)
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.
Ok, I've started playing with a bit of a settings refactor, which can be seen in the latest commit. What I've done for now...
- Pulled groups of settings out into submodules of settings with vaguely sensible names (I hope) and any specialized types where relevant
- Re-exported those types from the original settings module, to avoid needing to change other code
What I've also done for one of those sets of properties (the display
submodule) is to pull the properties into a new settings type at that submodule level, as well as a function for setting defaults for that submodule on the ConfigBuilder
instance. I've then replaced the raw properties on settings with the new settings type, but with a serde
attribute to flatten the type, so the structure of the actual config file is unchanged. That obviously does need some changes elsewhere, so those changes are reflected wherever there is now a ".display
" included in a settings path.
The new submodule settings type is a potential option, just to see how well that fits in. I don't have any strong opinions on that one, see what you think and whether it's worth the slight extra code.
I like this approach, thank you! Just a few comments, nothing major though |
Oh one other thought It would be neat if we could also style the UI beyond colours this way. Like the differences between compact/full EG [styles.search_box]
border = none
etc that way, full/compact could just be presets. Not at all required for this PR though |
Yeah it would. It would be a bit of an expansion - at the moment the contents of styles maps basically 1-1 to the Ratatui type, and if you started to include a more general concept of style it would be more of a theme than a set of styles, but I agree that would be a good direction. I'll have a think about that one - it may be that something like |
atuin-client/src/settings/display.rs
Outdated
// Settings | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct Settings { |
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 is the new settings type mentioned...
atuin-client/src/settings/display.rs
Outdated
|
||
// Defaults | ||
|
||
pub(crate) fn defaults( |
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.
...along with a simple function to set defaults.
atuin-client/src/settings.rs
Outdated
pub word_chars: String, | ||
pub scroll_context_lines: usize, | ||
pub history_format: String, | ||
pub prefers_reduced_motion: bool, | ||
|
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 is where the new display settings type actual gets used, flattened, rather than having a set of properties here
atuin/src/command/client/search.rs
Outdated
@@ -158,7 +158,7 @@ impl Cmd { | |||
settings.filter_mode = self.filter_mode.unwrap(); | |||
} | |||
if self.inline_height.is_some() { | |||
settings.inline_height = self.inline_height.unwrap(); | |||
settings.display.inline_height = self.inline_height.unwrap(); |
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.
Any display settings are now a level deeper because of the new settings type, even though it's not visible externally in config.
um ok what github? Could you reopen this please, but use a branch that is not main? It behaves very strangely in terms of permissions. The rebased code is here: https://github.com/atuinsh/atuin/tree/kolektiv/styles I could open the PR, but would rather it be credited to you of course. tldr is that GitHub allows me to push to your branch, if you open a PR. I rebased this locally, pushed, and it just overwrote your main with the current main 🙃 ffs. I also now don't have permission to sort this out, as the PR was auto-closed and cannot be reopened. Sorry about that 😭 |
Otherwise - thanks for sorting this out. I'm pretty happy with the approach here! I'm a little unsure on the submodule The only other thing I'd like, is to ensure that a variety of already existing config files still load OK. This doesn't necessarily need to be done here, as we have broken this a few times in the past. So perhaps a wider issue of config testing |
Hah, I'm glad it's not only me that regularly gets tripped up by GitHub when it decides to be "helpful". No problem, what I'll do is grab that branch in my fork and work on there, and see where we end up. I'll go through and add in a "complete" (hopefully) set of styles. I'm also not 100% sure on the submodules I had a look at KDL incidentally, as you mentioned it somewhere above - I'd not come across it before. Interesting. My only personal pain from that is that all my config is generated by nix, and I don't think it can generate KDL at the moment, but that's clearly a pretty selfish reason not to do it if it makes sense! |
Sorry for the ping everyone but any advancements on this initiative @kolektiv? Excited about it! |
Yes, I'm going to try and pick it back up this weekend! I ended up travelling at short notice, so I'll put something together from here 🙂 |
Hi, I added some more styling options and merged with the main branch in my fork. As this feature still requires some work and is now entangled with the settings refactoring, should we split the settings refactoring part into its own PR? |
If they are not mutually dependent on each other I'd love if the custom styles could be merged even if settings refactoring is not complete. Thanks for all the work. |
(Recreated PR!)
As mentioned in #1153 - I've had a quick little play at a simple way for people to set styles. I've tried to make it fairly minimal rather than introduce a whole theme system or something similar. Some things to note:
styles
table in the config. I've currently implemented support for two styles, just as a proof - the command in the history list, and the selected command in the history list. They can be set something like the following (obviously, compact table notation is also fine):Here's how that particular configuration looks in my terminal (using the compact style).
Opinions/objections are welcome. Obviously, a couple of slight structural tweaks are needed, but I've tried to avoid anything too invasive.
Checks