本文主要是介绍Xshell配色转WindowsTerminal配色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. 本文目标
将Xshell
中的配色方案迁移到WindowsTerminal
中使用。
- 将Xshell配色方案导出
- 更改字符集为UTF-8
- 通过Java程序将Xshell配色方案转变成Windows Terminal配色方案
- 配置Windows Terminal
2. 操作步骤
2.1 导出Xshell配色
在Xshell菜单栏中依次点击工具->配色方案,会弹出选择配色方案窗口。在窗口中选择(按住Ctrl可以多选)想要导出的配色方案,然后点击导出按钮,本文以导出New Black、New White、XTerm为例,如下图所示:
选择要导出的目录,本文以D://data/
为例,文件名为ColorSchemes.xcs
2.2 更改字符集为UTF-8
Xshell6导出的配色方案默认是
UCS-2 Little Endian
编码,Java:StandardCharsets.UTF_16LE
本文将采用UTF-8进行解析,所以需要将字符集改为UTF-8,使用Notepad++打开在菜单栏中点击编码->使用UTF-8编码,然后点击保存按钮。
2.3 配色方案转换
需要调整的地方为导出配色方案的路径,本例为D:\data\ColorSchemes.xcs
package terminal;import com.alibaba.fastjson.JSON;import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;/*** Xshell配色转WindowsTerminal配色** @author faith.huan 2020-01-31*/
public class ColorXshellToWinTerminal {public static void main(String[] args) throws IOException {InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\\data\\ColorSchemes.xcs"), StandardCharsets.UTF_8);Map<String, Map<String, String>> map = new HashMap<>(300);BufferedReader reader = new BufferedReader(inputStreamReader);String line = reader.readLine();String key = "";while (line != null) {// System.out.println("line = " + line);if (line.startsWith("[")) {key = line.substring(1, line.length() - 1);// System.out.println(key);} else {String[] split = line.split("=");if (!"Names".equals(key) && split.length == 2) {String fieldName = fieldMap.get(split[0]);if (fieldName != null) {String fieldValue = "#" + split[1];if (map.containsKey(key)) {map.get(key).put(fieldName, fieldValue);} else {Map<String, String> m = new TreeMap<>(new FieldComparator());m.put("name", key);m.put(fieldName, fieldValue);map.put(key, m);}}}}line = reader.readLine();}System.out.println(JSON.toJSONString(map.values(), true));}private static Map<String, String> fieldMap = new HashMap<>();static {/** 定义Xshell配色字段与WinTerminal配色字段映射关系*/fieldMap.put("text", "foreground");fieldMap.put("background", "background");fieldMap.put("black", "black");fieldMap.put("black(bold)", "brightBlack");fieldMap.put("red", "red");fieldMap.put("red(bold)", "brightRed");fieldMap.put("green", "green");fieldMap.put("green(bold)", "brightGreen");fieldMap.put("yellow", "yellow");fieldMap.put("yellow(bold)", "brightYellow");fieldMap.put("blue", "blue");fieldMap.put("blue(bold)", "brightBlue");fieldMap.put("magenta", "purple");fieldMap.put("magenta(bold)", "brightPurple");fieldMap.put("cyan", "cyan");fieldMap.put("cyan(bold)", "brightCyan");fieldMap.put("white", "white");fieldMap.put("white(bold)", "brightWhite");fieldMap.put("text(bold)", null);fieldMap.put(null, null);}/*** 控制输出的Window Terminal 配色方案字段排序*/static class FieldComparator implements Comparator<String> {private Map<String, Integer> orderMap = new HashMap<>();FieldComparator() {orderMap.put("name", 1);orderMap.put("foreground", 2);orderMap.put("background", 3);orderMap.put("black", 4);orderMap.put("red", 5);orderMap.put("green", 6);orderMap.put("yellow", 7);orderMap.put("blue", 8);orderMap.put("purple", 9);orderMap.put("cyan", 10);orderMap.put("white", 11);orderMap.put("brightBlack", 12);orderMap.put("brightRed", 13);orderMap.put("brightGreen", 14);orderMap.put("brightYellow", 15);orderMap.put("brightBlue", 16);orderMap.put("brightPurple", 17);orderMap.put("brightCyan", 18);orderMap.put("brightWhite", 19);}@Overridepublic int compare(String o1, String o2) {return orderMap.get(o1).compareTo(orderMap.get(o2));}}}
运行上面的Java代码会在控制台中输出如下json内容
[{"name":"XTerm","foreground":"#e5e5e5","background":"#002B36","black":"#000000","red":"#bb0000","green":"#006400","yellow":"#c8af00","blue":"#1e90f5","purple":"#bb00bb","cyan":"#00cdcd","white":"#ebebeb","brightBlack":"#555555","brightRed":"#ff5555","brightGreen":"#55ff55","brightYellow":"#fff555","brightBlue":"#50beff","brightPurple":"#ff55ff","brightCyan":"#55ffff","brightWhite":"#ffffff"
},{"name":"New White","foreground":"#292929","background":"#ffffff","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#0000cc","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#2929ef","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"
},{"name":"New Black","foreground":"#f2f2f2","background":"#242424","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#4646ff","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#6f6ff4","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"
}]
2.4 配置Windows Terminal
依次点击**﹀**->Settings,然后选择一个文本编辑器(此处使用Notepad++)打开配置文件文件。
将上文生成的json数组内容(不包括开始符[
,结束符]
),复制到刚才打开的配置文件profiles.json
中的"schemes": [],
段的中括号内,如下所示。
"schemes": [{"name":"XTerm","foreground":"#e5e5e5","background":"#002B36","black":"#000000","red":"#bb0000","green":"#006400","yellow":"#c8af00","blue":"#1e90f5","purple":"#bb00bb","cyan":"#00cdcd","white":"#ebebeb","brightBlack":"#555555","brightRed":"#ff5555","brightGreen":"#55ff55","brightYellow":"#fff555","brightBlue":"#50beff","brightPurple":"#ff55ff","brightCyan":"#55ffff","brightWhite":"#ffffff"},{"name":"New White","foreground":"#292929","background":"#ffffff","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#0000cc","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#2929ef","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"},{"name":"New Black","foreground":"#f2f2f2","background":"#242424","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#4646ff","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#6f6ff4","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"}],
启用XTerm
配色方案,以ubuntu18.04为例,使用colorScheme
指定配色方案XTerm
"profiles":[{"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}","hidden": false,"name": "Ubuntu-18.04","source": "Windows.Terminal.Wsl","colorScheme": "XTerm","icon":"D://javaDev/pic/u18.ico","startingDirectory" : "//wsl$/Ubuntu-18.04/home/faith"},...]
3. 配色展示
3.1 XTerm配色
3.1 New White配色
3.3 New Black配色
图标下载地址:https://www.easyicon.net/ ,Tab上的图标下载32*32的即可,太大会模糊
完整profiles.json
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation{"$schema": "https://aka.ms/terminal-profiles-schema","defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}","copyOnSelect": true,"profiles":[{"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}","hidden": false,"name": "Ubuntu-18.04","source": "Windows.Terminal.Wsl","colorScheme": "XTerm","icon":"D://javaDev/pic/u18.ico","startingDirectory" : "//wsl$/Ubuntu-18.04/home/faith"},{"guid": "{6f9994f0-4403-5e85-9cce-98e5da3839bb}","hidden": false,"name": "Ubuntu-16.04","source": "Windows.Terminal.Wsl","colorScheme": "XTerm","icon": "D://JavaDev/pic/u16.ico","startingDirectory" : "//wsl$/Ubuntu-16.04/home/faith"},{// Make changes here to the powershell.exe profile"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}","name": "Windows PowerShell","commandline": "powershell.exe","hidden": false},{// Make changes here to the cmd.exe profile"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}","name": "cmd","commandline": "cmd.exe","hidden": false},{"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}","hidden": true,"name": "Azure Cloud Shell","source": "Windows.Terminal.Azure"}],// Add custom color schemes to this array"schemes": [{"name":"XTerm","foreground":"#e5e5e5","background":"#002B36","black":"#000000","red":"#bb0000","green":"#006400","yellow":"#c8af00","blue":"#1e90f5","purple":"#bb00bb","cyan":"#00cdcd","white":"#ebebeb","brightBlack":"#555555","brightRed":"#ff5555","brightGreen":"#55ff55","brightYellow":"#fff555","brightBlue":"#50beff","brightPurple":"#ff55ff","brightCyan":"#55ffff","brightWhite":"#ffffff"},{"name":"New White","foreground":"#292929","background":"#ffffff","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#0000cc","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#2929ef","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"},{"name":"New Black","foreground":"#f2f2f2","background":"#242424","black":"#36342e","red":"#a56434","green":"#008000","yellow":"#999606","blue":"#4646ff","purple":"#7b5175","cyan":"#00a2c4","white":"#cfd8d3","brightBlack":"#535755","brightRed":"#cf9e72","brightGreen":"#1cc470","brightYellow":"#e2e234","brightBlue":"#6f6ff4","brightPurple":"#a97ead","brightCyan":"#50ebfc","brightWhite":"#eceeee"}],// Add any keybinding overrides to this array.// To unbind a default keybinding, set the command to "unbound""keybindings": []
}
这篇关于Xshell配色转WindowsTerminal配色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!