Skip to content

Repository files navigation

dialog

A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.

Showcase

LinuxWindowsmacOS
Linux File DialogWindows File DialogmacOS File Dialog
Toggle More
LinuxWindowsmacOS
Linux Color Picker GTK3Linux MessageLinux Message with Yes and No ButtonsLinux Input PromptLinux Color Picker GTK2Windows Color PickerWindows MessageWindows Message with Yes and No ButtonsWindows Input PromptmacOS MessagemacOS Message with Yes and No ButtonsmacOS Input Prompt

Installation

v install https://github.com/ttytm/dialog

On macOS, dialog currently uses V webview to ensure it can interop with system windows.

# macOS only dependency
v install https://github.com/ttytm/webview
~/.vmodules/webview/build.vsh

Usage

// message launches a message box and returns `true` if `OK` or `Yes` was pressed.pub fnmessage(message string, opts MessageOptions) bool// prompt launches an input prompt with an "OK" and "Cancel" button.pub fnprompt(message string, opts PromptOptions) ?string// file_dialog opens a file dialog and returns the selected path or `none` if the selection was canceled.pub fnfile_dialog(opts FileDialogOptions) ?string// open_file opens a file dialog and returns the `os.File` of the selected file.// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.// It returns an error if the selection was cancelled or if reading the file fails.pub fnopen_file(opts FileOpenOptions) !os.File
// read_file opens a file dialog and reads the file contents of the selected file.// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.// It returns an error if the selection was cancelled or if reading the file fails.pub fnread_file(opts FileOpenOptions) !string// open_dir opens a file dialog and returns the path of the selected directory and a list of its contents.// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.// It returns an error if the selection was cancelled or if reading the directory contents fails.pub fnopen_dir(opts FileOpenOptions) !(string, []string)
// save_file opens a file dialog and saves the given content to the selected path.// Optionally, `path` can be specified as the default folder the dialog will attempt to open in.// `filename` can be provided to set the default text that will appear in the filename input.// It returns an error if the selection was canceled or if writing the file fails.pub fnsave_file(opts FileSaveOptions) !// color_picker opens an RGBA color picker dialog and returns the selected color or `none` if the// selection was canceled. Optionally, it takes a `color` and `opacity` argument. `color` sets the// dialogs initial color. `opacity` can be set to `false` to disable the opacity slider on Linux.pub fncolor_picker(opts ColorPickerOptions) ?Color

Note

v doc provides an overview of all public definitions.
Use v doc -comments dialog in the terminal, or refer to the module's doc pages in the browser.

Example

modulemainimportdialog
dialog.message('Thanks for using dialog!')
if!dialog.message('Do you want to continue?', buttons: .yes_no) {
dump('Canceled!')
}
input:= dialog.prompt('What is your pets name?')
dump(input)
selected_file:= dialog.file_dialog()
dump(selected_file)
selected_color:= dialog.color_picker()
dump(selected_color)
v run examples/minimal.v

Tip

When running and building on Windows, it is recommended to use gcc for compilation. E.g.:

v -cc gcc run examples/minimal.v

Disclaimer

The project is made public in an early stage. Best practices and quality will be paramount throughout development, but it may undergo drastic changes while maturing.

If the library could already achieve it's goal of also helping your project, or just to share some love, filling the ☆ of this repo with color will warm the heart of your fellow developer.

Credits

  • AndrewBelt/osdialog - C project that dialog binds to.
  • vlang/v - Simple-to-use, developer-friendly system programming with high interoperability.

About

A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.

Topics

Resources

Stars

34 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages