From f69c684d1e533323c1c94ebbb9c61cec028462e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 28 May 2026 15:18:44 +0000 Subject: [PATCH 1/2] refactor(app): group chart-layout arguments of visualize_json_tree into a struct https://claude.ai/code/session_01KouQSeGxaEKUEvq8hf9jq6 --- src/app.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index f48e9870..a6f92803 100644 --- a/src/app.rs +++ b/src/app.rs @@ -41,6 +41,17 @@ struct JsonInputShaping { no_sort: bool, } +/// Geometry options that control how the chart is laid out. +#[derive(Clone, Copy)] +struct ChartLayout { + /// How the available width is distributed across the columns. + column_width_distribution: ColumnWidthDistribution, + /// Whether the tree grows from the top down or from the bottom up. + direction: Direction, + /// Whether the bars are aligned to the left or to the right. + bar_alignment: BarAlignment, +} + impl App { /// Initialize the application from the environment. pub fn from_env() -> Self { @@ -74,8 +85,11 @@ impl App { no_sort, .. } = self.args; - let direction = Direction::from_top_down(top_down); - let bar_alignment = BarAlignment::from_align_right(align_right); + let layout = ChartLayout { + column_width_distribution, + direction: Direction::from_top_down(top_down), + bar_alignment: BarAlignment::from_align_right(align_right), + }; let shaping = JsonInputShaping { max_depth: max_depth.get(), min_ratio: min_ratio.into(), @@ -91,12 +105,15 @@ impl App { fn visualize_json_tree( tree: JsonTree, bytes_format: Self::DisplayFormat, - column_width_distribution: ColumnWidthDistribution, - direction: Direction, - bar_alignment: BarAlignment, + layout: ChartLayout, shaping: JsonInputShaping, ) -> Result { let JsonTree { tree, shared } = tree; + let ChartLayout { + column_width_distribution, + direction, + bar_alignment, + } = layout; let JsonInputShaping { max_depth, min_ratio, @@ -140,14 +157,7 @@ impl App { macro_rules! visualize { ($tree:expr, $bytes_format:expr) => { - VisualizeJsonTree::visualize_json_tree( - $tree, - $bytes_format, - column_width_distribution, - direction, - bar_alignment, - shaping, - ) + VisualizeJsonTree::visualize_json_tree($tree, $bytes_format, layout, shaping) }; } From 1e8e710efd56b286810cbd74c281a8d4b8369353 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 28 May 2026 23:18:02 +0700 Subject: [PATCH 2/2] refactor: re-arrange --- src/app.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index a6f92803..58c6ff0f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -30,17 +30,6 @@ pub struct App { args: Args, } -/// Tree-shaping options applied to a deserialized `--json-input` tree before visualization. -#[derive(Clone, Copy)] -struct JsonInputShaping { - /// Maximum number of levels to display. - max_depth: u64, - /// Minimal size proportion required to appear. - min_ratio: f32, - /// Whether to preserve the input order of the entries. - no_sort: bool, -} - /// Geometry options that control how the chart is laid out. #[derive(Clone, Copy)] struct ChartLayout { @@ -52,6 +41,17 @@ struct ChartLayout { bar_alignment: BarAlignment, } +/// Tree-shaping options applied to a deserialized `--json-input` tree before visualization. +#[derive(Clone, Copy)] +struct JsonInputShaping { + /// Maximum number of levels to display. + max_depth: u64, + /// Minimal size proportion required to appear. + min_ratio: f32, + /// Whether to preserve the input order of the entries. + no_sort: bool, +} + impl App { /// Initialize the application from the environment. pub fn from_env() -> Self {