Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

# dialog

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

## Showcase


Linux
Windows
macOS



Linux File Dialog


Windows File Dialog


macOS File Dialog

Toggle More


Linux
Windows
macOS



Linux Color Picker GTK3
Linux Message
Linux Message with Yes and No Buttons
Linux Input Prompt
Linux Color Picker GTK2


Windows Color Picker
Windows Message
Windows Message with Yes and No Buttons
Windows Input Prompt


macOS Message
macOS Message with Yes and No Buttons
macOS Input Prompt

## 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 main

import 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.