Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ jobs:
go-version: '1.22'

- name: Set up Core
run: go install ./cmd/core && core setup
run: go install ./cmd/core

- name: "Install video dependencies (TODO: move to a command)"
run: sudo add-apt-repository ppa:savoury1/ffmpeg4 && sudo apt install libswscale-dev libavcodec-dev libavformat-dev libswresample-dev libavutil-dev libasound2-dev
# - name: "Install video dependencies (TODO: move to a command)"
# run: sudo add-apt-repository ppa:savoury1/ffmpeg4 && sudo apt install libswscale-dev libavcodec-dev libavformat-dev libswresample-dev libavutil-dev libasound2-dev

- name: Build
run: go build -v ./...
# - name: Build
# run: go build -v ./...

- name: Build Docs (to confirm that web works)
run: core build web -dir docs -o static -v

# we can't test gpu, xyz, and system on the CI since there is no Vulkan support
- name: Test
Expand Down
14 changes: 5 additions & 9 deletions base/exec/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ func (st *StdIO) Set(o *StdIO) *StdIO {
func (st *StdIO) SetToOS() *StdIO {
cur := &StdIO{}
cur.SetFromOS()
if sif, ok := st.In.(*os.File); ok {
os.Stdin = sif
} else {
fmt.Printf("In is not an *os.File: %#v\n", st.In)
}
os.Stdout = st.Out.(*os.File)
os.Stderr = st.Err.(*os.File)
os.Stdin = st.In.(*os.File)
return cur
}

Expand Down Expand Up @@ -102,10 +98,13 @@ func IsPipe(rw any) bool {
if rw == nil {
return false
}
_, ok := rw.(io.Writer)
w, ok := rw.(io.Writer)
if !ok {
return false
}
if w == os.Stdout {
return false
}
of, ok := rw.(*os.File)
if !ok {
return false
Expand Down Expand Up @@ -248,9 +247,6 @@ func (st *StdIOState) PopToStart() {
for len(st.InStack) > st.InStart {
st.PopIn()
}
for len(st.PipeIn) > 0 {
CloseReader(st.PipeIn.Pop())
}
}

// ErrIsInOut returns true if the given Err writer is also present
Expand Down
17 changes: 11 additions & 6 deletions base/fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func NewFileInfoType(ftyp Known) *FileInfo {
// but file info will be updated based on the filename even if
// the file does not exist.
func (fi *FileInfo) InitFile(fname string) error {
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Kind = ""
var errs []error
path, err := filepath.Abs(fname)
if err == nil {
Expand All @@ -111,7 +114,6 @@ func (fi *FileInfo) InitFile(fname string) error {
fi.Path = fname
}
_, fi.Name = filepath.Split(path)
fi.SetMimeInfo()
info, err := os.Stat(fi.Path)
if err != nil {
errs = append(errs, err)
Expand All @@ -126,10 +128,12 @@ func (fi *FileInfo) InitFile(fname string) error {
// but file info will be updated based on the filename even if
// the file does not exist.
func (fi *FileInfo) InitFileFS(fsys fs.FS, fname string) error {
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Kind = ""
var errs []error
fi.Path = fname
_, fi.Name = path.Split(fname)
fi.SetMimeInfo()
info, err := fs.Stat(fsys, fi.Path)
if err != nil {
errs = append(errs, err)
Expand All @@ -145,17 +149,14 @@ func (fi *FileInfo) SetMimeInfo() error {
if fi.Path == "" || fi.Path == "." || fi.IsDir() {
return nil
}
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Generated = IsGeneratedFile(fi.Path)
fi.Kind = ""
mtyp, _, err := MimeFromFile(fi.Path)
if err != nil {
return err
}
fi.Mime = mtyp
fi.Cat = CategoryFromMime(fi.Mime)
fi.Known = MimeKnown(fi.Mime)
fi.Generated = IsGeneratedFile(fi.Path)
if fi.Cat != UnknownCategory {
fi.Kind = fi.Cat.String() + ": "
}
Expand All @@ -172,11 +173,15 @@ func (fi *FileInfo) SetFileInfo(info fs.FileInfo) {
fi.Size = datasize.Size(info.Size())
fi.Mode = info.Mode()
fi.ModTime = info.ModTime()
fi.Generated = false
if info.IsDir() {
fi.Kind = "Folder"
fi.Cat = Folder
fi.Known = AnyFolder
} else {
if fi.Mode.IsRegular() {
fi.SetMimeInfo()
}
if fi.Cat == UnknownCategory {
if fi.IsExec() {
fi.Cat = Exe
Expand Down
20 changes: 1 addition & 19 deletions base/reflectx/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,15 +953,7 @@ func SetRobust(to, from any) error {
rto := reflect.ValueOf(to)
pto := UnderlyingPointer(rto)
if IsNil(pto) {
// If the original value is a non-nil pointer, we can just use it
// even though the underlying pointer is nil (this happens when there
// is a pointer to a nil pointer; see #1365).
if !IsNil(rto) && rto.Kind() == reflect.Pointer {
pto = rto
} else {
// Otherwise, we cannot recover any meaningful value.
return fmt.Errorf("got nil destination value")
}
return fmt.Errorf("got nil destination value")
}
pito := pto.Interface()

Expand All @@ -971,16 +963,6 @@ func SetRobust(to, from any) error {
return fmt.Errorf("destination value cannot be set; it must be a variable or field, not a const or tmp or other value that cannot be set (value: %v of type %T)", pto, pto)
}

// images should not be copied per content: just set the pointer!
// otherwise the original images (esp colors!) are altered.
// TODO: #1394 notes the more general ambiguity about deep vs. shallow pointer copy.
if img, ok := to.(*image.Image); ok {
if fimg, ok := from.(image.Image); ok {
*img = fimg
return nil
}
}

// first we do the generic AssignableTo case
if rto.Kind() == reflect.Pointer {
fv := reflect.ValueOf(from)
Expand Down
2 changes: 1 addition & 1 deletion cmd/core/web/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func makeFiles(c *config.Config) error {

preRenderHTML := ""
if c.Web.GenerateHTML {
preRenderHTML, err = exec.Output("go", "run", "-tags", "offscreen,generatehtml", ".")
err = exec.Verbose().SetBuffer(false).Run("go", "run", "-tags", "offscreen,generatehtml", ".")
if err != nil {
return err
}
Expand Down
127 changes: 68 additions & 59 deletions core/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"reflect"
"strings"

"github.com/fsnotify/fsnotify"
"github.com/mitchellh/go-homedir"

"cogentcore.org/core/base/elide"
Expand Down Expand Up @@ -71,11 +70,11 @@ type FilePicker struct {
// index of currently selected file in Files list (-1 if none)
selectedIndex int

// change notify for current dir
watcher *fsnotify.Watcher
// // change notify for current dir
// watcher *fsnotify.Watcher

// channel to close watcher watcher
doneWatcher chan bool
// // channel to close watcher watcher
// doneWatcher chan bool

// Previous path that was processed via UpdateFiles
prevPath string
Expand Down Expand Up @@ -113,6 +112,7 @@ func (fp *FilePicker) Init() {
})

fp.Maker(func(p *tree.Plan) {
fmt.Println("start", fp.directory, fp.selectedFilename)
if fp.directory == "" {
fp.SetFilename("") // default to current directory
}
Expand All @@ -121,25 +121,27 @@ func (fp *FilePicker) Init() {
}
recentPaths.AddPath(fp.directory, SystemSettings.SavedPathsMax)
saveRecentPaths()
fmt.Println("will read files")
fp.readFiles()

if fp.prevPath != fp.directory {
// TODO(#424): disable for all platforms for now; causing issues
if false && TheApp.Platform() != system.MacOS {
// mac is not supported in a high-capacity fashion at this point
if fp.prevPath == "" {
fp.configWatcher()
} else {
fp.watcher.Remove(fp.prevPath)
}
fp.watcher.Add(fp.directory)
if fp.prevPath == "" {
fp.watchWatcher()
}
}
// // TODO(#424): disable for all platforms for now; causing issues
// if false && TheApp.Platform() != system.MacOS {
// // mac is not supported in a high-capacity fashion at this point
// if fp.prevPath == "" {
// fp.configWatcher()
// } else {
// fp.watcher.Remove(fp.prevPath)
// }
// fp.watcher.Add(fp.directory)
// if fp.prevPath == "" {
// fp.watchWatcher()
// }
// }
fp.prevPath = fp.directory
}

fmt.Println("will add stuff")
tree.AddAt(p, "path", func(w *Chooser) {
Bind(&fp.directory, w)
w.SetEditable(true).SetDefaultNew(true)
Expand Down Expand Up @@ -171,15 +173,15 @@ func (fp *FilePicker) Init() {

func (fp *FilePicker) Destroy() {
fp.Frame.Destroy()
if fp.watcher != nil {
fp.watcher.Close()
fp.watcher = nil
}
if fp.doneWatcher != nil {
fp.doneWatcher <- true
close(fp.doneWatcher)
fp.doneWatcher = nil
}
// if fp.watcher != nil {
// fp.watcher.Close()
// fp.watcher = nil
// }
// if fp.doneWatcher != nil {
// fp.doneWatcher <- true
// close(fp.doneWatcher)
// fp.doneWatcher = nil
// }
}

// FilePickerFilterer is a filtering function for files; returns true if the
Expand Down Expand Up @@ -438,41 +440,42 @@ func (fp *FilePicker) makeSelectedRow(selected *tree.Plan) {
}

func (fp *FilePicker) configWatcher() error {
if fp.watcher != nil {
return nil
}
var err error
fp.watcher, err = fsnotify.NewWatcher()
return err
// if fp.watcher != nil {
// return nil
// }
// var err error
// fp.watcher, err = fsnotify.NewWatcher()
// return err
return nil
}

func (fp *FilePicker) watchWatcher() {
if fp.watcher == nil || fp.watcher.Events == nil {
return
}
if fp.doneWatcher != nil {
return
}
fp.doneWatcher = make(chan bool)
go func() {
watch := fp.watcher
done := fp.doneWatcher
for {
select {
case <-done:
return
case event := <-watch.Events:
switch {
case event.Op&fsnotify.Create == fsnotify.Create ||
event.Op&fsnotify.Remove == fsnotify.Remove ||
event.Op&fsnotify.Rename == fsnotify.Rename:
fp.Update()
}
case err := <-watch.Errors:
_ = err
}
}
}()
// if fp.watcher == nil || fp.watcher.Events == nil {
// return
// }
// if fp.doneWatcher != nil {
// return
// }
// fp.doneWatcher = make(chan bool)
// go func() {
// watch := fp.watcher
// done := fp.doneWatcher
// for {
// select {
// case <-done:
// return
// case event := <-watch.Events:
// switch {
// case event.Op&fsnotify.Create == fsnotify.Create ||
// event.Op&fsnotify.Remove == fsnotify.Remove ||
// event.Op&fsnotify.Rename == fsnotify.Rename:
// fp.Update()
// }
// case err := <-watch.Errors:
// _ = err
// }
// }
// }()
}

// updateFilesEvent updates the list of files and other views for the current path.
Expand All @@ -484,17 +487,20 @@ func (fp *FilePicker) updateFilesEvent() { //types:add
}

func (fp *FilePicker) readFiles() {
fmt.Println("will es", fp.directory)
effpath, err := filepath.EvalSymlinks(fp.directory)
if err != nil {
log.Printf("FilePicker Path: %v could not be opened -- error: %v\n", effpath, err)
return
}
fmt.Println("will lstat", effpath)
_, err = os.Lstat(effpath)
if err != nil {
log.Printf("FilePicker Path: %v could not be opened -- error: %v\n", effpath, err)
return
}

fmt.Println("will walk")
fp.files = make([]*fileinfo.FileInfo, 0, 1000)
filepath.Walk(effpath, func(path string, info fs.FileInfo, err error) error {
if err != nil {
Expand All @@ -509,7 +515,9 @@ func (fp *FilePicker) readFiles() {
if path == effpath { // proceed..
return nil
}
fmt.Println("will new fileinfo", path)
fi, ferr := fileinfo.NewFileInfo(path)
fmt.Println("did new fi", path)
keep := ferr == nil
if fp.Filterer != nil {
keep = fp.Filterer(fp, fi)
Expand All @@ -522,6 +530,7 @@ func (fp *FilePicker) readFiles() {
}
return nil
})
fmt.Println("did walk")
}

// updateFavorites updates list of files and other views for current path
Expand Down
2 changes: 2 additions & 0 deletions core/generatehtml.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
func init() {
wb := NewWidgetBase()
ExternalParent = wb
fmt.Println("core init")
wb.SetOnChildAdded(func(n tree.Node) {
fmt.Println("core oca")
fmt.Println(GenerateHTML(n.(Widget)))
os.Exit(0)
})
Expand Down
Loading
Loading