use of suite.os.Execute in project suite by stupidsing.
the class Hkex method query.
private JsonNode query(String url) {
JsonNode json;
if (Boolean.TRUE)
try (InputStream is = Singleton.me.storeCache.http(url).collect(To::inputStream)) {
json = mapper.readTree(is);
} catch (IOException ex) {
json = Fail.t(ex);
}
else {
Execute execute = new Execute(new String[] { "curl", url });
json = Rethrow.ex(() -> mapper.readTree(execute.out));
}
return json;
}
use of suite.os.Execute in project suite by stupidsing.
the class OtfTest method otfTest.
@Test
public void otfTest() {
String familyKey = "Family";
String subfamilyKey = "Subfamily";
List<String> keys = List.of(familyKey, subfamilyKey);
List<String> commands = //
Read.each(//
"/tmp/fonts").map(//
Paths::get).concatMap(//
FileUtil::findPaths).map(//
Path::toString).filter(path -> {
String pathl = path.toLowerCase();
return pathl.endsWith(".otf") || pathl.endsWith(".ttf");
}).map2(path -> {
Execute exec = new Execute(new String[] { "otfinfo", "-i", path });
return //
Read.from(//
exec.out.split("\n")).map(//
line -> line.split(":")).filter(//
arr -> 2 <= arr.length).map2(arr -> arr[0].trim(), //
arr -> arr[1].trim()).filterKey(//
keys::contains).toMap();
}).map((k, m) -> {
String f = m.get(familyKey);
String sf = m.get(subfamilyKey);
String dir = "/home/ywsing/.fonts/" + f + "/";
String ext = k.substring(k.lastIndexOf(".") + 1).toLowerCase();
return "mkdir -p '" + dir + "'; mv '" + k + "' '" + dir + f + " " + sf + "." + ext + "'";
}).sort(//
Object_::compare).toList();
for (String command : commands) System.out.println(command);
}
use of suite.os.Execute in project suite by stupidsing.
the class PopupMain method run.
@Override
protected boolean run(String[] args) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int centerX = screenSize.width / 2, centerY = screenSize.height / 2;
int width = screenSize.width / 2, height = screenSize.height / 8;
JTextField inTextField = new JTextField();
inTextField.setFont(new FontUtil().monoFont);
inTextField.addActionListener(event -> {
execute(inTextField.getText());
System.exit(0);
});
JLabel outLabel = new JLabel();
JFrame frame = new JFrame("Pop-up");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(centerX - width / 2, centerY - height / 2);
frame.setSize(new Dimension(width, height));
frame.setVisible(true);
Fun<String, Execute> volumeControl = (String c) -> {
inTextField.requestFocusInWindow();
return new Execute(new String[] { "/usr/bin/amixer", "set", "PCM", "2" + c });
};
JLabel volLabel = new JLabel("Volume");
JButton volUpButton = new JButton("+");
volUpButton.setMnemonic(KeyEvent.VK_A);
volUpButton.addActionListener(event -> volumeControl.apply("+"));
JButton volDnButton = new JButton("-");
volDnButton.setMnemonic(KeyEvent.VK_Z);
volDnButton.addActionListener(event -> volumeControl.apply("-"));
LayoutCalculator lay = new LayoutCalculator(frame.getContentPane());
Node layout = //
lay.boxv(lay.fx(32, //
lay.boxh(//
lay.ex(32, lay.c(inTextField)), //
lay.fx(64, lay.c(volLabel)), //
lay.fx(48, lay.c(volUpButton)), //
lay.fx(48, lay.c(volDnButton)))), lay.ex(32, lay.c(outLabel)));
Runnable refresh = () -> {
lay.arrange(layout);
frame.repaint();
};
Listen.componentResized(frame).wire(refresh::run);
refresh.run();
System.in.read();
return true;
}
Aggregations