Skip to content

Commit

Permalink
Added the display after EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
noborus committed Mar 29, 2020
1 parent a312dfd commit 231761e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ It supports various compressed files(gzip, bzip2, zstd, lz4, and xz).
return nil
}

if config.Debug {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
oviewer.Debug = config.Debug
root := oviewer.New()
m := root.Model
Expand Down Expand Up @@ -111,9 +114,7 @@ func initConfig() {
viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
//fmt.Println("Using config file:", viper.ConfigFileUsed())
}
viper.ReadInConfig()

if err := viper.Unmarshal(&config); err != nil {
fmt.Println(err)
Expand Down
33 changes: 33 additions & 0 deletions draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oviewer

import (
"fmt"
"strings"

"github.com/gdamore/tcell"
"github.com/mattn/go-runewidth"
Expand Down Expand Up @@ -40,6 +41,7 @@ func (root *root) Draw() {
searchWord = root.input
}

// Header
lY := 0
lX := 0
hy := 0
Expand All @@ -60,10 +62,17 @@ func (root *root) Draw() {
hy++
}

// Body
lX = m.yy * m.vWidth
for y := root.HeaderLen(); y < m.vHight; y++ {
contents := m.getContents(m.lineNum + lY)
if contents == nil {
// EOF
contents = strToContents("~", 0)
contents[0].style = contents[0].style.Foreground(tcell.ColorGray)
}
if len(contents) == 0 {
// blank line
lY++
continue
}
Expand Down Expand Up @@ -127,6 +136,30 @@ func (root *root) noWrapContents(y int, lX int, lY int, contents []content) (rX
return lX, lY
}

func doReverse(cp *[]content, searchWord string) {
contents := *cp
for n := range contents {
contents[n].style = contents[n].style.Normal()
}
if searchWord == "" {
return
}
s, cIndex := contentsToStr(contents)
for i := strings.Index(s, searchWord); i >= 0; {
start := cIndex[i]
end := cIndex[i+len(searchWord)]
for ci := start; ci < end; ci++ {
contents[ci].style = contents[ci].style.Reverse(true)
}
j := strings.Index(s[i+1:], searchWord)
if j >= 0 {
i += j + 1
} else {
break
}
}
}

func (root *root) statusDraw() {
screen := root.Screen
style := tcell.StyleDefault
Expand Down
25 changes: 0 additions & 25 deletions oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"os"
"os/signal"
"strings"
"syscall"

"github.com/dgraph-io/ristretto"
Expand Down Expand Up @@ -97,30 +96,6 @@ func contentsToStr(contents []content) (string, map[int]int) {
return s, cIndex
}

func doReverse(cp *[]content, searchWord string) {
contents := *cp
for n := range contents {
contents[n].style = contents[n].style.Reverse(false)
}
if searchWord == "" {
return
}
s, cIndex := contentsToStr(contents)
for i := strings.Index(s, searchWord); i >= 0; {
start := cIndex[i]
end := cIndex[i+len(searchWord)]
for ci := start; ci < end; ci++ {
contents[ci].style = contents[ci].style.Reverse(true)
}
j := strings.Index(s[i+1:], searchWord)
if j >= 0 {
i += j + 1
} else {
break
}
}
}

func (root *root) setContentString(vx int, vy int, contents []content, style tcell.Style) {
screen := root.Screen
for x, content := range contents {
Expand Down

0 comments on commit 231761e

Please sign in to comment.