mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-07 05:25:21 +02:00
feat(cli): new layout-ratios command
The implementation adds a new layout-ratio CLI command to komorebi that allows users to dynamically set column and row ratios for layouts at runtime via komorebic layout-ratio --columns 0.3 0.4 --rows 0.5. A public validate_ratios function was added to komorebi-layouts that clamps ratio values between 0.1 and 0.9, truncates when the cumulative sum would reach or exceed 1.0, and limits to a maximum of 5 ratios. This function is shared between config file deserialization and the new CLI command, ensuring consistent validation behavior. The SocketMessage enum in komorebi/src/core/mod.rs has a new LayoutRatios variant. The handler in process_command.rs uses the shared validate_ratios function to process the ratios before applying them to the focused workspace's layout options. When the CLI command is called without any arguments, it prints a helpful message instead of returning an error.
This commit is contained in:
@@ -1001,6 +1001,16 @@ struct ScrollingLayoutColumns {
|
||||
count: NonZeroUsize,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct LayoutRatios {
|
||||
/// Column width ratios (space-separated values between 0.1 and 0.9)
|
||||
#[clap(short, long, num_args = 1..)]
|
||||
columns: Option<Vec<f32>>,
|
||||
/// Row height ratios (space-separated values between 0.1 and 0.9)
|
||||
#[clap(short, long, num_args = 1..)]
|
||||
rows: Option<Vec<f32>>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct License {
|
||||
/// Email address associated with an Individual Commercial Use License
|
||||
@@ -1267,6 +1277,8 @@ enum SubCommand {
|
||||
/// Set the number of visible columns for the Scrolling layout on the focused workspace
|
||||
#[clap(arg_required_else_help = true)]
|
||||
ScrollingLayoutColumns(ScrollingLayoutColumns),
|
||||
/// Set the layout column and row ratios for the focused workspace
|
||||
LayoutRatios(LayoutRatios),
|
||||
/// Load a custom layout from file for the focused workspace
|
||||
#[clap(hide = true)]
|
||||
#[clap(arg_required_else_help = true)]
|
||||
@@ -2934,6 +2946,15 @@ if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) {
|
||||
SubCommand::ScrollingLayoutColumns(args) => {
|
||||
send_message(&SocketMessage::ScrollingLayoutColumns(args.count))?;
|
||||
}
|
||||
SubCommand::LayoutRatios(args) => {
|
||||
if args.columns.is_none() && args.rows.is_none() {
|
||||
println!(
|
||||
"No ratios provided, nothing to change. Use --columns or --rows to specify ratios."
|
||||
);
|
||||
} else {
|
||||
send_message(&SocketMessage::LayoutRatios(args.columns, args.rows))?;
|
||||
}
|
||||
}
|
||||
SubCommand::LoadCustomLayout(args) => {
|
||||
send_message(&SocketMessage::ChangeLayoutCustom(args.path))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user