2020-01-10 20:41:13 -05:00
|
|
|
// Code generated by zenity; DO NOT EDIT.
|
2022-03-24 10:37:37 -04:00
|
|
|
//go:build darwin
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
package zenutil
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2021-04-08 12:23:17 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"text/template"
|
|
|
|
)
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2020-01-21 07:03:58 -05:00
|
|
|
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
|
|
|
b, err := json.Marshal(v)
|
|
|
|
return string(b), err
|
|
|
|
}}).Parse(`
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "color" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
2021-02-18 21:20:57 -05:00
|
|
|
app.activate()
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
try{var res=app.chooseColor({defaultColor:{{json .}}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2022-03-26 20:05:52 -04:00
|
|
|
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
2020-01-21 07:03:58 -05:00
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
{{define "date" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
|
|
|
ObjC.import('Cocoa')
|
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
var date=$.NSDatePicker.alloc.init
|
|
|
|
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
|
|
|
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
|
|
|
date.setFrameSize(date.fittingSize)
|
2022-03-30 10:36:50 -04:00
|
|
|
{{- if .Date}}
|
|
|
|
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
var alert=$.NSAlert.alloc.init
|
|
|
|
alert.setAccessoryView(date)
|
|
|
|
alert.setMessageText({{json .Text}})
|
2022-03-28 15:22:39 -04:00
|
|
|
alert.addButtonWithTitle({{json .OK}})
|
|
|
|
alert.addButtonWithTitle({{json .Cancel}}).keyEquivalent='\033'
|
|
|
|
{{- if .Info}}
|
|
|
|
alert.setInformativeText({{json .Info}})
|
|
|
|
{{- end}}
|
|
|
|
{{- if .Extra}}
|
|
|
|
alert.addButtonWithTitle({{json .Extra}})
|
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
var res=alert.runModal
|
2022-03-28 15:22:39 -04:00
|
|
|
switch(res){case $.NSAlertThirdButtonReturn:$.puts({{json .Extra}})
|
2022-03-24 12:15:11 -04:00
|
|
|
case $.NSAlertSecondButtonReturn:$.exit(1)}
|
|
|
|
var fmt=$.NSDateFormatter.alloc.init
|
2022-05-11 12:49:15 -04:00
|
|
|
fmt.locale=$.NSLocale.localeWithLocaleIdentifier('en_US_POSIX')
|
2022-05-06 08:48:31 -04:00
|
|
|
fmt.dateFormat={{json .Format}}
|
2022-03-24 12:15:11 -04:00
|
|
|
fmt.stringFromDate(date.dateValue)
|
|
|
|
{{- end}}
|
2021-03-04 21:01:59 -05:00
|
|
|
{{define "dialog" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
2020-01-10 20:41:13 -05:00
|
|
|
app.activate()
|
2022-05-05 08:03:53 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
var opts={{json .Options}}
|
2021-10-06 18:39:36 -04:00
|
|
|
{{- if .IconPath}}
|
2022-05-05 08:03:53 -04:00
|
|
|
opts.withIcon=Path({{json .IconPath}})
|
2021-10-06 18:39:36 -04:00
|
|
|
{{- end}}
|
2022-05-06 08:48:31 -04:00
|
|
|
try{var res=app.{{.Operation}}({{json .Text}},opts)}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2021-03-03 21:52:05 -05:00
|
|
|
if(res.gaveUp){$.exit(5)}
|
2022-05-11 12:49:15 -04:00
|
|
|
if(res.buttonReturned==={{json .Extra}}){$.puts({{json .Extra}})
|
2021-03-03 21:52:05 -05:00
|
|
|
$.exit(1)}
|
2021-03-04 21:01:59 -05:00
|
|
|
res.textReturned
|
|
|
|
{{- end}}
|
|
|
|
{{define "file" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
try{var res=app.{{.Operation}}({{json .Options}})}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
2021-03-04 21:01:59 -05:00
|
|
|
if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
|
2020-01-26 11:04:49 -05:00
|
|
|
{{- end}}
|
2021-04-07 09:16:35 -04:00
|
|
|
{{define "list" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
2022-05-06 08:48:31 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
try{var res=app.chooseFromList({{json .Items}},{{json .Options}})}catch(e){$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
|
|
|
if(res===false)$.exit(1)
|
2021-07-08 13:56:28 -04:00
|
|
|
if(res.length!==0)res.join({{json .Separator}})
|
2021-04-07 09:16:35 -04:00
|
|
|
{{- end}}
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "notify" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
void app.displayNotification({{json .Text}},{{json .Options}})
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- end}}
|
|
|
|
{{define "progress" -}}
|
2021-04-22 10:03:08 -04:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
ObjC.import('readline')
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- if .Total}}
|
|
|
|
Progress.totalUnitCount={{.Total}}
|
|
|
|
{{- end}}
|
|
|
|
{{- if .Description}}
|
|
|
|
Progress.description={{json .Description}}
|
|
|
|
{{- end}}
|
2022-05-06 08:48:31 -04:00
|
|
|
while(true){try{var s=$.readline('')}catch(e){if(e.errorNumber===-128)$.exit(1)
|
2021-04-22 10:03:08 -04:00
|
|
|
break}
|
2021-04-25 13:34:56 -04:00
|
|
|
if(s.indexOf('#')===0){Progress.additionalDescription=s.slice(1)
|
2021-04-22 10:03:08 -04:00
|
|
|
continue}
|
|
|
|
var i=parseInt(s)
|
2022-05-06 08:48:31 -04:00
|
|
|
if(i>=0&&Progress.totalUnitCount>0){Progress.completedUnitCount=i}}
|
2022-05-11 12:49:15 -04:00
|
|
|
{{- end}}
|
|
|
|
{{define "pwd" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
var opts={{json .Options}}
|
|
|
|
{{- if .IconPath}}
|
|
|
|
opts.withIcon=Path({{json .IconPath}})
|
|
|
|
{{- end}}
|
|
|
|
function dialog(text){try{var res=app.displayDialog(text,opts)}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
$.dprintf(2,e)
|
|
|
|
$.exit(-1)}
|
|
|
|
if(res.gaveUp){$.exit(5)}
|
|
|
|
if(res.buttonReturned==={{json .Extra}}){$.puts({{json .Extra}})
|
|
|
|
$.exit(1)}
|
|
|
|
return res.textReturned}
|
|
|
|
var start=Date.now()
|
|
|
|
opts.defaultAnswer=''
|
|
|
|
var username=dialog('Username:')
|
|
|
|
{{- if .Options.Timeout}}
|
|
|
|
opts.givingUpAfter-=(Date.now()-start)/1000|0
|
|
|
|
{{- end}}
|
|
|
|
opts.hiddenAnswer=true
|
|
|
|
var password=dialog('Password:')
|
|
|
|
username+{{json .Separator}}+password
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- end}}`))
|