summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--widgets/account.go49
-rw-r--r--widgets/directories.go58
2 files changed, 84 insertions, 23 deletions
diff --git a/widgets/account.go b/widgets/account.go
index d283956..d749f60 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -15,6 +15,7 @@ import (
 
 type AccountView struct {
 	conf         *config.AccountConfig
+	dirlist      *DirectoryList
 	grid         *ui.Grid
 	logger       *log.Logger
 	interactive  ui.Interactive
@@ -38,8 +39,6 @@ func NewAccountView(
 		{ui.SIZE_EXACT, 20},
 		{ui.SIZE_WEIGHT, 1},
 	})
-	grid.AddChild(ui.NewBordered(
-		ui.NewFill('s'), ui.BORDER_RIGHT)).Span(2, 1)
 	grid.AddChild(ui.NewFill('.')).At(0, 1)
 	grid.AddChild(statusbar).At(1, 1)
 
@@ -54,8 +53,12 @@ func NewAccountView(
 		}
 	}
 
+	dirlist := NewDirectoryList(logger, worker)
+	grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT)).Span(2, 1)
+
 	acct := &AccountView{
 		conf:       conf,
+		dirlist:    dirlist,
 		grid:       grid,
 		logger:     logger,
 		statusline: statusline,
@@ -78,27 +81,6 @@ func NewAccountView(
 	return acct
 }
 
-func (acct *AccountView) connected(msg types.WorkerMessage) {
-	switch msg := msg.(type) {
-	case *types.Done:
-		acct.statusline.Set("Connected.")
-		acct.logger.Println("Connected.")
-		acct.worker.PostAction(&types.ListDirectories{}, nil)
-	case *types.CertificateApprovalRequest:
-		// TODO: Ask the user
-		acct.logger.Println("Approved unknown certificate.")
-		acct.statusline.Push("Approved unknown certificate.", 5*time.Second)
-		acct.worker.PostAction(&types.ApproveCertificate{
-			Message:  types.RespondTo(msg),
-			Approved: true,
-		}, acct.connected)
-	default:
-		acct.logger.Println("Connection failed.")
-		acct.statusline.Set("Connection failed.").
-			Color(tcell.ColorRed, tcell.ColorDefault)
-	}
-}
-
 func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) {
 	acct.grid.OnInvalidate(func(_ ui.Drawable) {
 		onInvalidate(acct)
@@ -136,3 +118,24 @@ func (acct *AccountView) Event(event tcell.Event) bool {
 	}
 	return false
 }
+
+func (acct *AccountView) connected(msg types.WorkerMessage) {
+	switch msg := msg.(type) {
+	case *types.Done:
+		acct.statusline.Set("Connected.")
+		acct.logger.Println("Connected.")
+		acct.dirlist.UpdateList()
+	case *types.CertificateApprovalRequest:
+		// TODO: Ask the user
+		acct.logger.Println("Approved unknown certificate.")
+		acct.statusline.Push("Approved unknown certificate.", 5*time.Second)
+		acct.worker.PostAction(&types.ApproveCertificate{
+			Message:  types.RespondTo(msg),
+			Approved: true,
+		}, acct.connected)
+	default:
+		acct.logger.Println("Connection failed.")
+		acct.statusline.Set("Connection failed.").
+			Color(tcell.ColorRed, tcell.ColorDefault)
+	}
+}
diff --git a/widgets/directories.go b/widgets/directories.go
new file mode 100644
index 0000000..a9ea7d4
--- /dev/null
+++ b/widgets/directories.go
@@ -0,0 +1,58 @@
+package widgets
+
+import (
+	"log"
+	"sort"
+
+	"github.com/gdamore/tcell"
+
+	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
+	"git.sr.ht/~sircmpwn/aerc2/worker/types"
+)
+
+type DirectoryList struct {
+	dirs         []string
+	logger       *log.Logger
+	onInvalidate func(d ui.Drawable)
+	worker       *types.Worker
+}
+
+func NewDirectoryList(logger *log.Logger, worker *types.Worker) *DirectoryList {
+	return &DirectoryList{logger: logger, worker: worker}
+}
+
+func (dirlist *DirectoryList) UpdateList() {
+	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:
+				sort.Strings(dirs)
+				dirlist.dirs = dirs
+				dirlist.Invalidate()
+			}
+		})
+}
+
+func (dirlist *DirectoryList) OnInvalidate(onInvalidate func(d ui.Drawable)) {
+	dirlist.onInvalidate = onInvalidate
+}
+
+func (dirlist *DirectoryList) Invalidate() {
+	if dirlist.onInvalidate != nil {
+		dirlist.onInvalidate(dirlist)
+	}
+}
+
+func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+	for i, name := range dirlist.dirs {
+		if i >= ctx.Height() {
+			break
+		}
+		ctx.Printf(0, i, tcell.StyleDefault, "%s", name)
+	}
+}
'n303' href='#n303'>303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504