Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-01-29 13:11:20 -06:00
parent c849564a35
commit 03805345f9
1 changed files with 357 additions and 0 deletions

View File

@ -623,3 +623,360 @@ func file_view_proto_init() {
}
// `autogen:view.sort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.48 2025-01-28_20:32:42_UTC
// go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//
package main
import (
"fmt"
"sort"
"sync"
)
// a simple global lock
var viewMu sync.RWMutex
func (x *Views) fixUuid() {
if x == nil {
return
}
if x.Uuid == "d19c1fbb-32c2-4957-aee6-f8128a511dca" {
return
}
x.Uuid = "d19c1fbb-32c2-4957-aee6-f8128a511dca"
x.Version = "v0.0.1 go.wit.com/toolkits/gocui"
}
func NewViews() *Views {
x := new(Views)
x.Uuid = "d19c1fbb-32c2-4957-aee6-f8128a511dca"
x.Version = "v0.0.1 go.wit.com/toolkits/gocui"
return x
}
// START SORT
// DEFINE THE Views ITERATOR.
// itializes a new iterator.
func newViewsIterator(things []*Views) *ViewsIterator {
return &ViewsIterator{things: things}
}
type ViewsIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Views
index int
}
func (it *ViewsIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *ViewsIterator) Next() *Views {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in ViewsIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE View ITERATOR.
// itializes a new iterator.
func newViewIterator(things []*View) *ViewIterator {
return &ViewIterator{things: things}
}
type ViewIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*View
index int
}
func (it *ViewIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *ViewIterator) Next() *View {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in ViewIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE GocuiState ITERATOR.
// itializes a new iterator.
func newGocuiStateIterator(things []*GocuiState) *GocuiStateIterator {
return &GocuiStateIterator{things: things}
}
type GocuiStateIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*GocuiState
index int
}
func (it *GocuiStateIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *GocuiStateIterator) Next() *GocuiState {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in GocuiStateIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE ViewSettings ITERATOR.
// itializes a new iterator.
func newViewSettingsIterator(things []*ViewSettings) *ViewSettingsIterator {
return &ViewSettingsIterator{things: things}
}
type ViewSettingsIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*ViewSettings
index int
}
func (it *ViewSettingsIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *ViewSettingsIterator) Next() *ViewSettings {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in ViewSettingsIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Tree ITERATOR.
// itializes a new iterator.
func newTreeIterator(things []*Tree) *TreeIterator {
return &TreeIterator{things: things}
}
type TreeIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Tree
index int
}
func (it *TreeIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *TreeIterator) Next() *Tree {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in TreeIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// sort struct by Name
type ViewName []*View
func (a ViewName) Len() int { return len(a) }
func (a ViewName) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a ViewName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Views) allViews() []*View {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*View
tmp = make([]*View, len(x.Views))
for i, p := range x.Views {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Tree) allChildren() []*View {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*View
tmp = make([]*View, len(x.Children))
for i, p := range x.Children {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the View protobufs
func (x *Views) selectAllViews() []*View {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each View
var tmp []*View
tmp = make([]*View, len(x.Views))
for i, p := range x.Views {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the View protobufs
func (x *Tree) selectAllChildren() []*View {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each View
var tmp []*View
tmp = make([]*View, len(x.Children))
for i, p := range x.Children {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
func (x *Views) SortByName() *ViewIterator {
// copy the pointers as fast as possible.
things := x.selectAllViews()
// todo: try slices.SortFunc() instead to see what happens
sort.Sort(ViewName(things))
// slices.SortFunc(things, func(a, b *Views) bool {
// return a.Name < b.Name // Sort by ??. let the compiler work it out??
// })
return newViewIterator(things)
}
// END SORT
func (x *Views) Len() int {
x.RLock()
defer x.RUnlock()
return len(x.Views)
}
// just a simple Append() shortcut (but still uses the mutex lock)
func (x *Views) Append(y *View) {
x.Lock()
defer x.Unlock()
x.Views = append(x.Views, y)
}
func (x *Views) All() *ViewIterator {
ViewPointers := x.selectAllViews()
iterator := newViewIterator(ViewPointers)
return iterator
}
func (x *Views) Delete(y *View) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Views {
if x.Views[i] == y {
x.Views[i] = x.Views[len(x.Views)-1]
x.Views = x.Views[:len(x.Views)-1]
return true
}
}
return false
}
// lookup a Views by the Name
func (x *Views) FindByName(s string) *View {
if x == nil {
return nil
}
x.RLock()
defer x.RUnlock()
for i, _ := range x.Views {
if x.Views[i].Name == s {
return x.Views[i]
}
}
return nil
}
func (x *Views) DeleteByName(s string) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Views {
if x.Views[i].Name == s {
x.Views[i] = x.Views[len(x.Views)-1]
x.Views = x.Views[:len(x.Views)-1]
return true
}
}
return false
}
func (x *Views) AppendByName(y *View) bool {
x.Lock()
defer x.Unlock()
for _, p := range x.Views {
if p.Name == y.Name {
return false
}
}
x.Views = append(x.Views, y)
return true
}