Skip to content

Commit

Permalink
[Search Git Status] use box drawing chars for diff type header (#291)
Browse files Browse the repository at this point in the history
Make the header box for Git staged/unstaged/merged/etc. look nicer.
Old:
+--------+
| Staged |
+--------+
New:
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Staged โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
  • Loading branch information
yogan authored Jan 25, 2023
1 parent 039a86d commit 63c8f8e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions functions/_fzf_report_diff_type.fish
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# helper for _fzf_preview_changed_file
# prints out something like
# +--------+
# | Staged |
# +--------+
# โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
# โ”‚ Staged โ”‚
# โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
function _fzf_report_diff_type --argument-names diff_type --description "Print a distinct colored header meant to preface a git patch."
# number of "-" to draw is the length of the string to box + 2 for padding
set repeat_count (math 2 + (string length $diff_type))
set horizontal_border +(string repeat --count $repeat_count -)+
set line (string repeat --count $repeat_count โ”€)
set top_border โ•ญ$lineโ•ฎ
set btm_border โ•ฐ$lineโ•ฏ

set_color yellow
echo $horizontal_border
echo "| $diff_type |"
echo $horizontal_border
echo $top_border
echo "โ”‚ $diff_type โ”‚"
echo $btm_border
set_color normal
end
2 changes: 1 addition & 1 deletion tests/preview_changed_file/deleted_in_working.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mock git diff "echo \$argv"
set output (_fzf_preview_changed_file " D out.log")

contains "| Unstaged |" $output && not contains "| Staged |" $output
contains "โ”‚ Unstaged โ”‚" $output && not contains "โ”‚ Staged โ”‚" $output
@test "only shows unstaged changes if file was only deleted in working tree" $status -eq 0
2 changes: 1 addition & 1 deletion tests/preview_changed_file/merge_conflict.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mock git diff "echo \$argv"
set output (_fzf_preview_changed_file "UU out.log")

@test "shows merge conflicts as unmerged" $output[2] = "| Unmerged |"
@test "shows merge conflicts as unmerged" $output[2] = "โ”‚ Unmerged โ”‚"
2 changes: 1 addition & 1 deletion tests/preview_changed_file/modified_in_both.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mock git diff "echo \$argv"
set output (_fzf_preview_changed_file "MM dir/file.txt")

contains "| Unstaged |" $output && contains "| Staged |" $output
contains "โ”‚ Unstaged โ”‚" $output && contains "โ”‚ Staged โ”‚" $output
@test "shows staged and unstaged changes if the file is modified in both places" $status -eq 0

0 comments on commit 63c8f8e

Please sign in to comment.