about summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* 6079 - optimize register spillsKartik Agaram2020-03-052-23/+211
| | | | | The second var to the same register in a block doesn't need to spill. We're never going to restore the var it's shadowing.
* 6078 - highlight hex literals in VimKartik Agaram2020-03-023-3/+3
|
* 6077Kartik Agaram2020-03-025-54/+55
|
* 6076Kartik Agaram2020-03-021-20/+21
|
* 6075Kartik Agaram2020-03-021-1/+2
|
* 6074Kartik Agaram2020-02-292-21/+25
|
* 6073Kartik Agaram2020-02-292-11/+28
|
* 6072Kartik Agaram2020-02-292-1/+3
| | | | | | | | | | | | | | I just did an experiment, and test_apps is spending over half its time (95 seconds that could be 40) redundantly clearing every stream before every test. And some of those streams are _large_; the translators for SubX and Mu use streams sizes pessimistically for the largest possible program they can handle (1MB per segment). A single test (the one in assort.subx) spends 24 seconds initializing 2 1MB-segments before processing a dozen lines of text in the blink of an eye. I'm not going to speed this up. But good to know.
* 6071 - array indexing for non-int power-of-2 typesKartik Agaram2020-02-292-11/+163
|
* 6070Kartik Agaram2020-02-2918-103/+99
|
* 6069Kartik Agaram2020-02-293-45/+45
|
* 6068Kartik Agaram2020-02-284-11/+11
|
* 6067Kartik Agaram2020-02-281-0/+58
| | | | Missed the file.
* 6066 - Vim syntax highlighting for Mu filesKartik Agaram2020-02-285-22/+22
|
* 6065Kartik Agaram2020-02-272-3/+3
|
* 6064Kartik Agaram2020-02-2716-3/+3
| | | | Fix CI.
* 6063Kartik Agaram2020-02-271-8816/+8893
|
* 6062Kartik Agaram2020-02-272-10/+92
|
* 6061Kartik Agaram2020-02-273-44/+44
|
* 6060Kartik Agaram2020-02-271-11/+11
|
* 6059Kartik Agaram2020-02-272-0/+13
|
* 6058Kartik Agaram2020-02-271-15/+15
|
* 6057Kartik Agaram2020-02-271-4/+6
|
* 6056Kartik Agaram2020-02-272-8506/+9028
|
* 6055 - record types and the 'get' instructionKartik Agaram2020-02-272-6/+487
| | | | | | | | | | | This is a lot of code for a single test, and it took a long time to get my data model just right. But the test coverage seems ok because it feels mostly like straight-line code. We'll see. I've also had to add a lot of prints. We really need app-level trace generation pretty urgently. That requires deciding how to turn it on/off from the commandline. And I've been reluctant to start relying on the hairy interface that is POSIX open().
* 6054Kartik Agaram2020-02-242-3/+21
|
* 6053Kartik Agaram2020-02-233-3/+3
|
* 6052Kartik Agaram2020-02-231-10/+21
|
* 6051Kartik Agaram2020-02-232-13/+25
|
* 6050Kartik Agaram2020-02-232-26/+34
|
* 6049Kartik Agaram2020-02-231-11/+11
|
* 6048Kartik Agaram2020-02-212-28/+9
|
* 6047Kartik Agaram2020-02-212-2/+2
|
* 6046Kartik Agaram2020-02-212-45/+42
| | | | One more error condition when desugaring function calls in SubX.
* 6045Kartik Agaram2020-02-211-16/+16
|
* 6044Kartik Agaram2020-02-212-68/+68
|
* 6043Kartik Agaram2020-02-212-0/+52
| | | | Test for 'index'.
* 6042Kartik Agaram2020-02-212-8415/+8477
|
* 6041 - array indexing starting to workKartik Agaram2020-02-215-10/+124
| | | | | | | | | | | | | And we're using it now in factorial.mu! In the process I had to fix a couple of bugs in pointer dereferencing. There are still some limitations: a) Indexing by a literal doesn't work yet. b) Only arrays of ints supported so far. Looking ahead, I'm not sure how I can support indexing arrays by non-literals (variables in registers) unless the element size is a power of 2.
* 6040Kartik Agaram2020-02-211-3/+20
|
* 6039Kartik Agaram2020-02-212-0/+22
|
* 6038Kartik Agaram2020-02-201-8112/+8313
|
* 6037 - first passing test for pointer lookupKartik Agaram2020-02-202-67/+192
|
* 6036Kartik Agaram2020-02-202-5/+6
|
* 6035Kartik Agaram2020-02-202-18/+18
|
* 6034Kartik Agaram2020-02-202-20/+20
|
* 6033 - save pointer lookup state while parsingKartik Agaram2020-02-202-30/+37
|
* 6032 - make room for '*' pointer lookups in stmtsKartik Agaram2020-02-202-31/+89
|
* 6031 - bugfix in selecting codegen patternKartik Agaram2020-02-202-6/+23
|
* 6030Kartik Agaram2020-02-202-11/+9
|
                                                             
                                         










                                                                                           

                                                   
                                                      
                                                    


                                                  



                         
                                                   





                                                                        
                                         



                                                                    


                            



                                                 
                                            
                                     


                                                     
                                                                          





                                         




                                           
                                                                              





                                                                             

                                             
                                                   


                                                            

                     
 




































                                                                                              
package widgets

