1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-14 21:35:03 -05:00
filebot/website/scripts/escape.groovy

31 lines
879 B
Groovy
Raw Normal View History

def escapeShell(String arg) {
return '"' + arg.replaceAll(/["$`<>^\\"']/, /\\$0/) + '"'
}
if (java.awt.GraphicsEnvironment.headless && console != null) {
// CLI mode
console.printf('Enter: ')
def s = console.readLine()
console.println('\n' + escapeShell(s) + '\n')
System.exit(0)
} else {
// GUI mode
2013-10-31 11:23:43 -04:00
new groovy.swing.SwingBuilder().edt{
frame(title: 'Escape Tool', size: [350, 230], show: true, defaultCloseOperation: javax.swing.JFrame.EXIT_ON_CLOSE) {
gridLayout(cols: 1, rows: 2)
2013-10-31 11:23:43 -04:00
scrollPane{
textArea id: 'value', lineWrap: true, font: new java.awt.Font('Monospaced', 0, 16)
}
scrollPane{
textArea id: 'escape', lineWrap: true, text: bind(source:value, sourceProperty:'text', converter: { escapeShell(it) }), font: new java.awt.Font('Monospaced', 0, 16)
}
}
}
System.in.read() // wait for GUI to close
}