Go cross-platform library for displaying dialogs and input boxes

dlgs

TravisCI Build Status AppVeyor Build Status GoDoc Go Report Card

dlgs is a cross-platform library for displaying dialogs and input boxes.

Installation

go get -u github.com/gen2brain/dlgs

Documentation

Documentation on GoDoc.

Examples

item, _, err := dlgs.List("List", "Select item from list:", []string{"Bug", "New Feature", "Improvement"})
if err != nil {
    panic(err)
}
passwd, _, err := dlgs.Password("Password", "Enter your API key:")
if err != nil {
    panic(err)
}
yes, err := dlgs.Question("Question", "Are you sure you want to format this media?", true)
if err != nil {
    panic(err)
}

More

For cross-platform notifications and alerts see beeep.

Owner
Milan Nikolic
SysAdmin / Developer
Milan Nikolic
Comments
  • File picker returns an incorrect path for USB devices on Windows

    File picker returns an incorrect path for USB devices on Windows

    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: grafik

    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: grafik

    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)
    }
    
  • Fix Darwin implementation to escape input sent to osascript

    Fix Darwin implementation to escape input sent to osascript

    The current MacOS implementation of dlgs is vulnerable to code injection through unescaped text being sent to the osascript command. This PR fixes this by escaping the text before concatenating it with the AppleScript.

    Demonstration:

    Info("Proof of Concept\" buttons {\"OK\"} \n tell application \"Calculator\" to activate \n--", "Hello, Calculator.app!")
    //                     ^                     ^- Open Calculator.app                        ^
    //                     |- Break out of the title string.                                   |- Comment out the rest of the original AppleScript.
    

    This should open the Calculator app.

  • Fix: Multiple extension filter wasn't working on MacOS for File() and…

    Fix: Multiple extension filter wasn't working on MacOS for File() and…

    … FileMulti().

    Fix: Couldn't use same filter string across all platforms (as MacOS expects "jpg" instead of "*.jpg" for a filter string, unlike Windows and Linux). Now the characters are stripped down for Mac.

  • class already exits error

    class already exits error

    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?

  • Color selector doesn't work

    Color selector doesn't work

    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.

  • Fix build error on darwin

    Fix build error on darwin

    Build on darwin fails due to missing the change in #22.

    $ sw_vers
    ProductName:    macOS
    ProductVersion: 11.2.1
    BuildVersion:   20D74
    
    $ go build ./...
    ./file_darwin.go:99:16: undefined: ret
    

    This PR fix the build error and now I confirmed that the build will pass.

  • Fixed problem to display dialogs on MacOs Catalina

    Fixed problem to display dialogs on MacOs Catalina

    When trying to open an Error dialog on MacOs Catalina, I was getting the error "Cannot convert application "System Events" in type number or string. (-1700)".

    Removing the "tell application "System Events" to" it worked for me.

  • Fixed a bug in Darwin

    Fixed a bug in Darwin

    The bug: if path of file was chosen, the last element (i.e. the file itself) would be dropped.

    These are the raw outputs of the osascript choose... command:

    $ osascript -e 'choose file'
    alias Macintosh HD:Users:chewxy:workspace:gorgoniaws:src:stuff:cmd:train:checkpoint.0
    
    $  osascript -e 'choose folder'
    alias Macintosh HD:Users:chewxy:workspace:gorgoniaws:src:stuff:cmd:train:images:
    

    Observe that when "choose folder". is used as the script, there is a trailing :, but when "choose file" is used, there are no trailing :

    Hence it can be deduced that the reason for dropping the last element is because the function wishes to handle directories.

    Upon further investigation, it's noted that strings.Join was used. This is not recommended practice. Instead, the proper path handling library, which is built into the stdlib of Go should be used.

    Thus, the functions have been amended to use the proper path library.

  • Implement simple MessageBox dialog, where no icon will be displayed.

    Implement simple MessageBox dialog, where no icon will be displayed.

    In some cases it was necessary to have a dialog without the icon. Especially on macOS where the dialog's text gets squeezed due to the icon being too big, making it look a little odd. On Linux I made it display as info, since I don't know of a way to disable icons using zenity.

  • fix dirDialog: incorrect result if path too short

    fix dirDialog: incorrect result if path too short

    This pull request is related to issue #20 .

    Platform: Windows 10 Summary: if a user selects the root of a disk / USB device (file picker), then the returned file path is incorrect. Example: user selects the root of disk C C:\ but the return value is C:\l Disk (C:). This bug seems to be related to the length of the file path which the user had selected. If the user selects a child directory (not the root of a disk/device), then the correct file path is returned. I tested this change on Windows 10 64 Bit.

    For an explanation please read the comment by @ncruces: https://github.com/gen2brain/dlgs/issues/20#issuecomment-813522377

  • Allow for alerts to fire from any user.

    Allow for alerts to fire from any user.

    While using this library to fire alerts for a golang app (more specifically an osquery plugin) which runs as root, alerts wouldn't fire as root had no logged in session. Setting the osascript to tell application "System Events" made the alert popup on the currently logged in users screen.

  • Error handling is bogus

    Error handling is bogus

    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.
    • Any returned error is a exec Error...

    With the current logic, we cannot properly distinguish between this.

  • Causes False Positive Windows 10

    Causes False Positive Windows 10

    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

  • Any plans on having a CLI?

    Any plans on having a CLI?

    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.

  • File filters not working on MacOS

    File filters not working on MacOS

    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.

  • FileMulti can only choose 10 files cant more

    FileMulti can only choose 10 files cant more

    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
    }
    
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Dec 28, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Jan 1, 2023
An experimental Go cross platform UI library.

