gen2brain / dlgs Goto Github PK
View Code? Open in Web Editor NEWGo cross-platform library for displaying dialogs and input boxes
License: BSD 2-Clause "Simplified" License
Go cross-platform library for displaying dialogs and input boxes
License: BSD 2-Clause "Simplified" License
It would be nice if you can add notifications too.
There's a bug when I use .File()
to pick a directory. More specific: picking the root directory of a USB device always yields a corrupted path.
Picking a sub-directory of a USB device:
Picking a sub-directory on a USB device works as expected. Example:
The returned path is F:\testDir
which is correct. ✔️
Picking the root directory of a USB device:
If I select the root directory on a USB device, then the returned path contains parts of the USB device name (in this case SanDisk
). Example:
The returned path is F:\isk (F:)
which is incorrect / doesn't even exist. ❌ I tried this with different names (renamed the USB device) and the error is always the same (e.g. renaming the USB device to MyUSB
results in the path F:\B (F:)
).
On Linux, picking the root directory of a USB device works perfectly fine. So, this seems to be an issue which is related to Windows only. I couldn't trace back the error to its source. Although, I can see in the debugger that the property displayName
of the struct browseinfoW
in function dirDialog()
in file file_windows.go
contains this incorrect path. Could it be, that this issue is due to different responses from syscalls? It could be that the syscall for picking a directory returns a different value when a user picks the root of a USB device.
Code:
package main
import (
"fmt"
"github.com/gen2brain/dlgs"
)
func main() {
selectedDirectory, _, err := dlgs.File("Pick a directory", "", true)
if err != nil {
panic(err)
}
fmt.Printf("selected directory: %s", selectedDirectory)
}
Sorry, dunno how to open a pull request.
message_darwin.go line 61:
Change
From: tell application "System Events" to display dialog ....
To: display dialog ...
Otherwise you get (because of "with icon" part):
28:115: execution error: System Events got an error: Can’t make application "System Events" into type number or string. (-1700)
Thanks for this library, its helpful!
However there is some caveat regarding error handling and "cancel/close dialog" actions:
I am not quite sure for what the boolean return value should have been.
The logic right now on Linux:
func Entry(title, text, defaultText string) (string, bool, error)
o, err := exec.Command(cmd, "--entry", "--title", title, "--text", text, "--entry-text", defaultText).Output()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
return "", ws.ExitStatus() == 0, nil // <<<<<< Correct reporting a Cancle OR Close action
}
}
ret := true
out := strings.TrimSpace(string(o))
if out == "" {
ret = false // <<<<<<<<<<<< Why is an empty answer unsuccesful. (1)
}
return out, ret, err
}
Removing the check for the empty string at the end, would be desirable, since validation of the string should strongly be done outside of this function.
Doing this, gives the boolean value the meaning
true
: if the User has pressed OK
and accepts the entry.false
: the user has closed or cancled.error
is a exec
Error...With the current logic, we cannot properly distinguish between this.
I searched around, and did not find any prior art on a crossplatform CLI dialog tool. (There are some platform-specific tools, e.g., https://github.com/cocoadialog/cocoadialog.) Is there any interest in creating a CLI wrapper around dlgs to fill this niche? If nobody has the time for it, I can probably do it myself when I should have the time.
I'm relatively new to Go, so I apologize in advance if this is something obvious.
I've written a Go program using dlgs
which I've found super handy. The program calls dlgs.Entry
twice, once right after the other. The program compiles and runs fine on OS X. On Windows, when the program hits the second dlgs.Entry
, I get
panic: Class already exists.
Is this expected behavior or a bug?
On macos 10.13.2, color selector doesn't work.
It doesn't show and the code execution stops at that point and doesn't go to the next line to evaluate the returned response.
Hello!
I've noticed a couple of issues with MacOS's File() (and by extension FileMulti()) functions' file filtering.
The filter argument only works for a single file extension - you can't pass, say, "jpg png" to filter out any non-image files.
The extension filter argument MacOS expects (jpg
, for example) isn't the same format as what Linux and Windows takes (*.jpg
).
I've submitted a PR to resolve these issues - #13. I also expounded on the documentation to give an idea of what a cross-platform filter argument would look like. I just wanted to create an issue here to explain it a bit in case you had some questions or wanted to discuss it a bit.
How set width for dialog box?
This is the program built iwth dlgs "error" and "warning" pop ups
https://www.virustotal.com/gui/file/c6ecfb6dcf7b610f1ead08e38c17797be28486ef4c77b3293d02ed71b374bdd2/behavior/VirusTotal%20Sysmon
Detected by 7 engines
and writes to
C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\Microsoft\UPnP Device Host\upnphost\udhisapi.dll
and
HKLM\SOFTWARE\Microsoft\Windows Media Player NSS\3.0\Servers\A70D59A1-8EAD-4F40-AAAB-FBFC460800A4\FriendlyName
this is the same code, built in the same way, just without dlgs
https://www.virustotal.com/gui/file/9cb0cb053f58b92ad71eb50e531b802ddd01d5eb6164a391ea982b6325b328b3/behavior/VirusTotal%20Sysmon
Detected by 5 Engines
and proceeds to function as intended
So i'm using https://github.com/go-flutter-desktop/go-flutter and use plugin https://github.com/miguelpruivo/flutter_file_picker, but when i pick multi file there is only show 10 files not more. And i check the package file_picker use and then when i see it i found this repo, and i try to use it independent but only show when i choose 10 files.
This is my code
package main
import (
"log"
"strings"
"github.com/gen2brain/dlgs"
"github.com/pkg/errors"
)
func main() {
filter, err := fileFilter("ANY")
if err != nil {
log.Println("Failed to get filter", err)
return
}
filePaths, _, err := dlgs.FileMulti("Select one or more files", filter)
if err != nil {
log.Println("Failed to open dialog picker")
return
}
// type []string is not supported by StandardMessageCodec
sliceFilePaths := make([]interface{}, len(filePaths))
for i, file := range filePaths {
sliceFilePaths[i] = file
}
log.Println(sliceFilePaths)
}
func fileFilter(method string) (string, error) {
switch method {
case "ANY":
return "*", nil
case "IMAGE":
return "Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00", nil
case "AUDIO":
return "Audios (*.mp3)\x00*.mp3\x00All Files (*.*)\x00*.*\x00\x00", nil
case "VIDEO":
return "Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00All Files (*.*)\x00*.*\x00\x00", nil
default:
if strings.HasPrefix(method, "__CUSTOM_") {
resolveType := strings.Split(method, "__CUSTOM_")
return "Files (*." + resolveType[1] + ")\x00*." + resolveType[1] + "\x00All Files (*.*)\x00*.*\x00\x00", nil
}
return "", errors.New("unknown method")
}
}
func fileDialog(title string, filter string) (string, error) {
filePath, _, err := dlgs.File(title, filter, false)
if err != nil {
return "", errors.Wrap(err, "failed to open dialog picker")
}
return filePath, nil
}
Hey, there. An option to save a specific file by name would be rather nice. It's something to add at some stage, anyway.
This is a great lib. I wonder if I can add to it to open a Printer Dialog box. I just need to print files and so opening the printer dialog box and letting Windows and Darwin take over seems a good approach to stay out of the weeds.
Is there any way to force the message dialogs to always appear on top of the application window?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.