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

[tyndur-devel] [PATCH] Pascal-RTL: ReadEscapeSequence



* Pascal-RTL: kedit hat so eine schoene Funktion, um den vt100-Kram
  einzulesen und in was vernuenftiges umzuwanden. Das kann so ziemlich
  jedes interaktiven Programm brauchen, also ab in die RTL damit.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/pas/kedit/kedit.pas       |    2 +-
 src/modules/pas/kedit/kedit_input.pas |    2 +-
 src/modules/pas/kedit/kedit_tui.pas   |   82 ---------------------------------
 src/modules/pas/lib/tyndur/tyndur.pas |   81 ++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 84 deletions(-)

diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas
index 3542b07..dc956d5 100644
--- a/src/modules/pas/kedit/kedit.pas
+++ b/src/modules/pas/kedit/kedit.pas
@@ -103,7 +103,7 @@ procedure Edit;
             case key of
                 #27: { VT100-Escapesequenz }
                     begin
-                        key := HandleEscapeSequence();
+                        key := ReadEscapeSequence();
                         if (key >= SK_MIN) and (key <= SK_MAX) and (special_key_handler[key] <> nil) then begin
                             special_key_handler[key](@state);
                         end else begin
diff --git a/src/modules/pas/kedit/kedit_input.pas b/src/modules/pas/kedit/kedit_input.pas
index 0b2e298..493d6b8 100644
--- a/src/modules/pas/kedit/kedit_input.pas
+++ b/src/modules/pas/kedit/kedit_input.pas
@@ -2,7 +2,7 @@ unit kedit_input;
 
 interface
 
-uses kedit_main, kedit_tui;
+uses tyndur, kedit_main, kedit_tui;
 
 
 type
diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas
index 13c7781..028d9b6 100644
--- a/src/modules/pas/kedit/kedit_tui.pas
+++ b/src/modules/pas/kedit/kedit_tui.pas
@@ -16,40 +16,6 @@ const
     OPT_NO      = 2;
     OPT_CANCEL  = 3;
 
-
-    SK_F1       = #59;
-    SK_F2       = #60;
-    SK_F3       = #61;
-    SK_F4       = #62;
-    SK_F5       = #63;
-    SK_F6       = #64;
-    SK_F7       = #65;
-    SK_F8       = #66;
-    SK_F9       = #67;
-    SK_F10      = #68;
-    SK_F11      = #133;
-    SK_F12      = #134;
-
-    SK_INS      = #82;
-    SK_DEL      = #83;
-    SK_HOME     = #71;
-    SK_END      = #79;
-    SK_PGUP     = #73;
-    SK_PGDN     = #81;
-
-    SK_UP       = #72;
-    SK_DOWN     = #80;
-    SK_LEFT     = #75;
-    SK_RIGHT    = #77;
-
-    SK_CTRL_PGUP    =   #132;
-    SK_CTRL_PGDN    =   #118;
-
-    SK_MIN = #59;
-    SK_MAX = #134;
-
-function HandleEscapeSequence: char;
-
 procedure ShowCursor(visible: boolean);
 procedure FillRectangle(x1, y1, x2, y2: integer);
 function Space(n: integer): string;
@@ -74,54 +40,6 @@ begin
     if visible then CursorOn else CursorOff;
 end;
 
