summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-08-28 21:23:10 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-08-28 21:23:10 +0900
commit90b0cd44ac8fb9a6965c3dcf050f0e6aa2e90121 (patch)
tree2d1f49202779dfbcf797e3b7290f077f1b19bfe5 /src
parent698e8008df42d863af01a8da81f560f295f728ea (diff)
Should not strip ANSI codes when --ansi is not set
Diffstat (limited to 'src')
-rw-r--r--src/core.go4
-rw-r--r--src/item.go14
-rw-r--r--src/terminal.go8
3 files changed, 16 insertions, 10 deletions
diff --git a/src/core.go b/src/core.go
index fdd1e061..4f072151 100644
--- a/src/core.go
+++ b/src/core.go
@@ -174,7 +174,7 @@ func Run(opts *Options) {
chunks: snapshot,
pattern: pattern})
for i := 0; i < merger.Length(); i++ {
- fmt.Println(merger.Get(i).AsString())
+ fmt.Println(merger.Get(i).AsString(opts.Ansi))
}
}
os.Exit(0)
@@ -250,7 +250,7 @@ func Run(opts *Options) {
fmt.Println()
}
for i := 0; i < count; i++ {
- fmt.Println(val.Get(i).AsString())
+ fmt.Println(val.Get(i).AsString(opts.Ansi))
}
os.Exit(0)
}
diff --git a/src/item.go b/src/item.go
index 2ab8a78c..12ca3dfb 100644
--- a/src/item.go
+++ b/src/item.go
@@ -94,15 +94,19 @@ func (item *Item) Rank(cache bool) Rank {
}
// AsString returns the original string
-func (item *Item) AsString() string {
- return *item.StringPtr()
+func (item *Item) AsString(stripAnsi bool) string {
+ return *item.StringPtr(stripAnsi)
}
// StringPtr returns the pointer to the original string
-func (item *Item) StringPtr() *string {
+func (item *Item) StringPtr(stripAnsi bool) *string {
if item.origText != nil {
- trimmed, _, _ := extractColor(string(*item.origText), nil)
- return &trimmed
+ if stripAnsi {
+ trimmed, _, _ := extractColor(string(*item.origText), nil)
+ return &trimmed
+ }
+ orig := string(*item.origText)
+ return &orig
}
str := string(item.text)
return &str
diff --git a/src/terminal.go b/src/terminal.go
index aca319a1..053ed783 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -42,6 +42,7 @@ type Terminal struct {
history *History
cycle bool
header []string
+ ansi bool
margin [4]string
marginInt [4]int
count int
@@ -207,6 +208,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
marginInt: [4]int{0, 0, 0, 0},
cycle: opts.Cycle,
header: opts.Header,
+ ansi: opts.Ansi,
reading: true,
merger: EmptyMerger,
selected: make(map[uint32]selectedItem),
@@ -288,7 +290,7 @@ func (t *Terminal) output() {
if len(t.selected) == 0 {
cnt := t.merger.Length()
if cnt > 0 && cnt > t.cy {
- fmt.Println(t.merger.Get(t.cy).AsString())
+ fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
}
} else {
sels := make([]selectedItem, 0, len(t.selected))
@@ -805,7 +807,7 @@ func (t *Terminal) Loop() {
}
selectItem := func(item *Item) bool {
if _, found := t.selected[item.index]; !found {
- t.selected[item.index] = selectedItem{time.Now(), item.StringPtr()}
+ t.selected[item.index] = selectedItem{time.Now(), item.StringPtr(t.ansi)}
return true
}
return false
@@ -843,7 +845,7 @@ func (t *Terminal) Loop() {
case actExecute:
if t.cy >= 0 && t.cy < t.merger.Length() {
item := t.merger.Get(t.cy)
- executeCommand(t.execmap[mapkey], item.AsString())
+ executeCommand(t.execmap[mapkey], item.AsString(t.ansi))
}
case actInvalid:
t.mutex.Unlock()