about summary refs log tree commit diff stats
BranchCommit messageAuthorAge
bongkeys: st-xterm compatAcid Bong21 months
masterbump version to 6.4Hiltjo Posthuma2 years
musldmenumon fixAcid Bong21 months
 
TagDownloadAuthorAge
6.4dwm-6.4.tar.gz  Hiltjo Posthuma2 years
6.3dwm-6.3.tar.gz  Hiltjo Posthuma3 years
6.2dwm-6.2.tar.gz  Anselm R Garbe6 years
6.1dwm-6.1.tar.gz  Hiltjo Posthuma9 years
6.0dwm-6.0.tar.gz  anselm@garbe.us13 years
5.9dwm-5.9.tar.gz  garbeam@gmail.com13 years
5.8.2dwm-5.8.2.tar.gz  Anselm R Garbe14 years
5.8.1dwm-5.8.1.tar.gz  Anselm R Garbe14 years
5.8dwm-5.8.tar.gz  anselm@garbe.us14 years
5.7.2dwm-5.7.2.tar.gz  Anselm R Garbe15 years
5.7.1dwm-5.7.1.tar.gz  Anselm R Garbe15 years
5.7dwm-5.7.tar.gz  Anselm R Garbe15 years
5.6.1dwm-5.6.1.tar.gz  Anselm R Garbe15 years
5.6dwm-5.6.tar.gz  Anselm R Garbe15 years
5.5dwm-5.5.tar.gz  Anselm R Garbe16 years
5.4.1dwm-5.4.1.tar.gz  a@null16 years
5.4dwm-5.4.tar.gz  a@null16 years
5.3.1dwm-5.3.1.tar.gz  Anselm R Garbe16 years
5.3dwm-5.3.tar.gz  Anselm R Garbe16 years
5.2dwm-5.2.tar.gz  Anselm R Garbe16 years
5.1dwm-5.1.tar.gz  Anselm R Garbe16 years
5.0dwm-5.0.tar.gz  Anselm R Garbe16 years
4.9dwm-4.9.tar.gz  Anselm R Garbe17 years
4.8dwm-4.8.tar.gz  Anselm R Garbe17 years
4.7dwm-4.7.tar.gz  Anselm R. Garbe17 years
4.6dwm-4.6.tar.gz  arg@suckless.org17 years
4.5dwm-4.5.tar.gz  Anselm R. Garbe17 years
4.4.1dwm-4.4.1.tar.gz  Anselm R. Garbe17 years
4.4dwm-4.4.tar.gz  Anselm R. Garbe17 years
4.3dwm-4.3.tar.gz  arg@f00b4r17 years
4.2dwm-4.2.tar.gz  Anselm R. Garbe17 years
4.1dwm-4.1.tar.gz  Anselm R. Garbe17 years
4.0dwm-4.0.tar.gz  Anselm R. Garbe18 years
3.9dwm-3.9.tar.gz  Anselm R. Garbe18 years
3.8dwm-3.8.tar.gz  Anselm R. Garbe18 years
3.7dwm-3.7.tar.gz  Anselm R. Garbe18 years
3.6.1dwm-3.6.1.tar.gz  Anselm R. Garbe18 years
3.6dwm-3.6.tar.gz  Anselm R. Garbe18 years
3.5dwm-3.5.tar.gz  Anselm R. Garbe18 years
3.4dwm-3.4.tar.gz  Anselm R. Garbe18 years
3.3dwm-3.3.tar.gz  Anselm R. Garbe18 years
3.2.2dwm-3.2.2.tar.gz  Anselm R. Garbe18 years
3.2.1dwm-3.2.1.tar.gz  Anselm R. Garbe18 years
3.2dwm-3.2.tar.gz  Anselm R. Garbe18 years
3.1dwm-3.1.tar.gz  Anselm R. Garbe18 years
3.0dwm-3.0.tar.gz  Anselm R. Garbe18 years
2.9dwm-2.9.tar.gz  Anselm R. Garbe18 years
2.8dwm-2.8.tar.gz  arg@mig2918 years
2.7dwm-2.7.tar.gz  arg@mig2918 years
2.6dwm-2.6.tar.gz  arg@mig2918 years
2.5.1dwm-2.5.1.tar.gz  arg@mig2918 years
2.5dwm-2.5.tar.gz  arg@mig2918 years
2.4dwm-2.4.tar.gz  arg@mig2918 years
2.3dwm-2.3.tar.gz  arg@mig2918 years
2.2dwm-2.2.tar.gz  arg@mig2918 years
2.1dwm-2.1.tar.gz  arg@mig2918 years
2.0dwm-2.0.tar.gz  arg@mig2918 years
1.9dwm-1.9.tar.gz  Anselm R. Garbe18 years
1.8dwm-1.8.tar.gz  Anselm R. Garbe18 years
1.7.1dwm-1.7.1.tar.gz  Anselm R. Garbe18 years
1.7dwm-1.7.tar.gz  arg@mmvi18 years
1.6dwm-1.6.tar.gz  arg@mmvi18 years
1.5dwm-1.5.tar.gz  Anselm R. Garbe18 years
1.4dwm-1.4.tar.gz  Anselm R. Garbe18 years
1.3dwm-1.3.tar.gz  Anselm R. Garbe18 years
1.2dwm-1.2.tar.gz  Anselm R. Garbe18 years
1.1dwm-1.1.tar.gz  Anselm R. Garbe18 years
1.0dwm-1.0.tar.gz  Anselm R. Garbe18 years
0.9dwm-0.9.tar.gz  Anselm R.Garbe18 years
0.8dwm-0.8.tar.gz  Anselm R.Garbe18 years
0.7dwm-0.7.tar.gz  arg@10ksloc.org18 years
0.6dwm-0.6.tar.gz  arg@10ksloc.org18 years
0.5dwm-0.5.tar.gz  arg@10ksloc.org18 years
0.4dwm-0.4.tar.gz  arg@10ksloc.org18 years
0.3dwm-0.3.tar.gz  arg@10ksloc.org18 years
0.2dwm-0.2.tar.gz  Anselm R. Garbe18 years
0.1dwm-0.1.tar.gz  Anselm R. Garbe18 years
0&id=8635c70fda20b91f97c42f4e23e97bc01a14a89d'>8635c70 ^
80e891a ^
72e4b5e ^
8635c70 ^
ecd803a ^
8fa4583 ^

