summary refs log tree commit diff stats
path: root/examples/plugin_new_macro.py
blob: ec0c487cdacbffc3ee6daadcbf205213a98fe97f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# This plugin adds the new macro %date which is substituted with the current
# date in commands that allow macros.  You can test it with the command
# ":shell echo %date; read"

# Save the original macro function
import ranger.core.actions
old_get_macros = ranger.core.actions.Actions._get_macros

# Define a new macro function
import time
def get_macros_with_date(self):
       macros = old_get_macros(self)
       macros['date'] = time.strftime('%m/%d/%Y')
       return macros

# Overwrite the old one
ranger.core.actions.Actions._get_macros = get_macros_with_date
kspecs/aerc/blame/widgets/aerc.go?h=0.1.0&id=e463c38476b96be99b4ae08af4db9e92da9d2a50'>^
cab3771 ^
80e891a ^
1c41b63 ^

cab3771 ^
b76deea ^

648ca98 ^
c286d3d ^
b76deea ^
0911cd5 ^
1c41b63 ^
cab3771 ^
cab3771 ^
c286d3d ^


cab3771 ^



b76deea ^


cab3771 ^









80e891a ^
c286d3d ^

cab3771 ^
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



               
 
                                  
 
                                          



                                                


                                        

 
                                                                 
                               
 
                                                          

                                       
                                    

                                       

          

                                                                   
                                            
                                                          

                                                              
 

                                              
                                            
                                                     
                                       
                                         
         
 
                     


                                   



                                                                     


                                                       









                                            
                                                 

                                                                            
 
package widgets

import (
	"log"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc2/config"
	libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
)

type Aerc struct {
	accounts map[string]*AccountView
	grid     *libui.Grid
	tabs     *libui.Tabs
}

func NewAerc(conf *config.AercConfig, logger *log.Logger) *Aerc {
	tabs := libui.NewTabs()

	mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
		{libui.SIZE_EXACT, 1},
		{libui.SIZE_WEIGHT, 1},
	}).Columns([]libui.GridSpec{
		{libui.SIZE_EXACT, 20},
		{libui.SIZE_WEIGHT, 1},
	})

	// TODO: Grab sidebar size from config and via :set command
	mainGrid.AddChild(libui.NewText("aerc").
		Strategy(libui.TEXT_CENTER).
		Color(tcell.ColorBlack, tcell.ColorWhite))
	mainGrid.AddChild(tabs.TabStrip).At(0, 1)
	mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)

	accts := make(map[string]*AccountView)

	for _, acct := range conf.Accounts {
		view := NewAccountView(&acct, logger)
		accts[acct.Name] = view
		tabs.Add(view, acct.Name)
	}

	return &Aerc{
		accounts: accts,
		grid:     mainGrid,
		tabs:     tabs,
	}
}

func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
	aerc.grid.OnInvalidate(func(_ libui.Drawable) {
		onInvalidate(aerc)
	})
}

func (aerc *Aerc) Invalidate() {
	aerc.grid.Invalidate()
}

func (aerc *Aerc) Draw(ctx *libui.Context) {
	aerc.grid.Draw(ctx)
}

func (aerc *Aerc) Event(event tcell.Event) bool {
	acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView)
	return acct.Event(event)
}