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

Introduce '--keep-ansi' option to keep ANSI codes on output #2693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func Run(opts *Options, version string, revision string) {
}
item.text, item.colors = ansiProcessor(data)
item.text.Index = itemIndex
item.origText = &data
itemIndex++
return true
})
Expand Down
3 changes: 3 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type Options struct {
Criteria []criterion
Multi int
Ansi bool
KeepAnsi bool
Mouse bool
Theme *tui.ColorTheme
Black bool
Expand Down Expand Up @@ -1633,6 +1634,8 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Multi = 0
case "--ansi":
opts.Ansi = true
case "--keep-ansi":
opts.KeepAnsi = true
case "--no-ansi":
opts.Ansi = false
case "--no-mouse":
Expand Down
7 changes: 5 additions & 2 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ type Terminal struct {
scrollbar string
previewScrollbar string
ansi bool
keepAnsi bool
tabstop int
margin [4]sizeSpec
padding [4]sizeSpec
Expand Down Expand Up @@ -631,6 +632,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
header0: opts.Header,
ellipsis: opts.Ellipsis,
ansi: opts.Ansi,
keepAnsi: opts.KeepAnsi,
tabstop: opts.Tabstop,
hasLoadActions: false,
triggerLoad: false,
Expand Down Expand Up @@ -985,16 +987,17 @@ func (t *Terminal) output() bool {
if len(t.expect) > 0 {
t.printer(t.pressed)
}
stripAnsi := t.ansi && (!t.keepAnsi)
found := len(t.selected) > 0
if !found {
current := t.currentItem()
if current != nil {
t.printer(current.AsString(t.ansi))
t.printer(current.AsString(stripAnsi))
found = true
}
} else {
for _, sel := range t.sortSelected() {
t.printer(sel.item.AsString(t.ansi))
t.printer(sel.item.AsString(stripAnsi))
}
}
return found
Expand Down