661e3ec ^



ecd803a ^




6838c23 ^
ecd803a ^








6838c23 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
               

        
                                  
 
                                      
                                         

 
                    
                        
                                    
                          
                                             
                               
                                 

 
                                                      

                                              
 
                                                                         
                          
                                    
                                    
                                         
                                        
                                   
         



                                                

 















                                                                            
                                
                           

 
                                         
                          

 
                                     
                             

 



                                                 
                                                    
                                                
                                             
                                      
                                   





                                                          
                                                  
                                             
                                             
                                   

                                                    



                   




                           
                                  








                                     
                              
package widgets

import (
	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc/lib"
	"git.sr.ht/~sircmpwn/aerc/lib/ui"
)

type ExLine struct {
	ui.Invalidatable
	commit      func(cmd string)
	finish      func()
	tabcomplete func(cmd string) []string
	cmdHistory  lib.History
	input       *ui.TextInput
}

func NewExLine(commit func(cmd string), finish func(),
	tabcomplete func(cmd string) []string,
	cmdHistory lib.History) *ExLine {

	input := ui.NewTextInput("").Prompt(":").TabComplete(tabcomplete)
	exline := &ExLine{
		commit:      commit,
		finish:      finish,
		tabcomplete: tabcomplete,
		cmdHistory:  cmdHistory,
		input:       input,
	}
	input.OnInvalidate(func(d ui.Drawable) {
		exline.Invalidate()
	})
	return exline
}

func NewPrompt(prompt string, commit func(text string),
	tabcomplete func(cmd string) []string) *ExLine {

	input := ui.NewTextInput("").Prompt(prompt).TabComplete(tabcomplete)
	exline := &ExLine{
		commit:      commit,
		tabcomplete: tabcomplete,
		cmdHistory:  &nullHistory{input: input},
		input:       input,
	}
	input.OnInvalidate(func(d ui.Drawable) {
		exline.Invalidate()
	})
	return exline
}

func (ex *ExLine) Invalidate() {
	ex.DoInvalidate(ex)
}

func (ex *ExLine) Draw(ctx *ui.Context) {
	ex.input.Draw(ctx)
}

func (ex *ExLine) Focus(focus bool) {
	ex.input.Focus(focus)
}

func (ex *ExLine) Event(event tcell.Event) bool {
	switch event := event.(type) {
	case *tcell.EventKey:
		switch event.Key() {
		case tcell.KeyEnter, tcell.KeyCtrlJ:
			cmd := ex.input.String()
			ex.input.Focus(false)
			ex.commit(cmd)
			ex.finish()
		case tcell.KeyUp:
			ex.input.Set(ex.cmdHistory.Prev())
			ex.Invalidate()
		case tcell.KeyDown:
			ex.input.Set(ex.cmdHistory.Next())
			ex.Invalidate()
		case tcell.KeyEsc, tcell.KeyCtrlC:
			ex.input.Focus(false)
			ex.cmdHistory.Reset()
			ex.finish()
		default:
			return ex.input.Event(event)
		}
	}
	return true
}

type nullHistory struct {
	input *ui.TextInput
}

func (*nullHistory) Add(string) {}

func (h *nullHistory) Next() string {
	return h.input.String()
}

func (h *nullHistory) Prev() string {
	return h.input.String()
}

func (*nullHistory) Reset() {}