[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 4/4] kedit: UTF-8-Unterstuetzung



+ kedit: Unterstuetzung fuer UTF-8-Text
---
 src/modules/pas/kedit/kedit.pas      |    4 ++--
 src/modules/pas/kedit/kedit_main.pas |    8 +++++---
 src/modules/pas/kedit/kedit_tui.pas  |    9 ++++++---
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas
index 473c218..71a5fcd 100644
--- a/src/modules/pas/kedit/kedit.pas
+++ b/src/modules/pas/kedit/kedit.pas
@@ -87,10 +87,10 @@ procedure Edit;
 
     procedure DoInput;
     var
-        key: char;
+        key: UnicodeChar;
     begin
         with state do begin
-            key:=readkey;
+            key := ReadUnicodeChar;
             case key of
                 #27: { VT100-Escapesequenz }
                     begin
diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas
index 486841b..8e2948d 100644
--- a/src/modules/pas/kedit/kedit_main.pas
+++ b/src/modules/pas/kedit/kedit_main.pas
@@ -7,7 +7,7 @@ const
     MaxColumns = 255;
 
 type
-    type_text = Array [1..MaxLines] of AnsiString;
+    type_text = Array [1..MaxLines] of UnicodeString;
 
     // Beschreibt einen offenen Puffer
     kedit_state = record
@@ -125,7 +125,7 @@ begin
                 for j := 1 to emptylines do begin
                     WriteLn(sfile);
                 end;
-                WriteLn(sfile,text^[i]);
+                WriteLn(sfile, Utf8Encode(text^[i]));
                 emptylines:=0;
             end;
         end;
@@ -140,6 +140,7 @@ var lfile: textfile;
     cnt: longint;
     i: integer;
     attr: word;
+    s: String;
 begin
     if loadname = '' then begin
         Textbackground(1);
@@ -178,7 +179,8 @@ begin
         cnt := 0;
         while not(eof(lfile)) do begin
             Inc(cnt);
-            ReadLn(lfile, text^[cnt]);
+            ReadLn(lfile, s);
+            text^[cnt] := Utf8Decode(s);
         end;
 
         Close(lfile);
diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas
index 2d0f2e8..8067ed1 100644
--- a/src/modules/pas/kedit/kedit_tui.pas
+++ b/src/modules/pas/kedit/kedit_tui.pas
@@ -252,7 +252,7 @@ begin
         screenY := 1 + y - scrolly;
 
         GotoXY(1, screenY);
-        Write(Copy(text^[y], 1+scrollx, 79));
+        Write(Utf8Encode(Copy(text^[y], 1+scrollx, 79)));
         Write(Space(79 - Length(Copy(text^[y], 1+scrollx, 79))));
         GotoXY(CursX - ScrollX, 1 + CursY - ScrollY);
     end;
@@ -267,6 +267,7 @@ var
     syntax_state: longint;
     syntax_chg: TSyntaxChange;
     fromCol, toCol: integer;
+    s: UnicodeString;
 begin
     // Titelleiste
     DrawTitleBar(state);
@@ -277,7 +278,8 @@ begin
     lastVisible := TextLines + state^.scrolly;
     if not highlight then begin
         for i := firstVisible to lastVisible do begin
-            Write(Copy(state^.text^[i], 1 + state^.scrollx, 80));
+            s := Copy(state^.text^[i], 1 + state^.scrollx, 80);
+            Write(Utf8Encode(s));
             Write(Space(80-Length(Copy(state^.text^[i],1+state^.scrollx,80))));
         end;
     end else begin
@@ -316,7 +318,8 @@ begin
                 end;
 
                 if fromCol <= toCol then begin
-                    Write(Copy(state^.text^[i], fromCol, toCol - fromCol + 1));
+                    s := Copy(state^.text^[i], fromCol, toCol - fromCol + 1);
+                    Write(Utf8Encode(s));
                 end;
 
                 if syntax_chg.posY > fromCol then begin
-- 
1.6.0.2