~gioverse/chat

962500503098240bc9d34b6781eeb5b312ef7d1c — Chris Waldon 3 months ago cddbe8d
example/kitchen{,/ui}: allow chats to start at oldest via a flag

This commit exposes a CLI flag to make chats start at the beginning
of the conversation instead of at the end. Having this flag may serve
as a useful reference for folks looking for this behavior.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2 files changed, 6 insertions(+), 2 deletions(-)

M example/kitchen/main.go
M example/kitchen/ui/ui.go
M example/kitchen/main.go => example/kitchen/main.go +2 -1
@@ 30,9 30,10 @@ func init() {
	flag.StringVar(&config.Theme, "theme", "light", "theme to use {light,dark}")
	flag.StringVar(&profileOpt, "profile", "none", "create the provided kind of profile. Use one of [none, cpu, mem, block, goroutine, mutex, trace, gio]")
	flag.BoolVar(&config.UsePlato, "plato", false, "use Plato Team Inc themed widgets")
	flag.BoolVar(&config.ScrollToEnd, "scroll-end", true, "start chat interfaces looking at the most recent chat messages, rather than the oldest")
	flag.IntVar(&config.Latency, "latency", 1000, "maximum latency (in millis) to simulate")
	flag.IntVar(&config.LoadSize, "load-size", 30, "number of items to load at a time")
	flag.IntVar(&config.BufferSize, "buffer-size", 30, "number of elements to hold in memory before compacting")
	flag.IntVar(&config.BufferSize, "buffer-size", 100, "number of elements to hold in memory before compacting")

	flag.Parse()
}

M example/kitchen/ui/ui.go => example/kitchen/ui/ui.go +4 -1
@@ 50,6 50,9 @@ type Config struct {
	// bufferSize specifies how many elements to hold in memory before
	// compacting the list.
	BufferSize int
	// ScrollToEnd controls whether the chat interfaces start looking at the beginning
	// or end of the chat content.
	ScrollToEnd bool
}

// th is the active theme object.


@@ 168,7 171,7 @@ func NewUI(invalidator func(), conf Config) *UI {
		rt := NewExampleData(users, local, g, 100)
		rt.SimulateLatency = conf.Latency
		rt.MaxLoads = conf.LoadSize
		rt.ScrollToEnd = false
		rt.ScrollToEnd = conf.ScrollToEnd
		lm := list.NewManager(conf.BufferSize,
			list.Hooks{
				// Define an allocator function that can instaniate the appropriate