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

ehc: Improve PAGER selection #570

Merged
merged 2 commits into from
Feb 18, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ To transition the selected issue from the TUI, press `m`.
The `view` command lets you see issue details in a terminal. Atlassian document is roughly converted to a markdown
and is nicely displayed in the terminal.

The command uses `less` as a pager by default. To set your own pager, see https://github.com/ankitpokhrel/jira-cli/discussions/569.

```sh
$ jira issue view ISSUE-1
```
Expand Down
9 changes: 7 additions & 2 deletions pkg/tui/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ func GetPager() string {
if IsDumbTerminal() {
return "cat"
}
pager := os.Getenv("PAGER")
pager := os.Getenv("JIRA_PAGER")
if pager == "" {
pager = "less"
pgr := os.Getenv("PAGER")
if pgr == "" {
pager = "less"
} else {
pager = pgr
}
}
return pager
}
Expand Down
65 changes: 32 additions & 33 deletions pkg/tui/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package tui

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestColumnPadding(t *testing.T) {
t.Parallel()

cases := []struct {
name string
input string
Expand Down Expand Up @@ -46,6 +47,8 @@ func TestColumnPadding(t *testing.T) {
}

func TestSplitText(t *testing.T) {
t.Parallel()

cases := []struct {
name string
input string
Expand Down Expand Up @@ -87,62 +90,58 @@ func TestSplitText(t *testing.T) {
}

func TestGetPager(t *testing.T) {
t.Parallel()

term := os.Getenv("TERM")
pager := os.Getenv("PAGER")

// TERM is xterm, PAGER is set.
// TERM is xterm, JIRA_PAGER is not set, PAGER is set.
{
_ = os.Setenv("TERM", "xterm")
t.Setenv("TERM", "xterm")

_ = os.Setenv("PAGER", "")
t.Setenv("PAGER", "")
assert.Equal(t, "less", GetPager())

_ = os.Setenv("PAGER", "more")
t.Setenv("PAGER", "more")
assert.Equal(t, "more", GetPager())

_ = os.Setenv("PAGER", pager)
t.Setenv("PAGER", "")
}

// TERM is set, PAGER is unset.
// TERM is set, JIRA_PAGER is not set, PAGER is unset.
{
_ = os.Unsetenv("PAGER")

_ = os.Setenv("TERM", "dumb")
t.Setenv("TERM", "dumb")
assert.Equal(t, "cat", GetPager())

_ = os.Setenv("TERM", "")
t.Setenv("TERM", "")
assert.Equal(t, "cat", GetPager())

_ = os.Setenv("TERM", "xterm")
t.Setenv("TERM", "xterm")
assert.Equal(t, "less", GetPager())

_ = os.Setenv("TERM", term)
}

// TERM gets precedence if both PAGER and TERM are set.
// TERM is set, JIRA_PAGER is set, PAGER is unset.
{
_ = os.Setenv("PAGER", "")
_ = os.Setenv("TERM", "")
t.Setenv("JIRA_PAGER", "bat")

t.Setenv("TERM", "dumb")
assert.Equal(t, "cat", GetPager())

_ = os.Setenv("PAGER", "more")
_ = os.Setenv("TERM", "dumb")
t.Setenv("TERM", "")
assert.Equal(t, "cat", GetPager())

_ = os.Setenv("PAGER", "more")
_ = os.Setenv("TERM", "xterm")
assert.Equal(t, "more", GetPager())
t.Setenv("TERM", "xterm")
assert.Equal(t, "bat", GetPager())
}

// TERM and PAGER are not set.
// TERM gets precedence if both PAGER and TERM are set.
{
_ = os.Unsetenv("PAGER")
_ = os.Unsetenv("TERM")
t.Setenv("TERM", "")
t.Setenv("PAGER", "")
t.Setenv("JIRA_PAGER", "")
assert.Equal(t, "cat", GetPager())
}

_ = os.Setenv("TERM", term)
_ = os.Setenv("PAGER", pager)
t.Setenv("PAGER", "more")
t.Setenv("TERM", "dumb")
assert.Equal(t, "cat", GetPager())

t.Setenv("PAGER", "more")
t.Setenv("TERM", "xterm")
assert.Equal(t, "more", GetPager())
}
}