From 57833a0ebbb74fa69c68bdb9a3ec8c737849c363 Mon Sep 17 00:00:00 2001 From: Alexandre Gobbo Date: Thu, 10 Jun 2021 16:37:43 +0200 Subject: [PATCH] Option -y to force headless mode --- src/main/assembly/help/Startup Options.md | 6 +++++- src/main/java/ch/psi/pshell/ui/App.java | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/assembly/help/Startup Options.md b/src/main/assembly/help/Startup Options.md index 2b61c2c9..d722b6a9 100644 --- a/src/main/assembly/help/Startup Options.md +++ b/src/main/assembly/help/Startup Options.md @@ -83,8 +83,12 @@ -a - tAuto close after executing file. + Auto close after executing file. + + -y + Force headless mode. + -z . diff --git a/src/main/java/ch/psi/pshell/ui/App.java b/src/main/java/ch/psi/pshell/ui/App.java index ad8fb45b..67902ad2 100644 --- a/src/main/java/ch/psi/pshell/ui/App.java +++ b/src/main/java/ch/psi/pshell/ui/App.java @@ -98,6 +98,10 @@ static public void main(String[] args) { static public void init(String[] args) { arguments = args; + if (isForcedHeadless()) { + System.setProperty("java.awt.headless", "true"); + } + Level consoleLogLevel = Level.WARNING; try { consoleLogLevel = Level.parse(getArgumentValue("clog")); @@ -353,6 +357,7 @@ static String getHelpMessage() { sb.append("\n\t-n\tInterpreter is not started"); sb.append("\n\t-q\tQuiet mode"); sb.append("\n\t-a\tAuto close after executing file"); + sb.append("\n\t-y\tHeadless mode"); sb.append("\n\t-z\tHome folder is volatile (created in tmp folder)"); sb.append("\n\t-home=\tSet the home folder (default is ./home)"); sb.append("\n\t-outp=\tSet the output folder (default is {home})"); @@ -695,10 +700,18 @@ static public boolean isDisabled() { return getBoolArgumentValue("n"); } + static public boolean isHelpMessage() { + return hasArgument("h"); + } + static public boolean isHeadless() { return GraphicsEnvironment.isHeadless(); } + static public boolean isForcedHeadless() { + return getBoolArgumentValue("y") || isHelpMessage() ; + } + //Resources static public String getResourceBundleValue(String key) { return getResourceBundleValue(App.class, key); @@ -789,7 +802,7 @@ static public class PshellProperties extends Config { protected void startup() { System.out.println("Version " + getApplicationBuildInfo()); - if (hasArgument("h")) { + if (isHelpMessage()) { System.out.println(getHelpMessage()); return; }