@@ -25,6 +25,7 @@ pub use self::preview::Preview;
2525pub use self :: proxy:: Proxy ;
2626pub use self :: server:: Server ;
2727pub use self :: sidebar:: Sidebar ;
28+ pub use self :: spacing:: Spacing ;
2829use crate :: appearance:: theme:: Styles ;
2930use crate :: appearance:: { self , Appearance } ;
3031use crate :: audio:: { self } ;
@@ -48,6 +49,7 @@ pub mod preview;
4849pub mod proxy;
4950pub mod server;
5051pub mod sidebar;
52+ pub mod spacing;
5153
5254const CONFIG_TEMPLATE : & str = include_str ! ( "../../config.toml" ) ;
5355const DEFAULT_THEME_NAME : & str = "ferra" ;
@@ -60,6 +62,7 @@ pub struct Config {
6062 pub proxy : Option < Proxy > ,
6163 pub font : Font ,
6264 pub scale_factor : ScaleFactor ,
65+ pub spacing : Spacing ,
6366 pub buffer : Buffer ,
6467 pub pane : Pane ,
6568 pub sidebar : Sidebar ,
@@ -312,6 +315,7 @@ impl Config {
312315 pub proxy : Option < Proxy > ,
313316 pub font : Font ,
314317 pub scale_factor : ScaleFactor ,
318+ pub spacing : Spacing ,
315319 pub buffer : Buffer ,
316320 pub pane : Pane ,
317321 pub sidebar : Sidebar ,
@@ -336,6 +340,7 @@ impl Config {
336340 proxy : None ,
337341 font : Font :: default ( ) ,
338342 scale_factor : ScaleFactor :: default ( ) ,
343+ spacing : Spacing :: default ( ) ,
339344 buffer : Buffer :: default ( ) ,
340345 pane : Pane :: default ( ) ,
341346 sidebar : Sidebar :: default ( ) ,
@@ -353,6 +358,62 @@ impl Config {
353358 }
354359 }
355360
361+ fn migrate_spacing_from_legacy (
362+ config : & mut Configuration ,
363+ raw_toml : & toml:: Value ,
364+ ) {
365+ if !toml_path_exists (
366+ raw_toml,
367+ & [ "spacing" , "buffer" , "line_spacing" ] ,
368+ ) && toml_path_exists ( raw_toml, & [ "buffer" , "line_spacing" ] )
369+ {
370+ config. spacing . buffer . line_spacing = config. buffer . line_spacing ;
371+ }
372+
373+ if !toml_path_exists ( raw_toml, & [ "spacing" , "pane" , "gap" , "inner" ] )
374+ && toml_path_exists ( raw_toml, & [ "pane" , "gap" , "inner" ] )
375+ {
376+ config. spacing . pane . gap . inner = config. pane . gap . inner ;
377+ }
378+ if !toml_path_exists ( raw_toml, & [ "spacing" , "pane" , "gap" , "outer" ] )
379+ && toml_path_exists ( raw_toml, & [ "pane" , "gap" , "outer" ] )
380+ {
381+ config. spacing . pane . gap . outer = config. pane . gap . outer ;
382+ }
383+
384+ if !toml_path_exists (
385+ raw_toml,
386+ & [ "spacing" , "sidebar" , "padding" , "buffer" ] ,
387+ ) && toml_path_exists (
388+ raw_toml,
389+ & [ "sidebar" , "padding" , "buffer" ] ,
390+ ) {
391+ config. spacing . sidebar . padding . buffer =
392+ config. sidebar . padding . buffer ;
393+ }
394+ if !toml_path_exists (
395+ raw_toml,
396+ & [ "spacing" , "sidebar" , "spacing" , "server" ] ,
397+ ) && toml_path_exists (
398+ raw_toml,
399+ & [ "sidebar" , "spacing" , "server" ] ,
400+ ) {
401+ config. spacing . sidebar . spacing . server =
402+ config. sidebar . spacing . server ;
403+ }
404+
405+ if !toml_path_exists (
406+ raw_toml,
407+ & [ "spacing" , "context_menu" , "padding" , "entry" ] ,
408+ ) && toml_path_exists (
409+ raw_toml,
410+ & [ "context_menu" , "padding" , "entry" ] ,
411+ ) {
412+ config. spacing . context_menu . padding . entry =
413+ config. context_menu . padding . entry ;
414+ }
415+ }
416+
356417 let path = Self :: path ( ) ;
357418 if !path. try_exists ( ) ? {
358419 return Err ( Error :: ConfigMissing ) ;
@@ -363,13 +424,25 @@ impl Config {
363424
364425 let config = toml:: Deserializer :: new ( content. as_ref ( ) ) ;
365426
427+ let mut configuration: Configuration =
428+ serde_ignored:: deserialize ( config, |ignored| {
429+ log:: warn!( "[config.toml] Ignoring unknown setting: {ignored}" ) ;
430+ } )
431+ . map_err ( |e| Error :: Parse ( e. to_string ( ) ) ) ?;
432+
433+ let raw_toml: toml:: Value = toml:: from_str ( content. as_ref ( ) )
434+ . map_err ( |e| Error :: Parse ( e. to_string ( ) ) ) ?;
435+
436+ migrate_spacing_from_legacy ( & mut configuration, & raw_toml) ;
437+
366438 let Configuration {
367439 theme,
368440 servers,
369441 context_menu,
370442 font,
371443 proxy,
372444 scale_factor,
445+ spacing,
373446 buffer,
374447 sidebar,
375448 keyboard,
@@ -383,10 +456,7 @@ impl Config {
383456 ctcp,
384457 logs,
385458 platform_specific,
386- } = serde_ignored:: deserialize ( config, |ignored| {
387- log:: warn!( "[config.toml] Ignoring unknown setting: {ignored}" ) ;
388- } )
389- . map_err ( |e| Error :: Parse ( e. to_string ( ) ) ) ?;
459+ } = configuration;
390460
391461 let servers = ServerMap :: new ( servers) . await ?;
392462
@@ -401,6 +471,7 @@ impl Config {
401471 font,
402472 proxy,
403473 scale_factor,
474+ spacing,
404475 buffer,
405476 sidebar,
406477 keyboard,
@@ -530,6 +601,23 @@ impl Config {
530601 }
531602}
532603
604+ fn toml_path_exists ( root : & toml:: Value , path : & [ & str ] ) -> bool {
605+ let mut current = root;
606+
607+ for key in path {
608+ let Some ( table) = current. as_table ( ) else {
609+ return false ;
610+ } ;
611+ let Some ( value) = table. get ( * key) else {
612+ return false ;
613+ } ;
614+
615+ current = value;
616+ }
617+
618+ true
619+ }
620+
533621pub fn random_nickname ( ) -> String {
534622 let mut rng = ChaCha8Rng :: from_rng ( & mut rand:: rng ( ) ) ;
535623 random_nickname_with_seed ( & mut rng)
0 commit comments