about summary refs log tree commit diff stats
path: root/widgets/directories.go
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/directories.go')
-rw-r--r--widgets/directories.go58
1 files changed, 58 insertions, 0 deletions
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)
+	}
+}
Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
// https://raytracing.github.io/books/RayTracingInOneWeekend.html
#include <iostream>

int main() {

    // Image

    const int image_width = 256;
    const int image_height = 256;

    // Render

    std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";

    for (int j = image_height-1; j >= 0; --j) {
        for (int i = 0; i < image_width; ++i) {
            auto r = double(i) / (image_width-1);
            auto g = double(j) / (image_height-1);
            auto b = 0.25;

            int ir = static_cast<int>(255.999 * r);
            int ig = static_cast<int>(255.999 * g);
            int ib = static_cast<int>(255.999 * b);

            std::cout << ir << ' ' << ig << ' ' << ib << '\n';
        }
    }
}