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()
|
93 | 93 | BasicTerminalBuffer::BasicTerminalBuffer() |
94 | 94 | : |
95 | 95 | fScreen(NULL), |
96 | | fHistory(NULL) |
| 96 | fHistory(NULL), |
| 97 | fTabStops(NULL) |
97 | 98 | { |
98 | 99 | } |
99 | 100 | |
… |
… |
BasicTerminalBuffer::~BasicTerminalBuffer()
|
102 | 103 | { |
103 | 104 | delete fHistory; |
104 | 105 | _FreeLines(fScreen, fHeight); |
| 106 | delete[] fTabStops; |
105 | 107 | } |
106 | 108 | |
107 | 109 | |
108 | 110 | status_t |
109 | 111 | BasicTerminalBuffer::Init(int32 width, int32 height, int32 historySize) |
110 | 112 | { |
| 113 | status_t error; |
| 114 | |
111 | 115 | fWidth = width; |
112 | 116 | fHeight = height; |
113 | 117 | |
… |
… |
BasicTerminalBuffer::Init(int32 width, int32 height, int32 historySize)
|
133 | 137 | if (fHistory == NULL) |
134 | 138 | return B_NO_MEMORY; |
135 | 139 | |
136 | | status_t error = fHistory->Init(width, historySize); |
| 140 | error = fHistory->Init(width, historySize); |
137 | 141 | if (error != B_OK) |
138 | 142 | return error; |
139 | 143 | } |
140 | 144 | |
| 145 | error = _ResetTabStops(fWidth); |
| 146 | if (error != B_OK) |
| 147 | return error; |
| 148 | |
141 | 149 | for (int32 i = 0; i < fHeight; i++) |
142 | 150 | fScreen[i]->Clear(); |
143 | 151 | |
… |
… |
BasicTerminalBuffer::InsertRI()
|
622 | 630 | } |
623 | 631 | |
624 | 632 | void |
| 633 | BasicTerminalBuffer::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 | |
| 649 | void |
625 | 650 | BasicTerminalBuffer::InsertLines(int32 numLines) |
626 | 651 | { |
627 | 652 | if (fCursor.y >= fScrollTop && fCursor.y < fScrollBottom) { |
… |
… |
BasicTerminalBuffer::RestoreOriginMode()
|
824 | 849 | fOriginMode = fSavedOriginMode; |
825 | 850 | } |
826 | 851 | |
| 852 | void |
| 853 | BasicTerminalBuffer::SetTabStop(int32 x) |
| 854 | { |
| 855 | x = restrict_value(x, 0, fWidth - 1); |
| 856 | fTabStops[x] = true; |
| 857 | } |
| 858 | |
| 859 | |
| 860 | void |
| 861 | BasicTerminalBuffer::ClearTabStop(int32 x) |
| 862 | { |
| 863 | x = restrict_value(x, 0, fWidth - 1); |
| 864 | fTabStops[x] = false; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | void |
| 869 | BasicTerminalBuffer::ClearAllTabStops() |
| 870 | { |
| 871 | for (int32 i = 0; i < fWidth; i++) |
| 872 | fTabStops[i] = false; |
| 873 | } |
| 874 | |
827 | 875 | |
828 | 876 | void |
829 | 877 | BasicTerminalBuffer::NotifyListener() |
… |
… |
BasicTerminalBuffer::_ResizeSimple(int32 width, int32 height,
|
1024 | 1072 | _FreeLines(fScreen, fHeight); |
1025 | 1073 | fScreen = lines; |
1026 | 1074 | |
| 1075 | if (fWidth != width) { |
| 1076 | status_t error = _ResetTabStops(width); |
| 1077 | if (error != B_OK) |
| 1078 | return error; |
| 1079 | } |
| 1080 | |
1027 | 1081 | fWidth = width; |
1028 | 1082 | fHeight = height; |
1029 | 1083 | |
… |
… |
BasicTerminalBuffer::_ResizeRewrap(int32 width, int32 height,
|
1209 | 1263 | fScreen = screen; |
1210 | 1264 | fHistory = history; |
1211 | 1265 | |
| 1266 | if (fWidth != width) { |
| 1267 | status_t error = _ResetTabStops(width); |
| 1268 | if (error != B_OK) |
| 1269 | return error; |
| 1270 | } |
| 1271 | |
1212 | 1272 | //debug_printf(" cursor: (%ld, %ld) -> (%ld, %ld)\n", fCursor.x, fCursor.y, |
1213 | 1273 | //cursor.x, cursor.y); |
1214 | 1274 | fCursor.x = cursor.x; |
… |
… |
BasicTerminalBuffer::_ResizeRewrap(int32 width, int32 height,
|
1229 | 1289 | } |
1230 | 1290 | |
1231 | 1291 | |
| 1292 | status_t |
| 1293 | BasicTerminalBuffer::_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 | |
1232 | 1307 | void |
1233 | 1308 | BasicTerminalBuffer::_Scroll(int32 top, int32 bottom, int32 numLines) |
1234 | 1309 | { |
diff --git src/apps/terminal/BasicTerminalBuffer.h src/apps/terminal/BasicTerminalBuffer.h
index 3b134b8..2d57aaf 100644
|
|
public:
|
107 | 107 | void InsertCR(); |
108 | 108 | void InsertLF(); |
109 | 109 | void InsertRI(); |
| 110 | void InsertTab(); |
110 | 111 | void SetInsertMode(int flag); |
111 | 112 | void InsertSpace(int32 num); |
112 | 113 | void InsertLines(int32 numLines); |
… |
… |
public:
|
142 | 143 | void SetOriginMode(bool enabled); |
143 | 144 | void SaveOriginMode(); |
144 | 145 | void RestoreOriginMode(); |
| 146 | void SetTabStop(int32 x); |
| 147 | void ClearTabStop(int32 x); |
| 148 | void ClearAllTabStops(); |
145 | 149 | |
146 | 150 | protected: |
147 | 151 | virtual void NotifyListener(); |
… |
… |
protected:
|
166 | 170 | int32 historyCapacity); |
167 | 171 | status_t _ResizeRewrap(int32 width, int32 height, |
168 | 172 | int32 historyCapacity); |
| 173 | status_t _ResetTabStops(int32 width); |
169 | 174 | |
170 | 175 | void _Scroll(int32 top, int32 bottom, |
171 | 176 | int32 numLines); |
… |
… |
protected:
|
202 | 207 | bool fAlternateScreenActive; |
203 | 208 | bool fOriginMode; |
204 | 209 | bool fSavedOriginMode; |
| 210 | bool* fTabStops; |
205 | 211 | |
206 | 212 | int fEncoding; |
207 | 213 | |
diff --git src/apps/terminal/TermConst.h src/apps/terminal/TermConst.h
index d9a6250..cb5bee1 100644
|
|
enum{
|
152 | 152 | SCRDOWN |
153 | 153 | }; |
154 | 154 | |
| 155 | #define TAB_WIDTH 8 |
| 156 | |
155 | 157 | #define MIN_COLS 10 |
156 | 158 | #define MAX_COLS 256 |
157 | 159 | #define MIN_ROWS 10 |
diff --git src/apps/terminal/TermParse.cpp src/apps/terminal/TermParse.cpp
index f385ec2..606f7be 100644
|
|
TermParse::DumpState(int *groundtable, int *parsestate, uchar c)
|
301 | 301 | int32 |
302 | 302 | TermParse::EscParse() |
303 | 303 | { |
304 | | int tmp; |
305 | 304 | int top, bot; |
306 | 305 | int cs96 = 0; |
307 | 306 | uchar curess = 0; |
… |
… |
TermParse::EscParse()
|
517 | 516 | break; |
518 | 517 | |
519 | 518 | case CASE_TAB: |
520 | | tmp = fBuffer->Cursor().x; |
521 | | tmp %= 8; |
522 | | fBuffer->MoveCursorRight(8 - tmp); |
| 519 | fBuffer->InsertTab(); |
523 | 520 | break; |
524 | 521 | |
525 | 522 | case CASE_ESC: |
… |
… |
TermParse::EscParse()
|
847 | 844 | |
848 | 845 | case CASE_HTS: |
849 | 846 | /* 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(); |
851 | 857 | parsestate = groundtable; |
852 | 858 | break; |
853 | 859 | |
diff --git src/apps/terminal/VTPrsTbl.c src/apps/terminal/VTPrsTbl.c
index 9816ff6..6ba0a0b 100644
|
|
CASE_GROUND_STATE,
|
1140 | 1140 | CASE_VPA, |
1141 | 1141 | CASE_GROUND_STATE, |
1142 | 1142 | CASE_CUP, |
1143 | | CASE_GROUND_STATE, |
| 1143 | CASE_TBC, |
1144 | 1144 | /* h i j k */ |
1145 | 1145 | CASE_SET, |
1146 | 1146 | CASE_GROUND_STATE, |