~sircmpwn/aerc

dirlist: adapt to dynamic UIconfig v1 PROPOSED

Reto Brunner: 1
 dirlist: adapt to dynamic UIconfig

 2 files changed, 21 insertions(+), 11 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/9629/mbox | git am -3
Learn more about email & git

[PATCH] dirlist: adapt to dynamic UIconfig Export this patch

---
 widgets/account.go |  2 +-
 widgets/dirlist.go | 30 ++++++++++++++++++++----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/widgets/account.go b/widgets/account.go
index 455c28e..f8b6581 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -65,7 +65,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
		}
	}

	dirlist := NewDirectoryList(acct, &acctUiConf, logger, worker)
	dirlist := NewDirectoryList(conf, acct, logger, worker)
	if acctUiConf.SidebarWidth > 0 {
		grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT))
	}
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index c0c8917..a102550 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -19,8 +19,8 @@ import (

type DirectoryList struct {
	ui.Invalidatable
	aercConf  *config.AercConfig
	acctConf  *config.AccountConfig
	uiConf    *config.UIConfig
	store     *lib.DirStore
	dirs      []string
	logger    *log.Logger
@@ -30,17 +30,18 @@ type DirectoryList struct {
	worker    *types.Worker
}

func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
	logger *log.Logger, worker *types.Worker) *DirectoryList {

	dirlist := &DirectoryList{
		aercConf: conf,
		acctConf: acctConf,
		uiConf:   uiConf,
		logger:   logger,
		spinner:  NewSpinner(uiConf),
		store:    lib.NewDirStore(),
		worker:   worker,
	}
	uiConf := dirlist.UiConfig()
	dirlist.spinner = NewSpinner(&uiConf)
	dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
		dirlist.Invalidate()
	})
@@ -48,6 +49,13 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
	return dirlist
}

func (dirlist *DirectoryList) UiConfig() config.UIConfig {
	return dirlist.aercConf.GetUiConfig(map[config.ContextType]string{
		config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name,
		config.UI_CONTEXT_FOLDER:  dirlist.Selected(),
	})
}

func (dirlist *DirectoryList) List() []string {
	return dirlist.store.List()
}
@@ -119,7 +127,7 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
		formatted = runewidth.FillRight(formatted, width-len(s))
		formatted = runewidth.Truncate(formatted, width-len(s), "…")
	}
	for _, char := range dirlist.uiConf.DirListFormat {
	for _, char := range dirlist.UiConfig().DirListFormat {
		switch char {
		case '%':
			if percent {
@@ -207,7 +215,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {

	if len(dirlist.dirs) == 0 {
		style := tcell.StyleDefault
		ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist)
		ctx.Printf(0, 0, style, dirlist.UiConfig().EmptyDirlist)
		return
	}

@@ -305,8 +313,9 @@ func folderMatches(folder string, pattern string) bool {
// will be appended at the end in alphabetical order
func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
	sort.Slice(dirlist.dirs, func(i, j int) bool {
		iInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[i])
		jInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[j])
		foldersSort := dirlist.acctConf.FoldersSort
		iInFoldersSort := findString(foldersSort, dirlist.dirs[i])
		jInFoldersSort := findString(foldersSort, dirlist.dirs[j])
		if iInFoldersSort >= 0 && jInFoldersSort >= 0 {
			return iInFoldersSort < jInFoldersSort
		}
@@ -325,12 +334,13 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
	dirlist.dirs = dirlist.store.List()
	// config option defaults to show all if unset
	if len(dirlist.acctConf.Folders) == 0 {
	configFolders := dirlist.acctConf.Folders
	if len(configFolders) == 0 {
		return
	}
	var filtered []string
	for _, folder := range dirlist.dirs {
		for _, cfgfolder := range dirlist.acctConf.Folders {
		for _, cfgfolder := range configFolders {
			if folderMatches(folder, cfgfolder) {
				filtered = append(filtered, folder)
				break
-- 
2.25.0
Thanks!

To git.sr.ht:~sircmpwn/aerc
   e78b7b8..ea0df7b  master -> master
View this thread in the archives