是否可以打印"扩展ASCII代码 "来自" http://www.asciitable.com/"在Terminal.app bash脚本中?
我尝试了什么
$ LC_ALL=en_GB.UTF-8 env printf '\u2502'
u2502
$
特别是我试图打印" LIGHT SHADE"中提到的人物 http://www.alanflavell.org.uk/unicode/unidata25.html
答案 0 :(得分:0)
echo,printf和import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.concurrent.ExecutionException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
public class TextAreaUpdater {
private JFrame frame;
private JTextArea area;
private JButton button;
private SwingWorker<String, String> worker;
public static void main(String[] args) {
SwingUtilities.invokeLater(new TextAreaUpdater()::createAndShowGui);
}
private void createAndShowGui() {
frame = new JFrame(getClass().getSimpleName());
area = new JTextArea(10, 30);
button = new JButton("Update!");
button.addActionListener(listener);
worker = new SwingWorker<String, String>() {
@Override
protected String doInBackground() throws Exception {
try {
Thread.sleep(5000); //Simulates long running task
} catch (InterruptedException e) {
e.printStackTrace();
}
return "I'm done!"; //Returns the text to be set on the JTextArea
}
@Override
protected void done() {
super.done();
try {
area.setText(get()); //Set the textArea the text given from the long running task
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
};
frame.add(area, BorderLayout.CENTER);
frame.add(button, BorderLayout.SOUTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private ActionListener listener = (e -> {
area.setText("Processing...");
worker.execute(); //Initializes long running task
});
}
的{{1}}和SwingWorker
转义码是Bash 4.2中的新增代码。 MacOS附带Bash 3.2。
您可以直接在脚本中对字符进行编码:\uHHHH
。唯一的区别是您的脚本不会自动在目标字符集中写入字符,但会以UTF-8硬编码。
根据您的可移植性要求,您还可以使用自制软件安装现代版本的Bash和GNU Coreutils。
\UHHHHHHHH