@@ -33,6 +33,8 @@ type Window struct {
3333 showHelp bool
3434 nArticles int
3535 nFeeds int
36+ askQuit bool
37+ currSearch string
3638}
3739
3840const (
@@ -223,8 +225,87 @@ func (w *Window) UpdateStatusTicker() {
223225 }()
224226}
225227
228+ // Search asks the user to input search query
229+ func (w * Window ) Search () {
230+ w .askQuit = true
231+ w .flexStatus .RemoveItem (w .status )
232+ w .currSearch = ""
233+
234+ inputField := tview .NewInputField ().
235+ SetLabel ("find: " ).
236+ SetFieldWidth (20 ).
237+ SetFieldBackgroundColor (tcell .ColorBlack )
238+
239+ capt := func (e * tcell.EventKey ) * tcell.EventKey {
240+ keyName := string (e .Name ())
241+ if strings .Contains (keyName , "Rune" ) {
242+ keyName = string (e .Rune ())
243+ }
244+
245+ if strings .EqualFold (keyName , "esc" ) {
246+ w .flexStatus .RemoveItem (inputField )
247+ w .flexStatus .AddItem (w .status , 1 , 1 , false )
248+ w .app .SetInputCapture (w .c .Input )
249+ w .app .SetFocus (w .articles )
250+ }
251+
252+ if strings .EqualFold (keyName , "enter" ) {
253+ w .flexStatus .RemoveItem (inputField )
254+ w .flexStatus .AddItem (w .status , 1 , 1 , false )
255+ w .app .SetInputCapture (w .c .Input )
256+ w .app .SetFocus (w .articles )
257+
258+ w .feeds .Select (2 , 0 )
259+ w .articles .Select (0 , 3 )
260+
261+ } else {
262+ w .currSearch += keyName
263+ }
264+
265+ return e
266+ }
267+ w .flexStatus .AddItem (inputField , 1 , 0 , false )
268+ w .app .SetFocus (inputField )
269+ w .app .SetInputCapture (capt )
270+ }
271+
272+ // AskQuit asks the user to quit or not.
273+ func (w * Window ) AskQuit () {
274+ w .askQuit = true
275+ w .flexStatus .RemoveItem (w .status )
276+
277+ inputField := tview .NewInputField ().
278+ SetLabel ("Quit [Y/n]? " ).
279+ SetFieldWidth (5 ).
280+ SetFieldBackgroundColor (tcell .ColorBlack )
281+
282+ x := func (e * tcell.EventKey ) * tcell.EventKey {
283+ keyName := string (e .Name ())
284+ if strings .Contains (keyName , "Rune" ) {
285+ keyName = string (e .Rune ())
286+ }
287+
288+ if strings .EqualFold (keyName , "y" ) || strings .EqualFold (keyName , "enter" ) {
289+ w .c .quit <- 1
290+ }
291+
292+ w .flexStatus .RemoveItem (inputField )
293+ w .flexStatus .AddItem (w .status , 1 , 1 , false )
294+ w .app .SetInputCapture (w .c .Input )
295+ w .app .SetFocus (w .articles )
296+
297+ return e
298+ }
299+ w .flexStatus .AddItem (inputField , 1 , 0 , false )
300+ w .app .SetFocus (inputField )
301+ w .app .SetInputCapture (x )
302+ }
303+
226304// StatusUpdate updates the status window with updated information
227305func (w * Window ) StatusUpdate () {
306+ if w .askQuit {
307+ return
308+ }
228309 // Update time
229310 c := w .status .GetCell (0 , 0 )
230311 c .SetText (
@@ -557,12 +638,12 @@ func (w *Window) AddToArticles(a *Article, markedWeb bool) {
557638 tc .SetReference (a )
558639 w .articles .SetCell (w .nArticles , 3 , tc )
559640
560- if a . highlight {
641+ if w . c . activeFeed == "result" {
561642 hTitle := ""
562643 fields := strings .Fields (a .title )
563644 for _ , f := range fields {
564645 found := false
565- for _ , h := range w . c . conf . Highlights {
646+ for _ , h := range strings . Fields ( w . currSearch ) {
566647 if strings .Contains (strings .ToLower (f ), strings .ToLower (h )) {
567648 found = true
568649 }
@@ -575,8 +656,26 @@ func (w *Window) AddToArticles(a *Article, markedWeb bool) {
575656 }
576657 tc .SetText (hTitle )
577658 } else {
578- tc .SetText (a .title )
579-
659+ if a .highlight {
660+ hTitle := ""
661+ fields := strings .Fields (a .title )
662+ for _ , f := range fields {
663+ found := false
664+ for _ , h := range w .c .conf .Highlights {
665+ if strings .Contains (strings .ToLower (f ), strings .ToLower (h )) {
666+ found = true
667+ }
668+ }
669+ if found {
670+ hTitle += fmt .Sprintf ("[%s]" + f + " [%s]" , w .c .theme .Highlights , w .c .theme .Title )
671+ } else {
672+ hTitle += f + " "
673+ }
674+ }
675+ tc .SetText (hTitle )
676+ } else {
677+ tc .SetText (a .title )
678+ }
580679 }
581680
582681 str := time .Since (a .published ).Round (time .Minute ).String ()
@@ -637,10 +736,10 @@ func (w *Window) AddPreview(a *Article) {
637736
638737// GetTime returns the timestring formatted as (%h%m < 24 hours < %d)
639738func GetTime (ts string ) string {
640- d_rex := regexp .MustCompile (`(\d+)h` )
641- d_res := d_rex .FindStringSubmatch (ts )
642- if len (d_res ) > 0 {
643- if i , err := strconv .Atoi (d_res [1 ]); err == nil {
739+ dDrex := regexp .MustCompile (`(\d+)h` )
740+ dRes := dDrex .FindStringSubmatch (ts )
741+ if len (dRes ) > 0 {
742+ if i , err := strconv .Atoi (dRes [1 ]); err == nil {
644743 if i > 23 {
645744 days := i / 24
646745 return strconv .Itoa (days ) + "d"
0 commit comments