[llvm-branch-commits] [lldb] r198381 - For Apple builds, handle the F1-F4 defaults for Terminal.app since they default to \033OP, \033OQ, \033OR, \033OS instead of \033[11~, \033[12~, \033[13~, \033[14~.

Greg Clayton gclayton at apple.com
Thu Jan 2 16:16:59 PST 2014


Author: gclayton
Date: Thu Jan  2 18:16:59 2014
New Revision: 198381

URL: http://llvm.org/viewvc/llvm-project?rev=198381&view=rev
Log:
For Apple builds, handle the F1-F4 defaults for Terminal.app since they default to \033OP, \033OQ, \033OR, \033OS instead of \033[11~, \033[12~, \033[13~, \033[14~.


Modified:
    lldb/branches/iohandler/source/Core/IOHandler.cpp

Modified: lldb/branches/iohandler/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Core/IOHandler.cpp?rev=198381&r1=198380&r2=198381&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Core/IOHandler.cpp (original)
+++ lldb/branches/iohandler/source/Core/IOHandler.cpp Thu Jan  2 18:16:59 2014
@@ -1596,6 +1596,10 @@ namespace curses
             debugger.EnableForwardEvents (listener_sp);
 
             bool update = true;
+#if defined(__APPLE__)
+            std::deque<int> escape_chars;
+#endif
+            
             while (!done)
             {
                 if (update)
@@ -1608,8 +1612,43 @@ namespace curses
                     doupdate();
                     update = false;
                 }
-                int ch = m_window_sp->GetChar();
                 
+#if defined(__APPLE__)
+                // Terminal.app doesn't map its function keys correctly, F1-F4 default to:
+                // \033OP, \033OQ, \033OR, \033OS, so lets take care of this here if possible
+                int ch;
+                if (escape_chars.empty())
+                    ch = m_window_sp->GetChar();
+                else
+                {
+                    ch = escape_chars.front();
+                    escape_chars.pop_front();
+                }
+                if (ch == KEY_ESCAPE)
+                {
+                    int ch2 = m_window_sp->GetChar();
+                    if (ch2 == 'O')
+                    {
+                        int ch3 = m_window_sp->GetChar();
+                        switch (ch3)
+                        {
+                            case 'P': ch = KEY_F(1); break;
+                            case 'Q': ch = KEY_F(2); break;
+                            case 'R': ch = KEY_F(3); break;
+                            case 'S': ch = KEY_F(4); break;
+                            default:
+                                escape_chars.push_back(ch2);
+                                escape_chars.push_back(ch3);
+                                break;
+                        }
+                    }
+                    else
+                        escape_chars.push_back(ch2);
+                }
+#else
+                int ch = m_window_sp->GetChar();
+
+#endif
                 if (ch == -1)
                 {
                     if (feof(m_in) || ferror(m_in))





More information about the llvm-branch-commits mailing list