Skip to content

Commit df56911

Browse files
GokceGKjoaopaletvicentepinto98
authored
Add custom pager handling (#299)
* add custom pager handling * ignore linter temporarily * change condition * add debug line * add debug log * add pager infos to README * Update README.md Co-authored-by: João Palet <joao.palet@outlook.com> * edit README.md * edit README.md * Update README.md Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Update README.md Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> --------- Co-authored-by: João Palet <joao.palet@outlook.com> Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>
1 parent c39e245 commit df56911

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,33 @@ stackit config list
130130

131131
You can also edit the configuration file manually.
132132

133+
## Customization
134+
135+
### Pager
136+
137+
To specify a custom pager, use the `PAGER` environment variable.
138+
139+
If the variable is not set, STACKIT CLI uses the `less` as default pager.
140+
141+
When using `less` as a pager, STACKIT CLI will automatically pass following options
142+
- -F, --quit-if-one-screen - Less will automatically exit if the entire file can be displayed on the first screen.
143+
- -S, --chop-long-lines - Lines longer than the screen width will be chopped rather than being folded.
144+
- -w, --hilite-unread - Temporarily highlights the first "new" line after a forward movement of a full page.
145+
- -R, --RAW-CONTROL-CHARS - ANSI color and style sequences will be interpreted.
146+
147+
> These options will not be added automatically if a custom pager is defined.
148+
>
149+
> In that case, users can define the parameters by using the specific environment variable required by the `PAGER` (if supported).
150+
151+
>
152+
> For example, if user sets the `PAGER` environment variable to `less` and would like to pass some arguments, `LESS` environment variable must be used as following:
153+
154+
>
155+
> export PAGER="less"
156+
>
157+
> export LESS="-R"
158+
159+
133160
## Autocompletion
134161

135162
If you wish to set up command autocompletion in your shell for the STACKIT CLI, please refer to our [autocompletion guide](./AUTOCOMPLETION.md).

internal/pkg/print/print.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,15 @@ func (p *Printer) PagerDisplay(content string) error {
180180
// -R: interprets ANSI color and style sequences
181181
pagerCmd := exec.Command("less", "-F", "-S", "-w", "-R")
182182

183+
pager, pagerExists := os.LookupEnv("PAGER")
184+
if pagerExists && pager != "nil" && pager != "" {
185+
pagerCmd = exec.Command(pager) // #nosec G204
186+
}
187+
183188
pagerCmd.Stdin = strings.NewReader(content)
184189
pagerCmd.Stdout = p.Cmd.OutOrStdout()
185190

191+
p.Debug(DebugLevel, "using pager: %s", pagerCmd.Args[0])
186192
err := pagerCmd.Run()
187193
if err != nil {
188194
p.Debug(ErrorLevel, "run pager command: %v", err)

0 commit comments

Comments
 (0)