Skip to content
Open
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
5 changes: 5 additions & 0 deletions translator/bat2cat/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func handleShortFlags(arg string, args []string, i int, result *[]string, skipNe
} else {
// Flags without direct mapping or bat-specific flags
switch flag {
case 'v':
// -v (display non-printing as ^X / M-x) — approximated with --show-all
// and caret notation. Note: bat also visualizes spaces/newlines which
// cat -v does not, but this is the closest available approximation.
*result = append(*result, "--show-all", "--nonprintable-notation=caret")
case 'p':
// -p (plain) is already added by default, ignore
case 'l', 'H', 'm':
Expand Down
22 changes: 22 additions & 0 deletions translator/bat2cat/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ func TestTranslateFlags(t *testing.T) {
expected: []string{"-p", "--paging=never", "--color=auto", "-u", "file.txt"},
},

// Show non-printing (approximate: also shows spaces/newlines)
{
name: "show non-printing",
input: []string{"-v", "file.txt"},
expected: []string{"-p", "--paging=never", "--color=auto", "--show-all", "--nonprintable-notation=caret", "file.txt"},
},

// Combined flags
{
name: "combined flags",
Expand All @@ -81,6 +88,21 @@ func TestTranslateFlags(t *testing.T) {
input: []string{"-nsu", "file.txt"},
expected: []string{"-p", "--paging=never", "--color=auto", "-n", "-s", "-u", "file.txt"},
},
{
name: "non-printing with line numbers",
input: []string{"-vn", "file.txt"},
expected: []string{"-p", "--paging=never", "--color=auto", "--show-all", "--nonprintable-notation=caret", "-n", "file.txt"},
},
{
name: "non-printing with squeeze and unbuffered",
input: []string{"-vsu", "file.txt"},
expected: []string{"-p", "--paging=never", "--color=auto", "--show-all", "--nonprintable-notation=caret", "-s", "-u", "file.txt"},
},
{
name: "non-printing as separate flag with others",
input: []string{"-n", "-v", "-s", "file.txt"},
expected: []string{"-p", "--paging=never", "--color=auto", "-n", "--show-all", "--nonprintable-notation=caret", "-s", "file.txt"},
},

// bat-specific flags that are ignored or overridden
{
Expand Down
Loading