From 744dd321ce2f18bd7a3256644c3098acb6ece72b Mon Sep 17 00:00:00 2001 From: Seven Tella <7onetella@gmail.com> Date: Thu, 27 Feb 2020 04:06:18 -0500 Subject: [PATCH] updating color scheme to give better visual cues --- command.go | 30 +++++++++++++++--------------- help.go | 46 ++++++++++++++++++++++++++-------------------- indexer.go | 15 ++++++++++----- model_base.go | 2 +- model_custom.go | 14 ++++++++++---- search.go | 5 +++-- simpleapp.go | 2 +- 7 files changed, 66 insertions(+), 48 deletions(-) diff --git a/command.go b/command.go index 4ea6afa..062ce98 100644 --- a/command.go +++ b/command.go @@ -42,7 +42,7 @@ func (s *Search) HandleCommand(command string) { } tokens := strings.Split(str, ".") if len(tokens) == 1 { - s.App.StatusBar.SetText("[red]please specify file extension[white]") + s.App.StatusBar.SetText("[red:white]please specify file extension[white]") return } @@ -79,30 +79,30 @@ func (s *Search) HandleCommand(command string) { err = OpenFileIfNoneExist(markdownFilePath, markdown) if err != nil { - s.App.StatusBar.SetText("[red]generating content: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]generating content: " + err.Error() + "[white]") return } OpenVim(s.App, markdownFilePath) - s.App.StatusBar.SetText("[yellow]content generated[white]") + s.App.StatusBar.SetText("[white:darkcyan]content generated[white]") // convert content to pdf if the extension is pdf if extension == "pdf" { // does pandoc exist in path? if !DoesBinaryExists("pandoc") { - s.App.StatusBar.SetText("[red]please install pandoc to generate pdf[white]") + s.App.StatusBar.SetText("[red:white]please install pandoc to generate pdf[white]") return } pdfFiePath := generatedDocPath + filename + ".pdf" err := Exec([]string{"pandoc", "-s", markdownFilePath, "-o", pdfFiePath}) if err != nil { - s.App.StatusBar.SetText("[red]generating pdf: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]generating pdf: " + err.Error() + "[white]") return } - s.App.StatusBar.SetText("[yellow]pdf generated[white]") + s.App.StatusBar.SetText("[white:darkcyan]pdf generated[white]") err = Exec([]string{"open", pdfFiePath}) if err != nil { - s.App.StatusBar.SetText("[red]opening pdf: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]opening pdf: " + err.Error() + "[white]") return } @@ -113,7 +113,7 @@ func (s *Search) HandleCommand(command string) { err = Exec([]string{"open", markdownFilePath}) if err != nil { - s.App.StatusBar.SetText("[red]opening content: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]opening content: " + err.Error() + "[white]") return } @@ -135,7 +135,7 @@ func (s *Search) HandleCommand(command string) { s.SelectRow(0) s.App.SetFocus(s.SearchBar) - s.App.StatusBar.SetText("[white]listing docs by type " + doctype) + s.App.StatusBar.SetText("[white:darkcyan]listing docs by type '" + doctype + "'") case "tag": tags := terms[1:] for i := 0; i < s.ResultList.GetRowCount(); i++ { @@ -206,7 +206,7 @@ func (s *Search) HandleCommand(command string) { } tokens := strings.Split(str, ".") if len(tokens) == 1 { - s.App.StatusBar.SetText("[red]please specify file extension[white]") + s.App.StatusBar.SetText("[red:white]please specify file extension[white]") return } @@ -244,14 +244,14 @@ func (s *Search) HandleCommand(command string) { err = OpenFileIfNoneExist(backupFilePath, content) if err != nil { - s.App.StatusBar.SetText("[red]exporting content: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]exporting content: " + err.Error() + "[white]") return } - s.App.StatusBar.SetText("[yellow]exporting done[white]") + s.App.StatusBar.SetText("[white:darkcyan]exporting done[white]") err = Exec([]string{"open", backupFilePath}) if err != nil { - s.App.StatusBar.SetText("[red]opening exported: " + err.Error() + "[white]") + s.App.StatusBar.SetText("[red:white]opening exported: " + err.Error() + "[white]") return } case "import": @@ -265,7 +265,7 @@ func (s *Search) HandleCommand(command string) { generatedDocPath := home + config.Config().GetString("generated_doc_path") tokens := strings.Split(str, ".") if len(tokens) == 1 { - s.App.StatusBar.SetText("[red]please specify file extension[white]") + s.App.StatusBar.SetText("[red:white]please specify file extension[white]") return } @@ -304,7 +304,7 @@ func (s *Search) HandleCommand(command string) { doc.SetID(0) s.App.DataHandler.Write(doc) } - s.App.StatusBar.SetText("[yellow]importing done[white]") + s.App.StatusBar.SetText("[white:darkcyan]importing done[white]") } } diff --git a/help.go b/help.go index a182caf..5ce4090 100644 --- a/help.go +++ b/help.go @@ -26,39 +26,45 @@ func (h *Help) SetApp(app *SimpleApp) { func (h *Help) Page() (title string, content tview.Primitive) { fmt.Fprintf(h.Content, ` + [white:darkcyan][List of shortcut keys for the following scope[][white] - [yellow]List of shortcut keys for the following scope[white] + [black:darkcyan][Entire App[][white] - [darkcyan]Entire App[white] - - Ctrl-C <- Exit - Ctrl-N <- New note - Ctrl-H <- Navigate to left menu item - Ctrl-L <- Navigate to right menu item - Ctrl-O <- Show debug view - Ctrl-D <- Go to debug view and back - Ctrl-E <- Clear debug view + Ctrl-c <- Exit + Ctrl-n <- New note + Ctrl-h <- Navigate to left menu item + Ctrl-l <- Navigate to right menu item + Ctrl-o <- Show debug view + Ctrl-d <- Go to debug view and back + Ctrl-e <- Clear debug view Tab <- Switch between various views - [darkcyan]Search Bar[white] + [black:darkcyan][Search Bar[][white] - Ctrl-U <- Delete the entire line. - Ctrl-A <- Move to the beginning of the line. - Ctrl-E <- Move to the end of the line. + Ctrl-n <- New note + Ctrl-Space <- Delete the entire line. + Ctrl-u <- Delete the entire line. + Ctrl-a <- Move to the beginning of the line. + Ctrl-e <- Move to the end of the line. Alt-left, Alt-b <- Move left by one word. Alt-right, Alt-f <- Move right by one word. - Ctrl-K <- Delete from the cursor to the end of the line. - Ctrl-W <- Delete the last word before the cursor. + Ctrl-k <- Delete from the cursor to the end of the line. + Ctrl-w <- Delete the last word before the cursor. - [darkcyan]Search Result Rows[white] + [black:darkcyan][Search Result Rows[][white] + Tab <- Go back to search bar j <- Move down k <- Move up i <- Load currently selected row in the edit view + e <- Edit vim editable fields, e.g. note + t <- Toggle toggle-able field spacebar <- Select row - Ctrl-D <- Batch delete selected rows - Tab <- Go back to search bar - + Ctrl-j <- Move row down + Ctrl-k <- Move row up + Ctrl-d <- Batch delete selected rows + Ctrl-a <- Select all / Deselect all + Ctrl-t <- Toggle all / Detoggle all `) return "Help", h.Content } diff --git a/indexer.go b/indexer.go index 0f76d1e..ba25ef9 100644 --- a/indexer.go +++ b/indexer.go @@ -111,7 +111,7 @@ func (ih *IndexHandler) Search(queryString string) ([]MiniDoc, string) { log.Errorf("index search error: %v", err) return nil, "" } - stat := fmt.Sprintf("%d matches, showing %d through %d, took %s\n", sr.Total, sr.Request.From+1, sr.Request.From+len(sr.Hits), sr.Took) + stat := fmt.Sprintf(" %d matches, showing %d through %d, took %s\n", sr.Total, sr.Request.From+1, sr.Request.From+len(sr.Hits), sr.Took) docs := make([]MiniDoc, sr.Hits.Len()) for ri, hit := range sr.Hits { @@ -135,8 +135,8 @@ func (ih *IndexHandler) Search(queryString string) ([]MiniDoc, string) { } log.Debug("# of fragments: " + strconv.Itoa(len(hit.Fragments))) - for _, fragments := range hit.Fragments { - rv := "" + for fieldName, fragments := range hit.Fragments { + rv := "[" + fieldName + "[] " for _, fragment := range fragments { // [43m [0m fragment = strings.ReplaceAll(fragment, "[43m", "[yellow]") @@ -167,7 +167,7 @@ func IndexMapping() (*mapping.IndexMappingImpl, error) { indexMapping := bleve.NewIndexMapping() for _, doctype := range doctypes { - documentMapping := DocumentMapping(indexedFields[doctype]) + documentMapping := DocumentMapping(indexedFields[doctype], excludedFields[doctype]) indexMapping.AddDocumentMapping(doctype, documentMapping) } indexMapping.TypeField = "type" @@ -176,7 +176,7 @@ func IndexMapping() (*mapping.IndexMappingImpl, error) { return indexMapping, nil } -func DocumentMapping(indexedFields []string) *mapping.DocumentMapping { +func DocumentMapping(indexedFields []string, excludedFields []string) *mapping.DocumentMapping { englishTextFieldMapping := bleve.NewTextFieldMapping() englishTextFieldMapping.Analyzer = en.AnalyzerName @@ -185,5 +185,10 @@ func DocumentMapping(indexedFields []string) *mapping.DocumentMapping { documentMapping.AddFieldMappingsAt(f, englishTextFieldMapping) } + disabledFieldMapping := bleve.NewDocumentDisabledMapping() + for _, f := range excludedFields { + documentMapping.AddSubDocumentMapping(f, disabledFieldMapping) + } + return documentMapping } diff --git a/model_base.go b/model_base.go index 66a387d..f7c2ac3 100644 --- a/model_base.go +++ b/model_base.go @@ -121,7 +121,7 @@ func (m *BaseDoc) GetMarkdown() string { } func (M *BaseDoc) GetAvailableActions() string { - return "😊" + return "*" } func (m *BaseDoc) GetDisplayFields() []string { diff --git a/model_custom.go b/model_custom.go index 23dacec..e569e9e 100644 --- a/model_custom.go +++ b/model_custom.go @@ -6,7 +6,7 @@ import ( "strings" ) -var doctypes = []string{"url", "note", "todo"} +var doctypes = []string{"url", "note", "todo", "shortcut"} var indexedFields = map[string][]string{ "url": {"title", "description", "tags"}, @@ -14,6 +14,12 @@ var indexedFields = map[string][]string{ "todo": {"task", "done", "tags"}, } +var excludedFields = map[string][]string{ + "url": {"url"}, + "note": {}, + "todo": {}, +} + // -------------------------------------------------------------------------------- // URL Doc // -------------------------------------------------------------------------------- @@ -45,7 +51,7 @@ func (d *URLDoc) HandleEvent(event *tcell.EventKey) { } func (d *URLDoc) GetAvailableActions() string { - return "[yellow]o[white]pen url in browser | [yellow]t[white]oggle watch later" + return "o <- open url in browser | t <- toggle watch later" } func (d *URLDoc) GetMarkdown() string { @@ -114,7 +120,7 @@ func (d *NoteDoc) GetDisplayFields() []string { } func (d *NoteDoc) GetAvailableActions() string { - return "" + return "*" } func (d *NoteDoc) GetEditFields() []string { @@ -181,7 +187,7 @@ func (d *ToDoDoc) HandleEvent(event *tcell.EventKey) { } func (d *ToDoDoc) GetAvailableActions() string { - return "[yellow]t[white] <= toggle done" + return "t <- toggle done" } func (d *ToDoDoc) GetMarkdown() string { diff --git a/search.go b/search.go index 5246561..9e40e65 100644 --- a/search.go +++ b/search.go @@ -190,7 +190,7 @@ func (s *Search) Search(searchby string) bool { s.debug("result is empty") return false } - s.App.StatusBar.SetText(stat) + s.App.StatusBar.SetText("[white:darkcyan]" + stat + "[white]") s.UpdateResult(result) return false @@ -295,6 +295,7 @@ func (s *Search) GoToSearchBar(clear bool) { s.SearchBar.Clear(true) s.InitSearchBar() } + s.App.StatusBar.SetText("[white:darkcyan] Ctrl-h <- navigate left | Ctrl-l <- navigate right[white]") s.App.Draw() s.App.SetFocus(s.SearchBar) } @@ -342,7 +343,7 @@ func (s *Search) Preview(direction int) { // move keys like j and k controls the selection // result list select only makes sense for shifting the focus over and selecting - s.App.StatusBar.SetText(fmt.Sprintf("%d | %s", s.CurrentRowIndex, doc.GetAvailableActions())) + s.App.StatusBar.SetText(fmt.Sprintf("[white:darkcyan] t <- toogle | spacebar <- select | %s | row %d", doc.GetAvailableActions(), s.CurrentRowIndex)) json := JsonMapFrom(doc) jh := NewJsonMapWrapper(json) diff --git a/simpleapp.go b/simpleapp.go index 67ab94f..e2ea856 100644 --- a/simpleapp.go +++ b/simpleapp.go @@ -108,7 +108,7 @@ func NewSimpleApp(opts ...SimpleAppOption) *SimpleApp { false, } - status.SetText("Ctrl-L for help") + status.SetText("[white:darkcyan] Ctrl-h <- navigate left | Ctrl-l <- navigate right[white]") app.DebugView = NewDebugView(app) app.Rows = tview.NewFlex().SetDirection(tview.FlexRow).