原本都是使用 PieTTY 來連線, 不過由於這軟體久沒有更新, 且下拉式的選單在連線數量變多時, 有點不怎麼好用, 加上目前的 PuTTY 版本在 UTF-8 的情形下, 可以設定英文字型就能正確的顯示與輸入中文, 而且有支援 Win7 的 JumpList 功能, 所以常用的連線也可以很方便的使用, 所以最近又改回使用 PuTTY 了.
由於 PuTTY 是 Open Source (PieTTY 說要放出 Source Code 也說好久了, 不過一直都沒看到), 所以有些功能就方便自己修改.
我自己常碰到的就是當使用 xterm 時, 可以使用下面這個設定來顯示視窗的標題:
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
不過... 當路徑有中文出現時, 反而就看不到 (因為 Windows 看不懂 UTF-8...), 這問題在 PieTTY 一樣也有. 這應該是 PuTTY 的這一個 Bug .
下面這兩個 Patch 就是用來修正這問題的 (我覺得這作法有點不太好, 不過算是對我來說比較簡單的改法, 所以... 雖然 patch 也有丟給 PuTTY 的作者群, 不過... 也許不會被接受.
Patch 1 (轉換為 UTF-16LE 再用 SetWindowTextW() 來顯示:
--- putty-src.orig/WINDOWS/WINDOW.C 2011-03-03 02:52:03 +0800
+++ putty-src/WINDOWS/WINDOW.C 2011-11-04 20:55:10 +0800
@@ -202,6 +202,27 @@
static UINT wm_mousewheel = WM_MOUSEWHEEL;
+/* convert to unicode for SetWindowText */
+static void my_SetWindowText(HWND hwnd, char *title)
+{
+ if (term->ucsdata->line_codepage != CP_ACP) {
+ int len, rc;
+ char *p;
+
+ len = MultiByteToWideChar(term->ucsdata->line_codepage, 0, title, -1, NULL, 0);
+ p = snewn(1 + len * 2, char);
+ rc = MultiByteToWideChar(term->ucsdata->line_codepage, 0, title, -1 , (LPWSTR)p, len*2);
+ if (rc != len)
+ SetWindowText(hwnd, title);
+ else
+ SetWindowTextW(hwnd, p);
+ sfree(p);
+ }
+ else
+ SetWindowText(hwnd, title);
+ return;
+}
+
/* Dummy routine, only required in plink. */
void ldisc_update(void *frontend, int echo, int edit)
{
@@ -2254,7 +2275,7 @@
set_title(NULL, cfg.wintitle);
if (IsIconic(hwnd)) {
- SetWindowText(hwnd,
+ my_SetWindowText(hwnd,
cfg.win_name_always ? window_name :
icon_name);
}
@@ -2772,10 +2793,10 @@
LOWORD(lParam), HIWORD(lParam)));
#endif
if (wParam == SIZE_MINIMIZED)
- SetWindowText(hwnd,
+ my_SetWindowText(hwnd,
cfg.win_name_always ? window_name : icon_name);
if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
- SetWindowText(hwnd, window_name);
+ my_SetWindowText(hwnd, window_name);
if (wParam == SIZE_RESTORED) {
processed_resize = FALSE;
clear_full_screen();
@@ -4524,7 +4545,7 @@
window_name = snewn(1 + strlen(title), char);
strcpy(window_name, title);
if (cfg.win_name_always || !IsIconic(hwnd))
- SetWindowText(hwnd, title);
+ my_SetWindowText(hwnd, title);
}
void set_icon(void *frontend, char *title)
@@ -4533,7 +4554,7 @@
icon_name = snewn(1 + strlen(title), char);
strcpy(icon_name, title);
if (!cfg.win_name_always && IsIconic(hwnd))
- SetWindowText(hwnd, title);
+ my_SetWindowText(hwnd, title);
}
void set_sbar(void *frontend, int total, int start, int page)
Patch 2 (某些中文如 "國" 會不正常):
diff --strip-trailing-cr -Nur putty-src.orig//TERMINAL.C putty-src/TERMINAL.C
--- putty-src.orig//TERMINAL.C 2011-05-07 18:57:19 +0800
+++ putty-src/TERMINAL.C 2011-11-14 20:55:08 +0800
@@ -4162,7 +4162,7 @@
*/
if (c == '\012' || c == '\015') {
term->termstate = TOPLEVEL;
- } else if (c == 0234 || c == '\007') {
+ } else if (c == '\007') { // remove 0234, it make some chinese word break
/*
* These characters terminate the string; ST and BEL
* terminate the sequence and trigger instant
如果有需要可以自行使用這兩個 patch 來處理.
或者... 不被我做的執行檔有問題的話, 也可以用下面的檔案:
win32 putty.exe: putty_0.61_x86.7z
win32 所有的執行檔: putty_0.61_all_x86.7z
win64 putty.exe: putty_0.61_x64.7z
win64 所有的執行檔: putty_0.61_all_x64.7z
PS. 本人不保證上述的檔案沒有問題, 要用的請自行負責吧.