Ticket #4657: term-tab-stops.patch

File term-tab-stops.patch, 6.1 KB (added by joshe, 15 years ago)

Implement tab stops

  • src/apps/terminal/BasicTerminalBuffer.cpp

    commit 1287cec35182c46a2bf5a2c46609163a608babc7
    Author: Joshua R. Elsasser <joshua@elsasser.org>
    Date:   Sun Sep 27 12:29:00 2009 +0000
    
        Implement tab stops.
    
    diff --git src/apps/terminal/BasicTerminalBuffer.cpp src/apps/terminal/BasicTerminalBuffer.cpp
    index 219afcd..9b39e7a 100644
    BasicTerminalBuffer::_CursorChanged()  
    9393BasicTerminalBuffer::BasicTerminalBuffer()
    9494    :
    9595    fScreen(NULL),
    96     fHistory(NULL)
     96    fHistory(NULL),
     97    fTabStops(NULL)
    9798{
    9899}
    99100
    BasicTerminalBuffer::~BasicTerminalBuffer()  
    102103{
    103104    delete fHistory;
    104105    _FreeLines(fScreen, fHeight);
     106    delete[] fTabStops;
    105107}
    106108
    107109
    108110status_t
    109111BasicTerminalBuffer::Init(int32 width, int32 height, int32 historySize)
    110112{
     113    status_t error;
     114
    111115    fWidth = width;
    112116    fHeight = height;
    113117
    BasicTerminalBuffer::Init(int32 width, int32 height, int32 historySize)  
    133137        if (fHistory == NULL)
    134138            return B_NO_MEMORY;
    135139
    136         status_t error = fHistory->Init(width, historySize);
     140        error = fHistory->Init(width, historySize);
    137141        if (error != B_OK)
    138142            return error;
    139143    }
    140144
     145    error = _ResetTabStops(fWidth);
     146    if (error != B_OK)
     147        return error;
     148
    141149    for (int32 i = 0; i < fHeight; i++)
    142150        fScreen[i]->Clear();
    143151
    BasicTerminalBuffer::InsertRI()  
    622630}
    623631
    624632void
     633BasicTerminalBuffer::InsertTab()
     634{
     635    int32 x;
     636
     637    fSoftWrappedCursor = false;
     638
     639    for (x = fCursor.x + 1; x < fWidth && !fTabStops[x]; x++)
     640        ; // no body
     641    x = restrict_value(x, 0, fWidth - 1);
     642
     643    if (x != fCursor.x) {
     644        fCursor.x = x;
     645        _CursorChanged();
     646    }
     647}
     648
     649void
    625650BasicTerminalBuffer::InsertLines(int32 numLines)
    626651{
    627652    if (fCursor.y >= fScrollTop && fCursor.y < fScrollBottom) {
    BasicTerminalBuffer::RestoreOriginMode()  
    824849    fOriginMode = fSavedOriginMode;
    825850}
    826851
     852void
     853BasicTerminalBuffer::SetTabStop(int32 x)
     854{
     855    x = restrict_value(x, 0, fWidth - 1);
     856    fTabStops[x] = true;
     857}
     858
     859
     860void
     861BasicTerminalBuffer::ClearTabStop(int32 x)
     862{
     863    x = restrict_value(x, 0, fWidth - 1);
     864    fTabStops[x] = false;
     865}
     866
     867
     868void
     869BasicTerminalBuffer::ClearAllTabStops()
     870{
     871    for (int32 i = 0; i < fWidth; i++)
     872        fTabStops[i] = false;
     873}
     874
    827875
    828876void
    829877BasicTerminalBuffer::NotifyListener()
    BasicTerminalBuffer::_ResizeSimple(int32 width, int32 height,  
    10241072    _FreeLines(fScreen, fHeight);
    10251073    fScreen = lines;
    10261074
     1075    if (fWidth != width) {
     1076        status_t error = _ResetTabStops(width);
     1077        if (error != B_OK)
     1078            return error;
     1079    }
     1080
    10271081    fWidth = width;
    10281082    fHeight = height;
    10291083
    BasicTerminalBuffer::_ResizeRewrap(int32 width, int32 height,  
    12091263    fScreen = screen;
    12101264    fHistory = history;
    12111265
     1266    if (fWidth != width) {
     1267        status_t error = _ResetTabStops(width);
     1268        if (error != B_OK)
     1269            return error;
     1270    }
     1271
    12121272//debug_printf("  cursor: (%ld, %ld) -> (%ld, %ld)\n", fCursor.x, fCursor.y,
    12131273//cursor.x, cursor.y);
    12141274    fCursor.x = cursor.x;
    BasicTerminalBuffer::_ResizeRewrap(int32 width, int32 height,  
    12291289}
    12301290
    12311291
     1292status_t
     1293BasicTerminalBuffer::_ResetTabStops(int32 width)
     1294{
     1295    if (fTabStops != NULL)
     1296        delete[] fTabStops;
     1297
     1298    fTabStops = new(std::nothrow) bool[width];
     1299    if (fTabStops == NULL)
     1300        return B_NO_MEMORY;
     1301
     1302    for (int32 i = 0; i < width; i++)
     1303        fTabStops[i] = (i % TAB_WIDTH) == 0;
     1304    return B_OK;
     1305}
     1306
    12321307void
    12331308BasicTerminalBuffer::_Scroll(int32 top, int32 bottom, int32 numLines)
    12341309{
  • src/apps/terminal/BasicTerminalBuffer.h

    diff --git src/apps/terminal/BasicTerminalBuffer.h src/apps/terminal/BasicTerminalBuffer.h
    index 3b134b8..2d57aaf 100644
    public:  
    107107            void                InsertCR();
    108108            void                InsertLF();
    109109            void                InsertRI();
     110            void                InsertTab();
    110111            void                SetInsertMode(int flag);
    111112            void                InsertSpace(int32 num);
    112113            void                InsertLines(int32 numLines);
    public:  
    142143            void                SetOriginMode(bool enabled);
    143144            void                SaveOriginMode();
    144145            void                RestoreOriginMode();
     146            void                SetTabStop(int32 x);
     147            void                ClearTabStop(int32 x);
     148            void                ClearAllTabStops();
    145149
    146150protected:
    147151    virtual void                NotifyListener();
    protected:  
    166170                                    int32 historyCapacity);
    167171            status_t            _ResizeRewrap(int32 width, int32 height,
    168172                                    int32 historyCapacity);
     173            status_t            _ResetTabStops(int32 width);
    169174
    170175            void                _Scroll(int32 top, int32 bottom,
    171176                                    int32 numLines);
    protected:  
    202207            bool                fAlternateScreenActive;
    203208            bool                fOriginMode;
    204209            bool                fSavedOriginMode;
     210            bool*               fTabStops;
    205211
    206212            int                 fEncoding;
    207213
  • src/apps/terminal/TermConst.h

    diff --git src/apps/terminal/TermConst.h src/apps/terminal/TermConst.h
    index d9a6250..cb5bee1 100644
    enum{  
    152152  SCRDOWN
    153153};
    154154
     155#define TAB_WIDTH 8
     156
    155157#define MIN_COLS 10
    156158#define MAX_COLS 256
    157159#define MIN_ROWS 10
  • src/apps/terminal/TermParse.cpp

    diff --git src/apps/terminal/TermParse.cpp src/apps/terminal/TermParse.cpp
    index f385ec2..606f7be 100644
    TermParse::DumpState(int *groundtable, int *parsestate, uchar c)  
    301301int32
    302302TermParse::EscParse()
    303303{
    304     int tmp;
    305304    int top, bot;
    306305    int cs96 = 0;
    307306    uchar curess = 0;
    TermParse::EscParse()  
    517516                break;
    518517
    519518            case CASE_TAB:
    520                 tmp = fBuffer->Cursor().x;
    521                 tmp %= 8;
    522                 fBuffer->MoveCursorRight(8 - tmp);
     519                fBuffer->InsertTab();
    523520                break;
    524521
    525522            case CASE_ESC:
    TermParse::EscParse()  
    847844
    848845                case CASE_HTS:
    849846                    /* HTS */
    850                     //      TabSet(term->tabs, screen->cur_col);
     847                    fBuffer->SetTabStop(fBuffer->Cursor().x);
     848                    parsestate = groundtable;
     849                    break;
     850
     851                case CASE_TBC:
     852                    /* TBC */
     853                    if (param[0] < 1)
     854                        fBuffer->ClearTabStop(fBuffer->Cursor().x);
     855                    else if (param[0] == 3)
     856                        fBuffer->ClearAllTabStops();
    851857                    parsestate = groundtable;
    852858                    break;
    853859
  • src/apps/terminal/VTPrsTbl.c

    diff --git src/apps/terminal/VTPrsTbl.c src/apps/terminal/VTPrsTbl.c
    index 9816ff6..6ba0a0b 100644
    CASE_GROUND_STATE,  
    11401140CASE_VPA,
    11411141CASE_GROUND_STATE,
    11421142CASE_CUP,
    1143 CASE_GROUND_STATE,
     1143CASE_TBC,
    11441144/*  h       i       j       k   */
    11451145CASE_SET,
    11461146CASE_GROUND_STATE,