-(* Eingabeverarbeitung ************************************************)
-
-function HandleEscapeSequence: char;
-begin
-    HandleEscapeSequence := #0;
-
-    case readkey of
-        'O':
-            case readkey of
-                'P': exit(SK_F1);
-                'Q': exit(SK_F2);
-                'R': exit(SK_F3);
-                'S': exit(SK_F4);
-            end;
-
-        '[':
-            case readkey of
-                'A': exit(SK_UP);
-                'B': exit(SK_DOWN);
-                'C': exit(SK_RIGHT);
-                'D': exit(SK_LEFT);
-                'F': exit(SK_END);
-                'H': exit(SK_HOME);
-
-                '3': if readkey = '~' then exit(SK_DEL);
-                '5': if readkey = '~' then exit(SK_PGUP);
-                '6': if readkey = '~' then exit(SK_PGDN);
-
-                '1':
-                    case readkey of
-                        '5': if readkey = '~' then exit(SK_F5);
-                        '7': if readkey = '~' then exit(SK_F6);
-                        '8': if readkey = '~' then exit(SK_F7);
-                        '9': if readkey = '~' then exit(SK_F8);
-                    end;
-
-                '2':
-                    case readkey of
-                        '0': if readkey = '~' then exit(SK_F9);
-                        '1': if readkey = '~' then exit(SK_F10);
-                        '3': if readkey = '~' then exit(SK_F11);
-                        '4': if readkey = '~' then exit(SK_F12);
-                        '~': exit(SK_INS);
-                    end;
-            end;
-    end;
-end;
-
 (* Rein grafisches Zeug ***********************************************)
 
 procedure FillRectangle(x1, y1, x2, y2: integer);
diff --git a/src/modules/pas/lib/tyndur/tyndur.pas b/src/modules/pas/lib/tyndur/tyndur.pas
index cf29ef9..19ccf0e 100644
--- a/src/modules/pas/lib/tyndur/tyndur.pas
+++ b/src/modules/pas/lib/tyndur/tyndur.pas
@@ -2,7 +2,41 @@ unit tyndur;
 
 interface
 
+    const
+        SK_F1       = #59;
+        SK_F2       = #60;
+        SK_F3       = #61;
+        SK_F4       = #62;
+        SK_F5       = #63;
+        SK_F6       = #64;
+        SK_F7       = #65;
+        SK_F8       = #66;
+        SK_F9       = #67;
+        SK_F10      = #68;
+        SK_F11      = #133;
+        SK_F12      = #134;
+
+        SK_INS      = #82;
+        SK_DEL      = #83;
+        SK_HOME     = #71;
+        SK_END      = #79;
+        SK_PGUP     = #73;
+        SK_PGDN     = #81;
+
+        SK_UP       = #72;
+        SK_DOWN     = #80;
+        SK_LEFT     = #75;
+        SK_RIGHT    = #77;
+
+        SK_CTRL_PGUP    =   #132;
+        SK_CTRL_PGDN    =   #118;
+
+        SK_MIN = #59;
+        SK_MAX = #134;
+
+
     function ReadUnicodeChar: UnicodeChar;
+    function ReadEscapeSequence: char;
 
 
 implementation
@@ -36,4 +70,51 @@ implementation
         exit(res[1]);
     end;
 
+    function ReadEscapeSequence: char;
+    begin
+        ReadEscapeSequence := #0;
+
+        case readkey of
+            'O':
+                case readkey of
+                    'P': exit(SK_F1);
+                    'Q': exit(SK_F2);
+                    'R': exit(SK_F3);
+                    'S': exit(SK_F4);
+                end;
+
+            '[':
+                case readkey of
+                    'A': exit(SK_UP);
+                    'B': exit(SK_DOWN);
+                    'C': exit(SK_RIGHT);
+                    'D': exit(SK_LEFT);
+                    'F': exit(SK_END);
+                    'H': exit(SK_HOME);
+
+                    '3': if readkey = '~' then exit(SK_DEL);
+                    '5': if readkey = '~' then exit(SK_PGUP);
+                    '6': if readkey = '~' then exit(SK_PGDN);
+
+                    '1':
+                        case readkey of
+                            '5': if readkey = '~' then exit(SK_F5);
+                            '7': if readkey = '~' then exit(SK_F6);
+                            '8': if readkey = '~' then exit(SK_F7);
+                            '9': if readkey = '~' then exit(SK_F8);
+                        end;
+
+                    '2':
+                        case readkey of
+                            '0': if readkey = '~' then exit(SK_F9);
+                            '1': if readkey = '~' then exit(SK_F10);
+                            '3': if readkey = '~' then exit(SK_F11);
+                            '4': if readkey = '~' then exit(SK_F12);
+                            '~': exit(SK_INS);
+                        end;
+                end;
+        end;
+    end;
+
+
 end.
-- 
1.6.0.2