Changeset 26003

Show
Ignore:
Timestamp:
06/17/08 18:49:06 (5 months ago)
Author:
bonefish
Message:

* Some preparations for DEC private mode settings support.
* Implemented alternate screen buffer support. Not used by any program

yet, since we still use the beterm termcap entry.

Location:
haiku/trunk/src/apps/terminal
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp

    r25988 r26003  
    121121 
    122122        fOverwriteMode = true; 
     123        fAlternateScreenActive = false; 
    123124 
    124125        fScreen = _AllocateLines(width, height); 
     
    163164                return SetHistoryCapacity(historyCapacity); 
    164165 
    165         // TODO: When alternate screen support is implemented, do that only when 
    166         // not using the alternate screen. 
    167         if (true) 
    168                 return _ResizeRewrap(width, height, historyCapacity); 
    169  
    170         return _ResizeSimple(width, height, historyCapacity); 
     166        if (fAlternateScreenActive) 
     167                return _ResizeSimple(width, height, historyCapacity); 
     168 
     169        return _ResizeRewrap(width, height, historyCapacity); 
    171170} 
    172171 
     
    180179 
    181180void 
    182 BasicTerminalBuffer::Clear() 
     181BasicTerminalBuffer::Clear(bool resetCursor) 
    183182{ 
    184183        fScreenOffset = 0; 
    185184        _ClearLines(0, fHeight - 1); 
    186         fCursor.SetTo(0, 0); 
     185 
     186        if (resetCursor) 
     187                fCursor.SetTo(0, 0); 
    187188 
    188189        if (fHistory != NULL) 
     
    586587                _Scroll(fScrollTop, fScrollBottom, 1); 
    587588        } else { 
    588                 fCursor.y++; 
     589                if (fCursor.y < fHeight - 1) 
     590                        fCursor.y++; 
    589591                _CursorChanged(); 
    590592        } 
     
    732734//debug_printf("BasicTerminalBuffer::SetCursor(%d, %d)\n", x, y); 
    733735        x = restrict_value(x, 0, fWidth - 1); 
    734         y = restrict_value(y, fScrollTop, fScrollBottom); 
     736        y = restrict_value(y, 0, fHeight - 1); 
    735737        if (x != fCursor.x || y != fCursor.y) { 
    736738                fCursor.x = x; 
     
    774776 
    775777// #pragma mark - private methods 
     778 
     779 
     780void 
     781BasicTerminalBuffer::_InvalidateAll() 
     782{ 
     783        fDirtyInfo.invalidateAll = true; 
     784 
     785        if (!fDirtyInfo.messageSent) { 
     786                NotifyListener(); 
     787                fDirtyInfo.messageSent = true; 
     788        } 
     789} 
    776790 
    777791 
  • haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h

    r25988 r26003  
    2222        int32   dirtyTop;                               // dirty line range 
    2323        int32   dirtyBottom;                    // 
     24        bool    invalidateAll; 
    2425        bool    messageSent;                    // listener has been notified 
    2526 
     
    4243                dirtyTop = INT_MAX; 
    4344                dirtyBottom = INT_MIN; 
     45                invalidateAll = false; 
    4446                messageSent = false; 
    4547        } 
     
    6264                        TerminalBufferDirtyInfo& DirtyInfo()    { return fDirtyInfo; } 
    6365 
    64                         status_t                        ResizeTo(int32 width, int32 height); 
    65                         status_t                        ResizeTo(int32 width, int32 height, 
     66        virtual status_t                        ResizeTo(int32 width, int32 height); 
     67        virtual status_t                        ResizeTo(int32 width, int32 height, 
    6668                                                                        int32 historyCapacity); 
    6769                        status_t                        SetHistoryCapacity(int32 historyCapacity); 
    68                         void                            Clear(); 
     70                        void                            Clear(bool resetCursor); 
    6971 
    7072                        void                            SynchronizeWith( 
     
    140142        inline  void                            _Invalidate(int32 top, int32 bottom); 
    141143        inline  void                            _CursorChanged(); 
     144                        void                            _InvalidateAll(); 
    142145 
    143146        static  TerminalLine**          _AllocateLines(int32 width, int32 count); 
     
    183186 
    184187                        bool                            fOverwriteMode; // false for insert 
     188                        bool                            fAlternateScreenActive; 
    185189 
    186190                        int                                     fEncoding; 
  • haiku/trunk/src/apps/terminal/TermParse.cpp

    r25992 r26003  
    791791                                case CASE_DECSET: 
    792792                                        /* DECSET */ 
    793                                         //      dpmodes(term, bitset); 
     793                                        for (int i = 0; i < nparam; i++) 
     794                                                _DecPrivateModeSet(param[i]); 
    794795                                        parsestate = groundtable; 
    795796                                        break; 
     
    797798                                case CASE_DECRST: 
    798799                                        /* DECRST */ 
    799                                         //      dpmodes(term, bitclr); 
     800                                        for (int i = 0; i < nparam; i++) 
     801                                                _DecPrivateModeReset(param[i]); 
    800802                                        parsestate = groundtable; 
    801803                                        break; 
     
    10711073        } 
    10721074} 
     1075 
     1076 
     1077void 
     1078TermParse::_DecPrivateModeSet(int value) 
     1079{ 
     1080        switch (value) { 
     1081                case 1: 
     1082                        // Application Cursor Keys (whatever that means). 
     1083                        // Not supported yet. 
     1084                        break; 
     1085                case 5: 
     1086                        // Reverse Video (inverses colors for the complete screen 
     1087                        // -- when followed by normal video, that's shortly flashes the 
     1088                        // screen). 
     1089                        // Not supported yet. 
     1090                        break; 
     1091                case 12: 
     1092                        // Start Blinking Cursor. 
     1093                        // Not supported yet. 
     1094                        break; 
     1095                case 25: 
     1096                        // Show Cursor 
     1097                        // Not supported yet. 
     1098                        break; 
     1099                case 1034: 
     1100                        // Interpret "meta" key, sets eighth bit. 
     1101                        // Not supported yet. 
     1102                        break; 
     1103                case 1049: 
     1104                        // Save cursor as in DECSC and use Alternate Screen Buffer, clearing 
     1105                        // it first. 
     1106                        fBuffer->SaveCursor(); 
     1107                        fBuffer->UseAlternateScreenBuffer(); 
     1108                        break; 
     1109        } 
     1110} 
     1111 
     1112 
     1113void 
     1114TermParse::_DecPrivateModeReset(int value) 
     1115{ 
     1116        switch (value) { 
     1117                case 1: 
     1118                        // Normal Cursor Keys (whatever that means). 
     1119                        // Not supported yet. 
     1120                        break; 
     1121                case 3: 
     1122                        // 80 Column Mode. 
     1123                        // Not supported yet. 
     1124                        break; 
     1125                case 4: 
     1126                        // Jump (Fast) Scroll. 
     1127                        // Not supported yet. 
     1128                        break; 
     1129                case 5: 
     1130                        // Normal Video (Leaves Reverse Video, cf. there). 
     1131                        // Not supported yet. 
     1132                        break; 
     1133                case 12: 
     1134                        // Stop Blinking Cursor. 
     1135                        // Not supported yet. 
     1136                        break; 
     1137                case 25: 
     1138                        // Hide Cursor 
     1139                        // Not supported yet. 
     1140                        break; 
     1141                case 1034: 
     1142                        // Don’t interpret "meta" key. 
     1143                        // Not supported yet. 
     1144                        break; 
     1145                case 1049: 
     1146                        // Use Normal Screen Buffer and restore cursor as in DECRC. 
     1147                        fBuffer->RestoreCursor(); 
     1148                        fBuffer->UseNormalScreenBuffer(); 
     1149                        break; 
     1150        } 
     1151} 
  • haiku/trunk/src/apps/terminal/TermParse.h

    r25911 r26003  
    7777 
    7878        void _DeviceStatusReport(int n); 
     79        void _DecPrivateModeSet(int value); 
     80        void _DecPrivateModeReset(int value); 
    7981 
    8082        int fFd; 
  • haiku/trunk/src/apps/terminal/TermView.cpp

    r25981 r26003  
    711711        { 
    712712                BAutolock _(fTextBuffer); 
    713                 fTextBuffer->Clear(); 
    714         } 
    715         fVisibleTextBuffer->Clear(); 
     713                fTextBuffer->Clear(true); 
     714        } 
     715        fVisibleTextBuffer->Clear(true); 
    716716 
    717717//debug_printf("Invalidate()\n"); 
     
    15641564        TerminalBufferDirtyInfo& info = fTextBuffer->DirtyInfo(); 
    15651565        int32 linesScrolled = info.linesScrolled; 
    1566         BRect bounds = Bounds(); 
    1567         int32 firstVisible = _LineAt(0); 
    1568         int32 lastVisible = _LineAt(bounds.bottom); 
    1569         int32 historySize = fTextBuffer->HistorySize(); 
    15701566 
    15711567//debug_printf("TermView::_SynchronizeWithTextBuffer(): dirty: %ld - %ld, " 
     
    16301626                fScrolledSinceLastSync = 0; 
    16311627        } 
     1628 
     1629        // Simple case first -- complete invalidation. 
     1630        if (info.invalidateAll) { 
     1631                Invalidate(); 
     1632                _UpdateScrollBarRange(); 
     1633                int32 offset = _LineAt(0); 
     1634                fVisibleTextBuffer->SynchronizeWith(fTextBuffer, offset, offset, 
     1635                        offset + fTextBuffer->Height() + 2); 
     1636                info.Reset(); 
     1637                return; 
     1638        } 
     1639 
     1640        BRect bounds = Bounds(); 
     1641        int32 firstVisible = _LineAt(0); 
     1642        int32 lastVisible = _LineAt(bounds.bottom); 
     1643        int32 historySize = fTextBuffer->HistorySize(); 
    16321644 
    16331645        bool doScroll = false; 
  • haiku/trunk/src/apps/terminal/TerminalBuffer.cpp

    r25964 r26003  
    66#include "TerminalBuffer.h" 
    77 
     8#include <algorithm> 
     9 
    810#include <Message.h> 
    911 
     
    1921        BLocker("terminal buffer"), 
    2022        fEncoding(M_UTF8), 
     23        fAlternateScreen(NULL), 
     24        fAlternateHistory(NULL), 
     25        fAlternateScreenOffset(0), 
    2126        fListenerValid(false) 
    2227{ 
     
    2631TerminalBuffer::~TerminalBuffer() 
    2732{ 
     33        delete fAlternateScreen; 
     34        delete fAlternateHistory; 
    2835} 
    2936 
     
    3441        if (Sem() < 0) 
    3542                return Sem(); 
     43 
     44        fAlternateScreen = _AllocateLines(width, height); 
     45        if (fAlternateScreen == NULL) 
     46                return B_NO_MEMORY; 
    3647 
    3748        return BasicTerminalBuffer::Init(width, height, historySize); 
     
    96107                fListener.SendMessage(MSG_TERMINAL_BUFFER_CHANGED); 
    97108} 
     109 
     110 
     111status_t 
     112TerminalBuffer::ResizeTo(int32 width, int32 height) 
     113{ 
     114        int32 historyCapacity = 0; 
     115        if (!fAlternateScreenActive) 
     116                historyCapacity = HistoryCapacity(); 
     117        else if (fAlternateHistory != NULL) 
     118                historyCapacity = fAlternateHistory->Capacity(); 
     119 
     120        return ResizeTo(width, height, historyCapacity); 
     121} 
     122 
     123 
     124status_t 
     125TerminalBuffer::ResizeTo(int32 width, int32 height, int32 historyCapacity) 
     126{ 
     127        // switch to the normal screen buffer first 
     128        bool alternateScreenActive = fAlternateScreenActive; 
     129        if (alternateScreenActive) 
     130                _SwitchScreenBuffer(); 
     131 
     132        int32 oldWidth = fWidth; 
     133        int32 oldHeight = fHeight; 
     134 
     135        // Resize the normal screen buffer/history. 
     136        status_t error = BasicTerminalBuffer::ResizeTo(width, height, 
     137                historyCapacity); 
     138        if (error != B_OK) { 
     139                if (alternateScreenActive) 
     140                        _SwitchScreenBuffer(); 
     141                return error; 
     142        } 
     143 
     144        TermPos cursor = fCursor; 
     145 
     146        // Switch to the alternate screen buffer and resize it. 
     147        if (fAlternateScreen != NULL) { 
     148                _SwitchScreenBuffer(); 
     149 
     150                fWidth = oldWidth; 
     151                fHeight = oldHeight; 
     152                fCursor.SetTo(0, 0); 
     153 
     154                error = BasicTerminalBuffer::ResizeTo(width, height, 0); 
     155                if (error != B_OK) { 
     156                        // This sucks -- we can't do anything about it. Delete the 
     157                        // alternate screen buffer. 
     158                        _FreeLines(fAlternateScreen, oldHeight); 
     159                        fAlternateScreen = NULL; 
     160                } 
     161 
     162                // Switch back. 
     163                if (!alternateScreenActive) 
     164                        _SwitchScreenBuffer(); 
     165 
     166                fWidth = width; 
     167                fHeight = height; 
     168                fCursor = cursor; 
     169        } 
     170 
     171        return error; 
     172} 
     173 
     174 
     175void 
     176TerminalBuffer::UseAlternateScreenBuffer() 
     177{ 
     178        if (fAlternateScreenActive || fAlternateScreen == NULL) 
     179                return; 
     180 
     181        _SwitchScreenBuffer(); 
     182        Clear(false); 
     183        _InvalidateAll(); 
     184} 
     185 
     186 
     187void 
     188TerminalBuffer::UseNormalScreenBuffer() 
     189{ 
     190        if (!fAlternateScreenActive) 
     191                return; 
     192 
     193        _SwitchScreenBuffer(); 
     194        _InvalidateAll(); 
     195} 
     196 
     197 
     198void 
     199TerminalBuffer::_SwitchScreenBuffer() 
     200{ 
     201        std::swap(fScreen, fAlternateScreen); 
     202        std::swap(fHistory, fAlternateHistory); 
     203        std::swap(fScreenOffset, fAlternateScreenOffset); 
     204        fAlternateScreenActive = !fAlternateScreenActive; 
     205} 
  • haiku/trunk/src/apps/terminal/TerminalBuffer.h

    r25964 r26003  
    2929                        void                            NotifyQuit(int32 reason); 
    3030 
     31        virtual status_t                        ResizeTo(int32 width, int32 height); 
     32        virtual status_t                        ResizeTo(int32 width, int32 height, 
     33                                                                        int32 historyCapacity); 
     34 
     35                        void                            UseAlternateScreenBuffer(); 
     36                        void                            UseNormalScreenBuffer(); 
     37 
    3138protected: 
    3239        virtual void                            NotifyListener(); 
    3340 
    3441private: 
     42                        void                            _SwitchScreenBuffer(); 
     43 
     44private: 
    3545                        int                                     fEncoding; 
     46 
     47                        TerminalLine**          fAlternateScreen; 
     48                        HistoryBuffer*          fAlternateHistory; 
     49                        int32                           fAlternateScreenOffset; 
    3650 
    3751                        // listener/dirty region management