Skip to content
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

Add configuration options for node symbols in the graphs #3263

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `ui.default-command` now accepts multiple string arguments, for more complex
default `jj` commands.

* Graph node symbols are now configurable via `ui.graph.default_node` and `ui.graph.elided_node`.

### Fixed bugs

## [0.15.1] - 2024-03-06
Expand Down
8 changes: 8 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
"ascii-large"
],
"default": "curved"
},
"default_node": {
"type": "string",
"description": "The symbol used as the default symbol for nodes."
},
"elided_node": {
"type": "string",
"description": "The symbol used for elided nodes."
}
}
},
Expand Down
27 changes: 22 additions & 5 deletions cli/src/graphlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,33 @@ pub fn get_graphlog<'a, K: Clone + Eq + Hash + 'a>(
) -> Box<dyn GraphLog<K> + 'a> {
let builder = GraphRowRenderer::new().output().with_min_row_height(0);

let (default_node_symbol, elided_node_symbol) = settings.node_symbols();

match settings.graph_style().as_str() {
"square" => SaplingGraphLog::create(
builder.build_box_drawing().with_square_glyphs(),
formatter,
"◉",
"◌",
&default_node_symbol,
&elided_node_symbol,
),
"ascii" => SaplingGraphLog::create(
builder.build_ascii(),
formatter,
&default_node_symbol,
&elided_node_symbol,
),
"ascii-large" => SaplingGraphLog::create(
builder.build_ascii_large(),
formatter,
&default_node_symbol,
&elided_node_symbol,
),
"ascii" => SaplingGraphLog::create(builder.build_ascii(), formatter, "o", "."),
"ascii-large" => SaplingGraphLog::create(builder.build_ascii_large(), formatter, "o", "."),
// "curved"
_ => SaplingGraphLog::create(builder.build_box_drawing(), formatter, "◉", "◌"),
_ => SaplingGraphLog::create(
builder.build_box_drawing(),
formatter,
&default_node_symbol,
&elided_node_symbol,
),
}
}
68 changes: 68 additions & 0 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,3 +1410,71 @@ fn test_elided() {
"###);
}

#[test]
fn test_custom_symbols() {
// Test that elided commits are shown as synthetic nodes.
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");

test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "main branch 1"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "main branch 2"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@--", "-m", "side branch 1"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "side branch 2"]);
test_env.jj_cmd_ok(
&repo_path,
&["new", "-m", "merge", r#"description("main branch 2")"#, "@"],
);

let get_log = |revs: &str| -> String {
test_env.jj_cmd_success(
&repo_path,
&["log", "-T", r#"description ++ "\n""#, "-r", revs],
)
};

// Simple test with showing default and elided nodes.
test_env.add_config(concat!(
"ui.log-synthetic-elided-nodes = true\n",
"ui.graph.default_node = '┝'\n",
"ui.graph.elided_node = '🮀'",
));
insta::assert_snapshot!(get_log("@ | @- | description(initial)"), @r###"
@ merge
├─╮
│ ┝ side branch 2
│ │
│ 🮀 (elided revisions)
┝ │ main branch 2
│ │
🮀 │ (elided revisions)
├─╯
┝ initial
~
"###);

// Simple test with showing default and elided nodes, ascii style.
test_env.add_config(concat!(
"ui.log-synthetic-elided-nodes = true\n",
"ui.graph.style = 'ascii'\n",
"ui.graph.default_node = '*'\n",
"ui.graph.elided_node = ':'",
));
insta::assert_snapshot!(get_log("@ | @- | description(initial)"), @r###"
@ merge
|\
| * side branch 2
| |
| : (elided revisions)
* | main branch 2
| |
: | (elided revisions)
|/
* initial
|
~
"###);
}
15 changes: 15 additions & 0 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ impl UserSettings {
.unwrap_or_else(|_| "curved".to_string())
}

pub fn node_symbols(&self) -> (String, String) {
let default_node_symbol = self.config.get_string("ui.graph.default_node");
let elided_node_symbol = self.config.get_string("ui.graph.elided_node");
match self.graph_style().as_str() {
"ascii" | "ascii-large" => (
default_node_symbol.unwrap_or("o".to_owned()),
elided_node_symbol.unwrap_or(".".to_owned()),
),
_ => (
default_node_symbol.unwrap_or("◉".to_owned()),
elided_node_symbol.unwrap_or("◌".to_owned()),
),
}
}

pub fn max_new_file_size(&self) -> Result<u64, config::ConfigError> {
let cfg = self
.config
Expand Down