Re: [心得] MUSHclient - Plugins:讓抓取聊天訊息視窗正確換行

看板mud_sanc (Sanctuary - 聖殿)作者 (hmml)時間12年前 (2013/12/08 00:55), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
  將換行判斷由 MUSHclient 自行判斷,改成用自訂的規則判斷, 之所以改成自定義,乃因 MUSHclient 無法判斷換行的字元是雙位元 的字還是單位元的字,導致換行常常換行換在字的中間,造成亂碼。 而 Lua 本身有提供檢查指定字元 ANSI 值的函數-string.byte,如 此便可以根據 ANSI 字位集亞洲規則(0 - 127 為單字元字集,128 以上為雙字元字集的前綴字元)更彈性地判斷換行正確位置應該是哪 裡。在那個位置,先行插入"\n"即可。   這個修改,重要訊息檢視視窗必須做好下列兩項設定變更: 1.Wrap output at column number 不得為空白,要填上期望換行的數值。 2.Auto-Wrap to window size 取消勾選,否則它依然會造成亂碼。   上列兩項,滑鼠在輸出視窗中點開右鍵功能表,選取: World Configuration...打開該輸出視窗的組態設定頁面,在左側樹狀 目錄中選取Output,上述第一項在頁面最下方兩個按鈕的上方;第二項 在右側勾選項列表中倒數第五項。 -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- <script> <![CDATA[ local conversion= { ['black'] = ANSI (30,22), ['maroon'] = ANSI (31,22), ['green'] = ANSI (32,22), ['olive'] = ANSI (33,22), ['navy'] = ANSI (34,22), ['purple'] = ANSI (35,22), ['teal'] = ANSI (36,22), ['silver'] = ANSI (37,22), --以下高亮 ['gray'] = ANSI (30,1), ['red'] = ANSI (31,1), ['lime'] = ANSI (32,1), ['yellow'] = ANSI (33,1), ['blue'] = ANSI (34,1), ['magenta'] = ANSI (35,1), ['cyan'] = ANSI (36,1), ['white'] = ANSI (37,1), } -- 前景 local BACKconversion= { ['black'] = ANSI (40), ['maroon'] = ANSI (41), ['green'] = ANSI (42), ['olive'] = ANSI (43), ['navy'] = ANSI (44), ['purple'] = ANSI (45), ['teal'] = ANSI (46), ['silver'] = ANSI (47), } --背景 chat_world = "sanc_chat_list" Listen_Player = 'hmml5' local first_time = true function color_chats (name, line, wildcards, styles) -- 試著找到 "chat_ world" local w = GetWorld (chat_world) -- get "chat" world -- 如果找不到,試著去打開它 if first_time and not w then local filename = GetInfo (67) .. chat_world .. ".mcl" Open (filename) w = GetWorld (chat_world) -- 再試一次 if not w then ColourNote ("white", "red", "無法打開指定的檔案:" .. filename) first_time = false -- don't repeatedly show failure message end -- 找不到 end -- can't find world first time around if w then -- 如果存在,w就是存著'chat_world' ID值的變數。 message_wrap = w:GetOption('wrap_column') - 14 --換行長度,14是時間字段長度 if GetAlphaOption("player") == Listen_Player then --負責抓訊息的角色視窗 --時間,上方藍色部份即是先減掉這段的長度 w:Simulate(ANSI (33, 40,1)..os.date (" %d ").. ANSI (32, 40,1)..os.date ("%H").. ANSI (36, 40,1)..os.date (":%M").. ANSI (32, 40,1).." >") for _, v in ipairs (styles) do Colour_Code = conversion[RGBColourToName (v.textcolour)].. BACKconversion[RGBColourToName (v.backcolour)] --如果字串長度小於設定的換行長度,就逐串減去。 if message_wrap >= string.len(v.text) then message_wrap = message_wrap - string.len(v.text) --減到換行長度小於字串長的時候 else --先檢測換行所在的字元是雙位元寬的字,還是單位元寬。 --是雙位元的話,將換行字元插入前一個位置。 if string.byte (v.text,message_wrap) > 127 then v.text = string.sub(v.text,1,message_wrap-1)..'\n'.. string.sub(v.text,message_wrap) --再檢測換行所在的前一字元是否為雙位元寬的字。 --是雙位元的話,將換行字元插入前一個位置。 elseif string.byte (v.text,message_wrap-1) > 127 then v.text = string.sub(v.text,1,message_wrap-2)..'\n'.. string.sub(v.text,message_wrap-1) end end w:Simulate(Colour_Code..v.text) --內容 end -- for each style run w:Simulate('\n') end -- ID end -- world found end -- function redirect ]]> </script> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.196.45 ※ 編輯: hmml 來自: 220.132.196.45 (12/08 01:30)

12/08 01:56, , 1F
待修理,還是有問題。
12/08 01:56, 1F
文章代碼(AID): #1IerBfE8 (mud_sanc)
文章代碼(AID): #1IerBfE8 (mud_sanc)