Skip to content

Commit 82b4a87

Browse files
committed
Add option to hide usage message
When the 'cmdheight` option is set to 0, printing the usage message triggers the "Press ENTER or type command to continue" prompt. Fixes #4
1 parent 8140e52 commit 82b4a87

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

doc/jj-diffconflicts.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,23 @@ g:jj_diffconflicts_jujutsu_version *g:jj_diffconflicts_jujutsu_version*
5656
binary is not desirable.
5757

5858
Example:
59-
`let g:jj_diffconflicts_jujutsu_version='0.17.1'`
59+
`vim.g.jj_diffconflicts_jujutsu_version="0.17.1"`
6060

6161
g:jj_diffconflicts_no_command *g:jj_diffconflicts_no_command*
6262

6363
Set this variable if you don't want the |:JJDiffConflicts| command to be
6464
automatically defined. When set, the main plugin function can instead be
6565
run with `require("jj-diffconflicts").run()`
6666

67+
g:jj_diffconflicts_show_usage_message *g:jj_diffconflicts_show_usage_message*
68+
69+
Set this variable to `false` to hide the usage message at start up.
70+
71+
Defaults to `true`.
72+
73+
Example:
74+
`vim.g.jj_diffconflicts_show_usage_message=false`
75+
6776

6877
Health check ~
6978

lua/jj-diffconflicts/init.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ M.run = function(show_history, marker_length)
5555
table.insert(conflicts, conflict)
5656
end
5757

58-
h.setup_ui(conflicts, show_history)
58+
local show_usage_message = vim.g.jj_diffconflicts_show_usage_message
59+
if show_usage_message == nil then
60+
show_usage_message = true
61+
end
62+
h.setup_ui(conflicts, show_history, show_usage_message)
5963
end
6064

6165
-- Return a table representing a software version that can be used as an
@@ -274,7 +278,7 @@ h.parse_conflict = function(patterns, raw_conflict)
274278
}
275279
end
276280

277-
h.setup_ui = function(conflicts, show_history)
281+
h.setup_ui = function(conflicts, show_history, show_usage_message)
278282
if show_history then
279283
-- Set up history view in a separate tab
280284
vim.cmd.tabnew()
@@ -287,13 +291,15 @@ h.setup_ui = function(conflicts, show_history)
287291

288292
-- Set up conflict resolution diff
289293
h.setup_diff_splits(conflicts)
294+
vim.cmd.redraw()
290295

291296
-- Display usage message
292-
vim.cmd.redraw()
293-
vim.notify(
294-
"Resolve conflicts leftward then save. Use :cq to abort.",
295-
vim.log.levels.WARN
296-
)
297+
if show_usage_message then
298+
vim.notify(
299+
"Resolve conflicts leftward then save. Use :cq to abort.",
300+
vim.log.levels.WARN
301+
)
302+
end
297303
end
298304

299305
-- Set up a two-way diff for conflict resolution.

tests/screenshots/no_usage_message

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--|---------|---------|---------|---------|---------|---------|---------|---------|
2+
01| X │ X
3+
02| X │ X
4+
03| X │ X
5+
04| apple │ APPLE
6+
05| grapefruit │ GRAPE
7+
06| orange │ ORANGE
8+
07| X │ X
9+
08| X │ X
10+
09| X │ X
11+
10|~ │~
12+
11|~ │~
13+
12|~ │~
14+
13|~ │~
15+
14|~ │~
16+
15|~ │~
17+
16|~ │~
18+
17|~ │~
19+
18|~ │~
20+
19|~ │~
21+
20|~ │~
22+
21|~ │~
23+
22|~ │~
24+
23|[No Name] [+] 4,1 All snapshot [RO] 4,1 All
25+
24|
26+
27+
--|---------|---------|---------|---------|---------|---------|---------|---------|
28+
01|00111111111111111111111111111111111111120011111111111111111111111111111111111111
29+
02|00111111111111111111111111111111111111120011111111111111111111111111111111111111
30+
03|00111111111111111111111111111111111111120011111111111111111111111111111111111111
31+
04|00333334444444444444444444444444444444420033333444444444444444444444444444444444
32+
05|00333333333344444444444444444444444444420033333444444444444444444444444444444444
33+
06|00333333444444444444444444444444444444420033333344444444444444444444444444444444
34+
07|00111111111111111111111111111111111111120011111111111111111111111111111111111111
35+
08|00111111111111111111111111111111111111120011111111111111111111111111111111111111
36+
09|00111111111111111111111111111111111111120011111111111111111111111111111111111111
37+
10|00000000000000000000000000000000000000020000000000000000000000000000000000000000
38+
11|00000000000000000000000000000000000000020000000000000000000000000000000000000000
39+
12|00000000000000000000000000000000000000020000000000000000000000000000000000000000
40+
13|00000000000000000000000000000000000000020000000000000000000000000000000000000000
41+
14|00000000000000000000000000000000000000020000000000000000000000000000000000000000
42+
15|00000000000000000000000000000000000000020000000000000000000000000000000000000000
43+
16|00000000000000000000000000000000000000020000000000000000000000000000000000000000
44+
17|00000000000000000000000000000000000000020000000000000000000000000000000000000000
45+
18|00000000000000000000000000000000000000020000000000000000000000000000000000000000
46+
19|00000000000000000000000000000000000000020000000000000000000000000000000000000000
47+
20|00000000000000000000000000000000000000020000000000000000000000000000000000000000
48+
21|00000000000000000000000000000000000000020000000000000000000000000000000000000000
49+
22|00000000000000000000000000000000000000020000000000000000000000000000000000000000
50+
23|55555555555555555555555555555555555555556666666666666666666666666666666666666666
51+
24|77777777777777777777777777777777777777777777777777777777777777777777777777777777

tests/test_jj_diffconflicts.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local SCREENSHOT = {
1515
long_markers = "tests/screenshots/long_markers_ui",
1616
multiple_conflicts = "tests/screenshots/multiple_conflicts_ui",
1717
missing_newline = "tests/screenshots/missing_newline_ui",
18+
no_usage_message = "tests/screenshots/no_usage_message",
1819
}
1920

2021
local T = MiniTest.new_set({
@@ -81,6 +82,12 @@ T["run"]["handles missing newlines conflicts"] = function()
8182
child.lua("jj.run(false, 7)")
8283
expect.reference_screenshot(child.get_screenshot(), SCREENSHOT.missing_newline)
8384
end
85+
T["run"]["hides usage message when g:jj_diffconflicts_show_usage_message is false"] = function()
86+
set_lines(read_file("tests/data/fruits.txt"))
87+
child.g.jj_diffconflicts_show_usage_message = false
88+
child.lua("jj.run(false, 7)")
89+
expect.reference_screenshot(child.get_screenshot(), SCREENSHOT.no_usage_message)
90+
end
8491

8592
T["history view"] = MiniTest.new_set()
8693
T["history view"]["displays UI"] = function()

0 commit comments

Comments
 (0)