Search in sources :

Example 1 with Execute

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;
}
Also used : Execute(suite.os.Execute) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 2 with Execute

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);
}
Also used : Execute(suite.os.Execute) List(java.util.List) Read(suite.streamlet.Read) Object_(suite.util.Object_) Paths(java.nio.file.Paths) FileUtil(suite.os.FileUtil) Test(org.junit.Test) Path(java.nio.file.Path) Execute(suite.os.Execute) FileUtil(suite.os.FileUtil) Test(org.junit.Test)

Example 3 with Execute

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;
}
Also used : Execute(suite.os.Execute) Node(suite.editor.LayoutCalculator.Node) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) LayoutCalculator(suite.editor.LayoutCalculator) JFrame(javax.swing.JFrame) FontUtil(suite.editor.FontUtil)

Aggregations

Execute (suite.os.Execute)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 JButton (javax.swing.JButton)1 JFrame (javax.swing.JFrame)1 JLabel (javax.swing.JLabel)1 JTextField (javax.swing.JTextField)1 Test (org.junit.Test)1 FontUtil (suite.editor.FontUtil)1 LayoutCalculator (suite.editor.LayoutCalculator)1 Node (suite.editor.LayoutCalculator.Node)1 FileUtil (suite.os.FileUtil)1 Read (suite.streamlet.Read)1 Object_ (suite.util.Object_)1