Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ttytm/dialog
A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.
https://github.com/ttytm/dialog
cross-platform dialog file filesystem gtk2 gtk3 library linux macos operating-system os ui windows
Last synced: 7 days ago
JSON representation
A cross-platform utility library for V to open system dialogs - open files, message boxes, color-pickers etc.
- Host: GitHub
- URL: https://github.com/ttytm/dialog
- Owner: ttytm
- License: mit
- Created: 2023-10-06T23:14:58.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-17T18:53:48.000Z (22 days ago)
- Last Synced: 2024-10-25T09:10:17.386Z (14 days ago)
- Topics: cross-platform, dialog, file, filesystem, gtk2, gtk3, library, linux, macos, operating-system, os, ui, windows
- Language: V
- Homepage: https://ttytm.github.io/dialog/
- Size: 30.3 KB
- Stars: 22
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-v - dialog - A cross-platform utility library to open system dialogs - open files, message boxes, color-pickers etc. (Libraries / Utility)
README
# dialog
> A cross-platform utility library for V to open system dialogs - open files, message boxes,
> color-pickers etc.## Showcase
Linux
Windows
macOS
Toggle More
Linux
Windows
macOS
## Installation
```sh
v install https://github.com/ttytm/dialog
```On macOS, `dialog` currently uses V webview to ensure it can interop with system windows.
```sh
# macOS only dependency
v install https://github.com/ttytm/webview
~/.vmodules/webview/build.vsh
```## Usage
```v ignore
// message launches a message box and returns `true` if `OK` or `Yes` was pressed.
pub fn message(message string, opts MessageOptions) bool// prompt launches an input prompt with an "OK" and "Cancel" button.
pub fn prompt(message string, opts PromptOptions) ?string// file_dialog opens a file dialog and returns the selected path or `none` if the selection was canceled.
pub fn file_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 fn open_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 fn read_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 fn open_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 fn save_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 fn color_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](https://ttytm.github.io/dialog/dialog.html) in the browser.### Example
```v
module mainimport dialog
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)
``````sh
v run examples/minimal.v
```> [!TIP]
> When running and building on Windows, it is recommended to use `gcc` for compilation. E.g.:
>
> ```sh
> 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](https://github.com/AndrewBelt/osdialog) - C project that `dialog` binds to.
- [vlang/v](https://github.com/vlang/v) - Simple-to-use, developer-friendly system programming with
high interoperability.