GXUI - A Go cross platform UI library. Notice: Unfortunately due to a shortage of hours in a day, GXUI is no longer maintained. If you're looking for

Jan 6, 2023
Cross-platform Go library to place an icon in the host operating system's taskbar.

trayhost Package trayhost is a cross-platform Go library to place an icon in the host operating system's taskbar. Platform Support macOS - Fully imple

Nov 6, 2022
Cross-platform Go/Golang GUI library.

中文 | English GoVCL Cross-platform Golang GUI library, The core binding is liblcl, a common cross-platform GUI library created by Lazarus. GoVCL is a n

Dec 30, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electr

Jan 9, 2023
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)

gowd Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) How to use this library: Download and install nwjs Install this library g

Dec 11, 2022
Cross-platform GUI for go is never this easy and clean.
Cross-platform GUI for go is never this easy and clean.

gimu Strongly suggest NOT to use this project anymore, the auto-generated cgo wrapper of Nuklear has a random crash issue which is hard to fix (becaus

Jul 12, 2022
Cross platform GUI in Go based on Material Design
Cross platform GUI in Go based on Material Design

About Fyne is an easy to use UI toolkit and app API written in Go. It is designed to build applications that run on desktop and mobile devices with a

Jan 3, 2023
Build cross-platform modern desktop apps in Go + HTML5
Build cross-platform modern desktop apps in Go + HTML5

Lorca A very small library to build modern HTML5 desktop apps in Go. It uses Chrome browser as a UI layer. Unlike Electron it doesn't bundle Chrome in

Jan 6, 2023
RobotGo, Go Native cross-platform GUI automation @vcaesar

Robotgo Golang Desktop Automation. Control the mouse, keyboard, bitmap, read the screen, Window Handle and global event listener. RobotGo supports Mac

Jan 7, 2023
A cross-platform app-development module for Go.
A cross-platform app-development module for Go.

The cross-platform Go module for building apps (pronounced klo-va-seed). Usecases As a lightweight alternative to Electron Write your frontend and nat

Dec 1, 2022
pure go, cross-platform, MIT-licensed ui toolkit for developers
pure go, cross-platform, MIT-licensed ui toolkit for developers

duit - developer ui toolkit WARNING: this library is work in progress. backwards incompatible changes will be made. details duit is a pure go (*), cro

Dec 24, 2022
Cross platform rapid GUI framework for golang based on Dear ImGui.
Cross platform rapid GUI framework for golang based on Dear ImGui.

giu Cross platform rapid GUI framework for golang based on Dear ImGui and the great golang binding imgui-go. Any contribution (features, widgets, tuto

Dec 28, 2022
Cross-Platform GUI Framework for Go

⚠️ I'm currently working on this project as part of my master's thesis at the Berlin University of Applied Sciences and Technology. It is under active

Oct 31, 2022
Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase
Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase. Inspired by Flutter, React. S

Apr 18, 2022
UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase
 UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

Apr 18, 2022
edotool: simulate keyboard input and mouse activity
edotool: simulate keyboard input and mouse activity

edotool Simulate keystrokes. Like xdotool (well, kind of), with support for both X11 and Wayland. edotool Screengrab Using edotool keystrokes can be s

Oct 27, 2022
a cross platfrom Go library to place an icon and menu in the notification area

systray is a cross-platform Go library to place an icon and menu in the notification area. Features Supported on Windows, macOS, and Linux Menu items

Dec 27, 2022