Skip to content

Commit e04c233

Browse files
committed
add default config for IPC
1 parent 54e6d3f commit e04c233

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/bin/ctl/commands.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ pub enum ModeAction {
220220
Toggle { name: String },
221221
}
222222

223+
#[derive(Debug, Clone, Subcommand)]
224+
pub enum ConfigAction {
225+
/// Print a commented-out default config to stdout
226+
Default,
227+
}
228+
223229
#[derive(Debug, Clone, Subcommand)]
224230
pub enum CommandKind {
225231
Action {
@@ -290,6 +296,10 @@ pub enum CommandKind {
290296
Wallpaper {
291297
path: String,
292298
},
299+
Config {
300+
#[command(subcommand)]
301+
action: ConfigAction,
302+
},
293303
}
294304

295305
#[derive(Debug, Parser)]
@@ -509,5 +519,6 @@ pub fn command_to_ipc(command: CommandKind) -> IpcCommand {
509519
}
510520
CommandKind::Wallpaper { path } => IpcCommand::Wallpaper(path),
511521
CommandKind::UpdateStatus { text } => IpcCommand::UpdateStatus(text),
522+
CommandKind::Config { .. } => unreachable!("config is handled locally"),
512523
}
513524
}

src/bin/instantwmctl.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ fn main() {
191191
let cli = Cli::parse();
192192

193193
let command = match &cli.command {
194+
ctl::CommandKind::Config { action } => {
195+
match action {
196+
ctl::commands::ConfigAction::Default => {
197+
println!(
198+
"{}",
199+
instantwm::config::config_toml::generate_commented_config()
200+
);
201+
}
202+
}
203+
return;
204+
}
194205
ctl::CommandKind::Action { name, args, list } => {
195206
if *list {
196207
let actions = instantwm::config::keybind_config::get_actions_for_ipc();

src/config/config_toml.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,48 @@ pub fn load_config_file() -> ThemeConfig {
258258
}
259259
}
260260

261+
/// Generate a commented-out default config template.
262+
///
263+
/// All settings are commented out so that:
264+
/// - Users can see what options are available
265+
/// - Defaults are not baked in, so they track upstream changes
266+
pub fn generate_commented_config() -> String {
267+
let config = ThemeConfig::default();
268+
let full = toml::to_string_pretty(&config).expect("failed to serialize default config");
269+
270+
let mut out = String::new();
271+
out.push_str("# instantWM configuration\n");
272+
out.push_str("#\n");
273+
out.push_str(
274+
"# This file is optional. instantWM uses sensible defaults when no config exists.\n",
275+
);
276+
out.push_str("# Uncomment and modify any section below to override defaults.\n");
277+
out.push_str("#\n");
278+
out.push_str("# Config changes are applied on reload (instantwmctl reload).\n");
279+
out.push_str("#\n");
280+
out.push_str(
281+
"# Use `instantwm --print-config` to see the full default config with all values.\n",
282+
);
283+
out.push_str("# Use `instantwm --list-actions` to see valid action names for keybinds.\n");
284+
out.push_str("#\n\n");
285+
286+
for line in full.lines() {
287+
if line.trim().is_empty() {
288+
out.push('\n');
289+
} else if line.starts_with('[') {
290+
out.push_str("# ");
291+
out.push_str(line);
292+
out.push('\n');
293+
} else {
294+
out.push_str("# ");
295+
out.push_str(line);
296+
out.push('\n');
297+
}
298+
}
299+
300+
out
301+
}
302+
261303
fn load_and_merge_config(path: &Path, visited: &mut HashSet<PathBuf>) -> Result<toml::Value, ()> {
262304
let canonical_path = path.canonicalize().map_err(|e| {
263305
eprintln!("instantwm: could not canonicalize path {:?}: {e}", path);

0 commit comments

Comments
 (0)