import (
	"log"
	"sort"

	"github.com/gdamore/tcell"

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

type DirectoryList struct {
	ui.Invalidatable
	conf      *config.AccountConfig
	dirs      []string
	logger    *log.Logger
	selecting string
	selected  string
	spinner   *Spinner
	worker    *types.Worker
}

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

	dirlist := &DirectoryList{
		conf:    conf,
		logger:  logger,
		spinner: NewSpinner(),
		worker:  worker,
	}
	dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
		dirlist.Invalidate()
	})
	dirlist.spinner.Start()
	return dirlist
}

func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
	var dirs []string
	dirlist.worker.PostAction(
		&types.ListDirectories{}, func(msg types.WorkerMessage) {

			switch msg := msg.(type) {
			case *types.Directory:
				dirs = append(dirs, msg.Name)
			case *types.Done:
				// There is always an INBOX, RFC-guaranteed
				// However, for some reason Dovecot doesn't always send it.
				inbox := false
				for _, dir := range dirs {
					if dir == "INBOX" {
						inbox = true
					}
				}
				if !inbox {
					dirs = append(dirs, "INBOX")
				}
				sort.Strings(dirs)
				dirlist.dirs = dirs
				dirlist.spinner.Stop()
				dirlist.Invalidate()
				if done != nil {
					done(dirs)
				}
			}
		})
}

func (dirlist *DirectoryList) Select(name string) {
	dirlist.selecting = name
	dirlist.worker.PostAction(&types.OpenDirectory{Directory: name},
		func(msg types.WorkerMessage) {
			switch msg.(type) {
			case *types.Error:
				dirlist.selecting = ""
			case *types.Done:
				dirlist.selected = dirlist.selecting
			}
			dirlist.Invalidate()
		})
	dirlist.Invalidate()
}

func (dirlist *DirectoryList) Selected() string {
	return dirlist.selected
}

func (dirlist *DirectoryList) Invalidate() {
	dirlist.DoInvalidate(dirlist)
}

func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)

	if dirlist.spinner.IsRunning() {
		dirlist.spinner.Draw(ctx)
		return
	}

	row := 0
	for _, name := range dirlist.dirs {
		if row >= ctx.Height() {
			break
		}
		if len(dirlist.conf.Folders) > 1 && name != dirlist.selected {
			idx := sort.SearchStrings(dirlist.conf.Folders, name)
			if idx == len(dirlist.conf.Folders) ||
				dirlist.conf.Folders[idx] != name {
				continue
			}
		}
		style := tcell.StyleDefault
		if name == dirlist.selected {
			style = style.Reverse(true)
		}
		ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
		ctx.Printf(0, row, style, "%s", name)
		row++
	}
}

func (dirlist *DirectoryList) nextPrev(delta int) {
	for i, dir := range dirlist.dirs {
		if dir == dirlist.selected {
			var j int
			ndirs := len(dirlist.dirs)
			for j = i + delta; j != i; j += delta {
				if j < 0 {
					j = ndirs - 1
				}
				if j >= ndirs {
					j = 0
				}
				name := dirlist.dirs[j]
				if len(dirlist.conf.Folders) > 1 && name != dirlist.selected {
					idx := sort.SearchStrings(dirlist.conf.Folders, name)
					if idx == len(dirlist.conf.Folders) ||
						dirlist.conf.Folders[idx] != name {

						continue
					}
				}
				break
			}
			dirlist.Select(dirlist.dirs[j])
			break
		}
	}
}

func (dirlist *DirectoryList) Next() {
	dirlist.nextPrev(1)
}

func (dirlist *DirectoryList) Prev() {
	dirlist.nextPrev(-1)
}