Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rvn0xsy committed Sep 20, 2021
1 parent 46555f4 commit 71670e5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ $ red-tldr upgrade
index-update = false
github-update = false
path = ""
color = true
```

| 配置项 | 描述 | 类型 |
| ----------- | ----------- | ----------- |
| index-update| 数据库索引文件是否自动更新 | Bool |
| github-update | 数据库文件是否从github自动更新 | Bool |
| path | 数据库文件存放路径 | string |
| path | 数据库文件存放路径 | String |
| color | 高亮输出命令 | Bool |



Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ Default configuration file path:`HOMEDIR/.red-tldr/config.toml`
index-update = false
github-update = false
path = ""
color = true
```


| Configuration item | Description | Type |
| ----------- | ----------- | ----------- |
| index-update| Whether the database index file is automatically updated | Bool |
| github-update | Whether the database file is automatically updated from github | Bool |
| path | Database file storage path | string |
| path | Database file storage path | String |
| color | Print highlight command | Bool |

## Contributing

Expand Down
1 change: 1 addition & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
index-update = false
github-update = false
path = ""
color = true
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module red-tldr
go 1.16

require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.1.0 // indirect
github.com/gookit/color v1.4.2
github.com/spf13/viper v1.8.1
gopkg.in/yaml.v2 v2.4.0
)
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand All @@ -140,6 +135,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
Expand Down Expand Up @@ -233,6 +230,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
50 changes: 46 additions & 4 deletions pkg/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ package pkg
import (
"encoding/json"
"fmt"
"github.com/spf13/viper"
yaml "gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"red-tldr/utils"
"strings"
"github.com/gookit/color"
)

var (
SearchDbDir = ""
SearchDbName = ""
)

func init() {
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(utils.GetConfigPath())
err := viper.ReadInConfig()
if err != nil {
utils.GenerateConfig()
}
}

func SetDbDir() {
SearchDbDir = utils.GetDatabasePath() + string(os.PathSeparator)
SearchDbName = utils.GetDatabaseFilePath()
Expand Down Expand Up @@ -65,16 +77,46 @@ func Search(file string,keyword string) {
}
}

func ShowHighLightData(Data * SearchDataStruct){
if viper.GetBool("red-tldr.color"){
// Color
color.Style{color.Red, color.OpBold}.Println(Data.Name)
lines := strings.Split(Data.Data,"\n")
printColor := false
for _,line := range lines{
if strings.HasPrefix(line,"```"){
if printColor {
printColor = false
continue
}else{
fmt.Println()
printColor = true
continue
}
}
if printColor {
color.Style{color.Green, color.OpBold}.Println(line)
// color.Green.Println(line)
continue
}
fmt.Println(line)
}
}else{
fmt.Println("=================")
fmt.Println(Data.Name)
fmt.Println("=================")
fmt.Println(Data.Data)
return
}
}

func ShowDetails(file SearchResultStruct) {
Data := new(SearchDataStruct)
yamlFile, err := ioutil.ReadFile(SearchDbDir+ utils.GetPathSeparator() + file.Filename)
utils.CheckErrorOnExit(err)
err = yaml.Unmarshal(yamlFile, Data)
utils.CheckErrorOnExit(err)
fmt.Println("=================")
fmt.Println(Data.Name)
fmt.Println("=================")
fmt.Println(Data.Data)
ShowHighLightData(Data)
}

func SelectOneResult(fileList []SearchResultStruct) {
Expand Down
2 changes: 1 addition & 1 deletion utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func GenerateConfig() {
viper.SetDefault("red-tldr.path",GetDatabasePath())
viper.SetDefault("red-tldr.index-update",false)
viper.SetDefault("red-tldr.github-update",false)

viper.SetDefault("red-tldr.color",true)
CheckErrorOnExit(viper.WriteConfigAs(GetConfigFilePath()))
log.Println("[Generate Config Success, Config File Path : ", GetConfigFilePath() ,"]")

Expand Down

0 comments on commit 71670e5

Please sign in to comment.