Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS built-in color picker capability #84

Merged
merged 1 commit into from Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cli/cli.rs
Expand Up @@ -175,7 +175,8 @@ pub fn build_cli() -> App<'static, 'static> {
- grabc (https://www.muquit.com/muquit/software/grabc/grabc.html)\n \
- colorpicker (https://github.com/Jack12816/colorpicker)\n \
- chameleon (https://github.com/seebye/chameleon)\n \
- KColorChooser (https://kde.org/applications/graphics/org.kde.kcolorchooser)")
- KColorChooser (https://kde.org/applications/graphics/org.kde.kcolorchooser)\n \
- macOS built-in color picker")
)
.subcommand(
SubCommand::with_name("format")
Expand Down
20 changes: 19 additions & 1 deletion src/cli/colorpicker.rs
Expand Up @@ -61,9 +61,27 @@ struct ColorPickerTool {
version_output_starts_with: &'static [u8],
}

/// Run an external X11 color picker tool (e.g. gpick or xcolor) and get the output as a string.
/// Run an external color picker tool (e.g. gpick or xcolor) and get the output as a string.
pub fn run_external_colorpicker() -> Result<String> {
let tools = [
#[cfg(target_os = "macos")]
ColorPickerTool {
command: "osascript",
// NOTE: This does not use `console.log` to print the value as you might expect,
// because that gets written to stderr instead of stdout regardless of the `-s o` flag.
// (This is accurate as of macOS Mojave/10.14.6).
// See related: https://apple.stackexchange.com/a/278395
args: vec!["-l", "JavaScript", "-s", "o", "-e", "
const app = Application.currentApplication();\n
app.includeStandardAdditions = true;\n
const rgb = app.chooseColor({defaultColor: [0.5, 0.5, 0.5]})\n
.map(n => Math.round(n * 255))\n
.join(', ');\n
`rgb(${rgb})`;\n
"],
version_args: vec!["-l", "JavaScript", "-s", "o", "-e", "'ok';"],
version_output_starts_with: b"ok",
},
ColorPickerTool {
command: "gpick",
args: vec!["--pick", "--single", "--output"],
Expand Down