2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 #ifdef VERBOSE_REV_INFO
25 static char rcs_id[] = "$TOG: TermFunction.c /main/2 1998/03/16 14:41:27 mgreess $";
26 #endif /* VERBOSE_REV_INFO */
30 * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company *
31 * (c) Copyright 1993, 1994, 1996 International Business Machines Corp. *
32 * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc. *
33 * (c) Copyright 1993, 1994, 1996 Novell, Inc. *
34 * (c) Copyright 1996 Digital Equipment Corporation. *
35 * (c) Copyright 1996 FUJITSU LIMITED. *
36 * (c) Copyright 1996 Hitachi. *
39 #include "TermHeader.h"
40 #include "TermPrimDebug.h"
41 #include "TermPrimI.h"
43 #include "TermBuffer.h"
45 #include "TermPrimData.h"
46 #include "TermFunction.h"
47 #include "TermPrimSetPty.h"
48 #include "TermPrimMessageCatI.h"
49 #include "TermPrimParserP.h"
50 #include "TermParseTable.h"
57 DtEraseMode eraseSwitch,
58 FunctionSource functionSource
63 /*** SCROLL *******************************************************************
65 * #### #### ##### #### # #
70 * #### #### # # #### ###### ######
72 #define EXIT_IF_MARGINS_SET(w) if( (w)->term.tpd->scrollLockTopRow != 0 || \
73 (w)->term.tpd->scrollLockBottomRow != \
78 doScroll(Widget w, short lines)
80 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
81 struct termData *tpd = tw->term.tpd;
84 EXIT_IF_MARGINS_SET(tw)
85 newtop = tpd->topRow + lines;
86 /* don't go past top of active buffer or past end of history buffer */
87 if (newtop>0) newtop=0;
88 if (newtop<-tpd->lastUsedHistoryRow) newtop=-tpd->lastUsedHistoryRow;
89 /* perform scroll... */
90 (void) _DtTermPrimScrollTextTo(w, newtop);
91 (void) _DtTermPrimScrollComplete((Widget) tw, True);
96 _DtTermFuncScroll(Widget w, int count, FunctionSource functionSource)
98 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
99 struct termData *tpd = tw->term.tpd;
101 /* make sure the cursor is off... */
102 (void) _DtTermPrimCursorOff(w);
104 /* and scroll the text... */
105 (void) doScroll(w, count);
106 (void) _DtTermPrimCursorOn(w);
111 _DtTermFuncBeginningOfBuffer(Widget w, int count, FunctionSource functionSource)
113 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
114 DtTermWidget vtw = (DtTermWidget) w;
115 struct termData *tpd = tw->term.tpd;
117 EXIT_IF_MARGINS_SET(tw)
118 /* make sure the cursor is off... */
119 (void) _DtTermPrimCursorOff(w);
120 (void) _DtTermPrimScrollTextTo(w, -tpd->lastUsedHistoryRow);
121 (void) _DtTermPrimScrollComplete((Widget) tw, True);
122 (void) _DtTermPrimCursorOn(w);
126 _DtTermFuncEndOfBuffer(Widget w, int count, FunctionSource functionSource)
128 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
129 struct termData *tpd = tw->term.tpd;
131 EXIT_IF_MARGINS_SET(tw)
132 (void) _DtTermPrimCursorOff(w);
133 (void) _DtTermPrimScrollTextTo(w, 0);
134 (void) _DtTermPrimScrollComplete((Widget) tw, True);
135 (void) _DtTermPrimCursorOn(w);
139 /*** CLEAR MEMORY / LINE ******************************************************
141 * #### # ###### ## #####
146 * #### ###### ###### # # # #
149 * # # ###### # # # # # # # ######
150 * ## ## # ## ## # # # ## # #
151 * # ## # ##### # ## # # # # # # # #####
152 * # # # # # # # # # # # #
153 * # # # # # # # # # ## #
154 * # # ###### # # # ###### # # # ######
158 clearToEndOfMemory(Widget w)
160 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
161 struct termData *tpd = tw->term.tpd;
164 /* clear from current cursor to end of memory... */
165 if (tpd->cursorRow + tpd->topRow < tpd->lastUsedRow) {
166 /* clear the current line to end of memory... */
167 (void) _DtTermPrimBufferClearLine(tpd->termBuffer,
168 tpd->topRow + tpd->cursorRow, tpd->cursorColumn);
170 /* clear the next line to the end of memory... */
171 for (i = tpd->topRow + tpd->cursorRow + 1; i < tpd->lastUsedRow; i++)
172 (void) _DtTermPrimBufferClearLine(tpd->termBuffer, i, 0);
174 /* render the current line from cursor to end of line... */
175 (void) _DtTermPrimRefreshText(w, tpd->cursorColumn, tpd->cursorRow,
176 tw->term.columns, tpd->cursorRow);
178 /* render the rest of the lines... */
179 if (tpd->cursorRow + 1 < tw->term.rows) {
180 (void) _DtTermPrimRefreshText(w, 0, tpd->cursorRow + 1,
181 tw->term.columns, tw->term.rows - 1);
184 /* set the lastUsedRow... */
185 if (tpd->cursorRow > tpd->memoryLockRow) {
186 if (tpd->cursorColumn == 0) {
187 /* don't count the current line -- lastUsedRow is the
190 tpd->lastUsedRow = tpd->topRow + tpd->cursorRow;
192 tpd->lastUsedRow = tpd->topRow + tpd->cursorRow + 1;
195 tpd->lastUsedRow = tpd->topRow + tpd->memoryLockRow + 1;
202 ** Erase characters on the specified row (and clear the enhancements) with
203 ** the appropriate semantics. For VT class emulators, there are several
204 ** ways to erase characters:
205 ** - from the active position to the end of line
206 ** - erase the specified number of characters starting at the current
208 ** - from the start of the line to the active position
209 ** - erase the entire line
210 ** - from the active position to the end of the buffer
211 ** - erase the specified number of lines starting at the current
213 ** - from the start of the buffer to the active position
214 ** - erase the entire buffer
216 ** We handle the easy stuff here, and pass the rest to _DtTermBufferErase.
223 DtEraseMode eraseSwitch,
224 FunctionSource functionSource
227 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
228 DtTermPrimData tpd = tw->term.tpd;
229 TermBuffer tb = tpd->termBuffer;
233 row = tpd->cursorRow + tpd->topRow;
234 col = tpd->cursorColumn;
240 ** erase from the current cursor position to the end of the line
242 _DtTermFuncClearToEndOfLine(w, 1, functionSource);
247 ** erase the current line
249 _DtTermFuncClearLine(w, 1, functionSource);
253 (void) _DtTermFuncClearToEndOfBuffer(w, 1, functionSource);
256 case eraseFromRow0Col0:
258 ** first clear all lines from the top of the screen upto the
261 row = tpd->cursorRow;
262 col = tpd->cursorColumn;
264 tpd->cursorColumn = 0;
265 for (tpd->cursorRow = tpd->topRow;
266 tpd->cursorRow < row;
269 _DtTermFuncClearLine(w, 1, functionSource);
271 tpd->cursorRow = row;
272 tpd->cursorColumn = col;
275 ** now clear all characters from col 0 to the current cursor position
276 ** on the current line...
278 _DtTermBufferErase(((DtTermPrimitiveWidget)w)->term.tpd->termBuffer,
279 tpd->cursorRow + tpd->topRow, tpd->cursorColumn,
280 count, eraseFromCol0);
282 (void) _DtTermPrimRefreshText(w, 0, tpd->cursorRow,
283 tpd->cursorColumn + 1 + (tpd->mbCurMax > 1 ? 1:0),
288 (void) _DtTermFuncClearBuffer(w, 0, functionSource);
292 _DtTermBufferErase(((DtTermPrimitiveWidget)w)->term.tpd->termBuffer,
293 tpd->cursorRow + tpd->topRow, tpd->cursorColumn,
295 (void) _DtTermPrimRefreshText(w, 0, tpd->cursorRow,
296 tpd->cursorColumn + 1 + (tpd->mbCurMax > 1 ? 1:0),
299 _DtTermBufferErase(((DtTermPrimitiveWidget)w)->term.tpd->termBuffer,
300 tpd->cursorRow + tpd->topRow, tpd->cursorColumn,
302 (void) _DtTermPrimRefreshText(w,
303 tpd->cursorColumn - (tpd->mbCurMax > 1 ? 1:0),
305 tpd->cursorColumn + count + (tpd->mbCurMax > 1 ? 1:0),
312 _DtTermFuncEraseInDisplay
316 FunctionSource functionSource
319 termFuncErase(w, 0, (DtEraseMode)count, functionSource);
323 _DtTermFuncEraseInLine
327 FunctionSource functionSource
330 termFuncErase(w, 0, (DtEraseMode)count, functionSource);
334 _DtTermFuncEraseCharacter
338 FunctionSource functionSource
341 termFuncErase(w, count, eraseCharCount, functionSource);
345 _DtTermFuncClearToEndOfBuffer(Widget w, int count, FunctionSource functionSource)
347 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
348 DtTermPrimData tpd = tw->term.tpd;
351 /* turn the cursor off... */
352 (void) _DtTermPrimCursorOff(w);
354 (void) clearToEndOfMemory(w);
359 _DtTermFuncClearBuffer(Widget w, int count, FunctionSource functionSource)
361 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
362 DtTermWidget vtw = (DtTermWidget) w;
363 struct termData *tpd = tw->term.tpd;
366 /* turn the cursor off... */
367 (void) _DtTermPrimCursorOff(w);
369 /* move the cursor to the first line after locked memory... */
370 /* move to cusor column 0 for now so that we will clear the entire
373 tpd->cursorColumn = 0;
376 /* and clear from the current cursor position to end of memory... */
377 (void) clearToEndOfMemory(w);
379 /* and set the final cursor position if origin mode */
380 if ( vtw->vt.td->originMode) {
381 tpd->cursorRow = vtw->term.tpd->scrollLockTopRow;
387 _DtTermFuncClearLine(Widget w, int count, FunctionSource functionSource)
389 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
390 struct termData *tpd = tw->term.tpd;
393 if (tpd->topRow + tpd->cursorRow < tpd->lastUsedRow) {
394 /* get the current width... */
395 lineWidth = _DtTermPrimBufferGetLineWidth(tpd->termBuffer,
396 tpd->topRow + tpd->cursorRow);
398 (void) _DtTermPrimBufferClearLine(tpd->termBuffer,
399 tpd->topRow + tpd->cursorRow, 0);
400 /* render the line. We only need to refresh the old line
404 (void) _DtTermPrimRefreshText(w, 0, tpd->cursorRow, lineWidth,
411 _DtTermFuncClearToEndOfLine(Widget w, int count, FunctionSource functionSource)
413 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
414 struct termData *tpd = tw->term.tpd;
417 if (tpd->topRow + tpd->cursorRow < tpd->lastUsedRow) {
418 /* turn the cursor off... */
419 (void) _DtTermPrimCursorOff(w);
421 /* get the current width... */
422 lineWidth = _DtTermPrimBufferGetLineWidth(tpd->termBuffer,
423 tpd->topRow + tpd->cursorRow);
425 if (lineWidth > tpd->cursorColumn) {
426 (void) _DtTermPrimBufferClearLine(tpd->termBuffer,
427 tpd->topRow + tpd->cursorRow, tpd->cursorColumn);
428 /* render the line. We only need to refresh the old line
431 (void) _DtTermPrimRefreshText(w,
432 tpd->cursorColumn - (tpd->mbCurMax > 1 ? 1 : 0),
434 lineWidth, tpd->cursorRow);
436 /* if this is the last row, we are not in memory lock land,
437 * and we are in column 0, it is no longer the last used row...
439 if ((tpd->topRow + tpd->cursorRow == tpd->lastUsedRow - 1) &&
440 (tpd->cursorColumn == 0) &&
441 (tpd->cursorRow > tpd->memoryLockRow)) {
442 tpd->lastUsedRow = tpd->topRow + tpd->cursorRow;
448 ** Delete "count" characters from the buffer, VT class terminals do not
449 ** support delete with wrap, so no need to worry about it.
452 _DtTermFuncDeleteChar
456 FunctionSource functionSource
459 DtTermPrimData tpd = ((DtTermPrimitiveWidget) w)->term.tpd;
464 row = tpd->topRow + tpd->cursorRow;
465 col = tpd->cursorColumn;
467 if (row < tpd->lastUsedRow && count > 0)
470 (void) _DtTermPrimCursorOff(w);
471 _DtTermBufferDelete(tpd->termBuffer, &row, &col, &deleteWidth);
472 (void) _DtTermPrimRefreshText(w, col, row,
473 ((DtTermPrimitiveWidget) w)->term.columns,
480 _DtTermFuncDeleteLine(Widget w, int count, FunctionSource functionSource)
482 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
483 struct termData *tpd = tw->term.tpd;
485 /* we might as well turn the cursor off now, since we will need to
486 * change the cursor column to the left margin when we are done
489 (void) _DtTermPrimCursorOff(w);
490 if (tpd->topRow + tpd->cursorRow < tpd->lastUsedRow) {
491 /* complete any pending scroll if the scroll area has changed... */
492 (void) _DtTermPrimScrollCompleteIfNecessary(w, tpd->cursorRow,
493 tw->term.rows - 1, count);
495 /* clip the line count... */
496 if (count > tpd->scrollLockBottomRow -tpd->scrollLockTopRow +1)
497 count = tpd->scrollLockBottomRow -tpd->scrollLockTopRow +1 ;
499 if (tpd->topRow + tpd->cursorRow + count > tpd->lastUsedRow) {
500 count = tpd->lastUsedRow - (tpd->topRow + tpd->cursorRow);
503 if (tpd->topRow + tpd->cursorRow + count > tpd->scrollLockBottomRow) {
504 count = tpd->scrollLockBottomRow -
505 (tpd->topRow + tpd->cursorRow) + 1;
508 /* special case out when there is a single line and we are
509 * deleting the top line...
511 if (((tpd->lastUsedRow == 1) && (tpd->cursorRow == 0)) ||
512 (tpd->cursorRow + 1 == tpd->lastUsedRow)) {
513 /* we need to clear the line, re-render it, and we are done...
515 (void) _DtTermPrimBufferClearLine(tpd->termBuffer,
516 tpd->topRow + tpd->cursorRow, 0);
517 (void) _DtTermPrimRefreshText(w, 0, tpd->cursorRow, tw->term.columns,
520 /* delete the lines at the cursor...
522 (void) _DtTermPrimBufferDeleteLine(tpd->termBuffer,
523 tpd->topRow + tpd->cursorRow, count, tpd->lastUsedRow);
524 /* delete lines at the cursor from the selection... */
525 (void) _DtTermPrimSelectDeleteLines(w,
526 tpd->lastUsedHistoryRow + tpd->topRow + tpd->cursorRow,
529 /* insert the lines we just deleted at the bottom of the
530 * scrolling region...
532 (void) _DtTermPrimBufferInsertLineFromTB(tpd->termBuffer,
533 tpd->topRow + tpd->scrollLockBottomRow - count + 1,
534 count, insertFromBottom);
535 /* insert lines at the bottom of the scrolling region into
538 (void) _DtTermPrimSelectInsertLines(w,
539 tpd->lastUsedHistoryRow + tpd->topRow +
540 tpd->scrollLockBottomRow - count + 1, count);
542 /* and scroll the text on the screen... */
543 (void) _DtTermPrimScrollTextArea(w, tpd->cursorRow,
544 tpd->scrollLockBottomRow + 1 - tpd->cursorRow, count);
548 /* move to the left margin... */
549 tpd->cursorColumn = tpd->leftMargin;
553 /** HARD/SOFT RESET ***********************************************************
555 * # # ## ##### ##### # #### #### ###### #####
556 * # # # # # # # # # # # # # #
557 * ###### # # # # # # # #### # # ##### #
558 * # # ###### ##### # # # # # # # #
559 * # # # # # # # # # # # # # # #
560 * # # # # # # ##### # #### #### # #
563 * ##### ###### #### ###### #####
565 * # # ##### #### ##### #
568 * # # ###### #### ###### #
571 _DtTermFuncHardReset(Widget w, int count, FunctionSource functionSource)
573 DtTermWidget vtw = (DtTermWidget) w;
574 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
575 struct termData *tpd = tw->term.tpd;
577 (void) _DtTermPrimScrollComplete(w, True);
578 /* ring the bell... */
579 (void) _DtTermPrimBell(w);
580 (void) _DtTermPrimCursorOn(w);
582 _DtTermFuncSoftReset(w, count, functionSource) ;
584 /* Do this after soft reset */
586 vtw->term.reverseVideo = False;
588 tpd->autoLineFeed=False ;
589 vtw->term.jumpScroll = True ;
590 /* auto key repeat is X server issue - do nothing here */
591 _DtTermFuncClearBuffer(w, 0, (FunctionSource) NULL ) ;
592 _DtTermFunctionKeyClear(w) ;
594 (void) _DtTermPrimSetCursorVisible(w, True);
595 (void) _DtTermPrimCursorOn(w);
601 _DtTermFuncSoftReset(Widget w, int count, FunctionSource functionSource)
603 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
604 struct termData *tpd = tw->term.tpd;
605 DtTermWidget vtw = (DtTermWidget) w;
606 DtTermData td = vtw->vt.td;
608 (void) _DtTermPrimScrollComplete(w, True);
609 /* ring the bell... */
610 (void) _DtTermPrimBell(w);
611 /* the following locks don't make sense in the vt context, but
612 I'll initialize them to make sure they're not corrupted in the
615 tpd->keyboardLocked.xferPending = False;
616 tpd->keyboardLocked.error = False;
617 tpd->keyboardLocked.record = False;
619 /* ANSI and vt220 resets (from RM) */
620 tpd->keyboardLocked.escape = False;
621 _DtTermPrimInsertCharUpdate(w, DtTERM_INSERT_CHAR_OFF);
623 /* vt 220 soft resets (DECRST, DECSTBM, from spec) */
624 tpd->autoWrapRight=True; /* We are NOT following the vt spec here*/
625 td->originMode=False;
626 td->applicationMode=False; /* Normal cursor mode */
627 td->applicationKPMode=False; /* Numeric keypad mode */
628 td->originMode=False;
630 tpd->memoryLockMode=SCROLL_LOCKoff ;
631 tpd->scrollLockTopRow = 0;
632 tpd->scrollLockBottomRow = tw->term.rows-1;
633 /* cursor state stuff for next restore cursor (DECRC) */
634 td->saveCursor.cursorRow = 0;
635 td->saveCursor.cursorColumn = 0;
636 td->saveCursor.enhFieldState = FIELD_UNPROTECT;
637 td->saveCursor.enhVideoState = (char)0;
638 td->saveCursor.originMode = False;
639 td->saveCursor.enhFgColorState = 0;
640 td->saveCursor.enhBgColorState = 0;
641 td->saveCursor.GL = &td->G0;
642 td->saveCursor.GR = &td->G0;
643 td->saveCursor.G0 = RENDER_FONT_NORMAL;
644 td->saveCursor.G1 = RENDER_FONT_LINEDRAW;
645 td->saveCursor.G2 = RENDER_FONT_NORMAL;
646 td->saveCursor.G3 = RENDER_FONT_NORMAL;
647 td->saveCursor.singleShiftFont = RENDER_FONT_NORMAL;
648 td->saveCursor.singleShiftPending = False;
649 /* this is saved by termprim td->saveCursor.wrapMode = False ; */
652 ** xterm resets (xterm extensions to DECRST
653 ** xterm does not reset this stuff so I won't either
654 ** td->allow80_132ColMode = False ;
655 ** td->doCursesFixMode = False ;
656 ** td->marginBellMode = False ;
657 ** tpd->logging = False ;
658 ** when implemented in Term, set "NOT alternate buffer"
660 vtw->vt.td->reverseWrapMode = False; /* this is inconsistant with xterm*/
663 /* Set the "other" state variables?
666 td->enhVideoState &= ~VIDEO_MASK;
667 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
668 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhVideo,
672 td->enhFieldState = FIELD_UNPROTECT;
673 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
674 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhField,
678 td->enhFgColorState = 0;
679 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
680 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhFgColor,
681 td->enhFgColorState);
684 td->enhBgColorState = 0;
685 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
686 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhBgColor,
687 td->enhBgColorState);
692 td->G0 = FONT_NORMAL;
693 td->G1 = FONT_NORMAL;
694 td->G2 = FONT_NORMAL;
695 td->G3 = FONT_NORMAL;
696 td->enhFontState = *td->GL;
697 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
698 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhFont,
701 /* reset the parser */
703 ParserContext context ;
704 context = GetParserContext(w) ;
705 context->stateTable = _DtTermStateStart ;
706 _DtTermClearParam(w) ;
709 (void) _DtTermPrimSetCursorVisible(w, True);
710 (void) _DtTermPrimCursorOn(w);
712 /* flush any pending text that we have queued up to send down the
715 (void) _DtTermPrimPendingTextFlush(tpd->pendingWrite);
720 /*** INSERT CHAR/LINE *********************************************************
722 * # # # #### ###### ##### #####
724 * # # # # #### ##### # # #
725 * # # # # # # ##### #
727 * # # # #### ###### # # #
730 * #### # # ## ##### # # # # # ######
731 * # # # # # # # # # # # ## # #
732 * # ###### # # # # # # # # # # #####
733 * # # # ###### ##### # # # # # # #
734 * # # # # # # # # # # # # ## #
735 * #### # # # # # # # ###### # # # ######
739 _DtTermFuncInsertLine(Widget w, int count, FunctionSource functionSource)
741 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
742 struct termData *tpd = tw->term.tpd;
743 int insertedRows = 0;
748 /* as with delete line, turn the cursor off now since we will
749 * pretty much need to turn it off later to change the cursor
750 * column to the left margin...
752 (void) _DtTermPrimCursorOff(w);
754 /* move the cursor to the left column... */
755 tpd->cursorColumn = tpd->leftMargin;
757 /* if the cursor is below used memory, we don't need to do anything...
759 if (tpd->topRow + tpd->cursorRow >= tpd->lastUsedRow) {
763 /* complete any pending scroll if the scroll area has changed... */
764 (void) _DtTermPrimScrollCompleteIfNecessary(w, tpd->cursorRow,
765 tw->term.rows - 1, -count);
767 /* first, insert any unused memory (from below lastUsedRow)... */
768 if (tpd->lastUsedRow < tpd->bufferRows) {
769 /* the most we can insert from the bottom is the number of lines
772 moveCount = tpd->bufferRows - tpd->lastUsedRow;
773 if (moveCount > count) {
779 (void) _DtTermPrimBufferInsertLineFromTB(tpd->termBuffer,
780 tpd->topRow + tpd->cursorRow,
781 moveCount, insertFromBottom);
782 /* inform the selection code that the selection has been moved... */
783 (void) _DtTermPrimSelectInsertLines(w,
784 tpd->lastUsedHistoryRow + tpd->topRow + tpd->cursorRow,
787 /* update screen info and counts... */
789 insertedRows += moveCount;
790 tpd->lastUsedRow += moveCount;
794 /* insert used memory...
796 /* first insert as much as we can from above the screen... */
797 if (count > tpd->topRow) {
798 moveCount = tpd->topRow;
804 /* insert them into the buffer before we modify the selecction...
806 (void) _DtTermPrimBufferInsertLineFromTB(tpd->termBuffer,
807 tpd->topRow + tpd->cursorRow - moveCount,
808 moveCount, insertFromTop);
810 /* delete the lines at the top of the buffer from the selection...
812 (void) _DtTermPrimSelectDeleteLines(w, tpd->lastUsedHistoryRow,
815 /* insert the lines at the bottom of the buffer in the
818 (void) _DtTermPrimSelectInsertLines(w,
819 tpd->lastUsedHistoryRow + tpd->topRow + tpd->cursorRow -
820 moveCount, moveCount);
822 /* update screen info and counts... */
824 insertedRows += moveCount;
825 tpd->topRow -= moveCount;
828 /* now insert whatever else we need from the bottom... */
830 /* DKS: we need to clip here so we don't self destruct... */
834 if ((tpd->cursorRow >= tpd->scrollLockTopRow) &&
835 (tpd->cursorRow <= tpd->scrollLockBottomRow)) {
836 /* scroll within the scroll region. So, take memory
837 * from the bottom of the scroll region instead of the
838 * bottom of memory...
840 /* insert lines into the selection... */
841 (void) _DtTermPrimBufferInsertLine(tpd->termBuffer,
842 tpd->topRow + tpd->cursorRow, moveCount,
843 tpd->scrollLockBottomRow - moveCount + 1);
844 /* then adjust the selection... */
845 (void) _DtTermPrimSelectInsertLines(w,
846 tpd->lastUsedHistoryRow + tpd->topRow + tpd->cursorRow,
849 /* just take the lines from the bottom... */
850 /* we don't need to delete lines from the bottom since
851 * that doesn't move the selection...
853 /* insert lines into the selection... */
854 (void) _DtTermPrimBufferInsertLineFromTB(tpd->termBuffer,
855 tpd->topRow + tpd->cursorRow, moveCount,
857 /* then adjust the selection... */
858 (void) _DtTermPrimSelectInsertLines(w,
859 tpd->lastUsedHistoryRow + tpd->topRow + tpd->cursorRow,
863 /* update screen info and counts... */
865 insertedRows += moveCount;
869 /* now we need to scroll below us. Remember, in order to scroll text
870 * down, the count needs to be *negative*...
872 if ((tpd->cursorRow >= tpd->scrollLockTopRow) &&
873 (tpd->cursorRow <= tpd->scrollLockBottomRow)) {
874 (void) _DtTermPrimScrollTextArea(w, tpd->cursorRow,
875 tpd->scrollLockBottomRow + 1 - tpd->cursorRow, -insertedRows);
877 (void) _DtTermPrimScrollTextArea(w, tpd->cursorRow,
878 tw->term.rows - tpd->cursorRow, -insertedRows);
884 /*** CURSOR MOTION ************************************************************
886 * #### # # ##### #### #### #####
887 * # # # # # # # # # # #
888 * # # # # # #### # # # #
889 * # # # ##### # # # #####
890 * # # # # # # # # # # # #
891 * #### #### # # #### #### # #
894 * # # #### ##### # #### # #
895 * ## ## # # # # # # ## #
896 * # ## # # # # # # # # # #
897 * # # # # # # # # # # #
898 * # # # # # # # # # ##
899 * # # #### # # #### # #
904 _DtTermFuncTab(Widget w, int count, FunctionSource functionSource)
906 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
907 struct termData *tpd = tw->term.tpd;
908 TermBuffer tBuffer = tpd->termBuffer;
911 (void) _DtTermPrimCursorOff(w);
913 /* Move to the next tab stop. Note that this cursor motion is
914 * similar to the right arrow cursor motion in that
915 * it doesn't set the line width until a character is entered.
917 /* DKS: this code currently enforces tabs at every 8 character
918 * positions. It needs to be worked on to support the margins/tabs
921 nextTab = _DtTermPrimBufferGetNextTab(tBuffer, tpd->cursorColumn);
923 /* check to see if we are past the end of the line... */
924 if ((nextTab <= 0) || (nextTab >= tpd->rightMargin)) {
925 tpd->cursorColumn = tpd->rightMargin;
927 tpd->cursorColumn = nextTab;
934 /* The remainder of this file is new for ANSI and should be merged with
935 the above (some of which may be incorrect for ANSI)
938 /*** VIDEO ENHANCEMENTS *******************************************************
940 * # # # ##### ###### ####
942 * # # # # # ##### # #
945 * ## # ##### ###### ####
948 * ###### # # # # ## # # #### ######
949 * # ## # # # # # ## # # # #
950 * ##### # # # ###### # # # # # # #####
951 * # # # # # # ###### # # # # # ###
952 * # # ## # # # # # ## # # # ###
953 * ###### # # # # # # # # #### ###### ###
957 _DtTermVideoEnhancement(Widget w,int value)
959 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
960 DtTermPrimData tpd = tw->term.tpd;
961 DtTermWidget vtw = (DtTermWidget) w;
962 DtTermData td = vtw->vt.td;
963 ParserContext context = GetParserContext(w);
968 td->enhVideoState &= ~VIDEO_MASK ;
971 td->enhFgColorState = 0;
972 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
973 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
974 enhFgColor, td->enhFgColorState);
975 td->enhBgColorState = 0;
976 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
977 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
978 enhBgColor, td->enhBgColorState);
981 case 1: /* Bold... */
982 td->enhVideoState |= BOLD;
983 td->enhVideoState &= ~HALF_BRIGHT ;
986 case 2: /* Half bright... */
987 td->enhVideoState |= HALF_BRIGHT ;
988 td->enhVideoState &= ~BOLD ;
991 case 4: /* Underline... */
992 td->enhVideoState |= UNDERLINE;
995 case 5: /* we don't do blink, so use inverse */
996 case 7: /* Inverse Video... */
997 td->enhVideoState |= INVERSE ;
1000 case 8: /* Secure Video... */
1001 td->enhVideoState |= SECURE ;
1004 case 22: /* Half bright off... */
1005 td->enhVideoState &= ~HALF_BRIGHT ;
1006 td->enhVideoState &= ~BOLD ;
1009 case 24: /* Underline off... */
1010 td->enhVideoState &= ~UNDERLINE ;
1013 case 25: /* we don't do blink, so use inverse */
1015 case 27: /* Inverse Video off... */
1016 td->enhVideoState &= ~INVERSE ;
1019 case 28: /* Secure Video off... */
1020 td->enhVideoState &= ~SECURE ;
1031 td->enhFgColorState = value - 30 + 1;
1032 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1033 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
1034 enhFgColor, td->enhFgColorState);
1038 td->enhFgColorState = 0;
1039 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1040 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
1041 enhFgColor, td->enhFgColorState);
1053 td->enhBgColorState = value - 40 + 1;
1054 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1055 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
1056 enhBgColor, td->enhBgColorState);
1060 td->enhBgColorState = 0;
1061 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1062 tpd->topRow + tpd->cursorRow, tpd->cursorColumn,
1063 enhBgColor, td->enhBgColorState);
1068 /* fprintf(stderr,"wrong param in SGR esc seq\n") ;*/
1071 /* set the enhancement */
1072 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1073 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhVideo,
1079 _DtTermFontEnhancement(Widget w,int value)
1081 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
1082 DtTermPrimData tpd = tw->term.tpd;
1083 DtTermWidget vtw = (DtTermWidget) w;
1084 DtTermData td = vtw->vt.td;
1085 ParserContext context = GetParserContext(w);
1087 (void)_DtTermPrimBufferSetEnhancement(tpd->termBuffer,
1088 tpd->topRow + tpd->cursorRow, tpd->cursorColumn, enhFont, value);
1091 /* This are utility functions for the terminal dialog to use to effect the
1094 void _DtTermSetUserKeyLock(
1098 _DtTermWidgetToAppContext(w);
1100 _DtTermAppLock(app);
1101 ((DtTermWidget)w)->vt.td->userKeysLocked = lock_state ;
1102 _DtTermAppUnlock(app);
1105 Boolean _DtTermGetUserKeyLock(
1109 _DtTermWidgetToAppContext(w);
1111 _DtTermAppLock(app);
1112 lock_state = ((DtTermWidget)w)->vt.td->userKeysLocked;
1113 _DtTermAppUnlock(app);
1117 void _DtTermSetAutoLineFeed(
1121 _DtTermWidgetToAppContext(w);
1123 _DtTermAppLock(app);
1124 ((DtTermWidget)w)->vt.td->tpd->autoLineFeed = alf_state ;
1125 _DtTermAppUnlock(app);
1128 Boolean _DtTermGetAutoLineFeed(
1132 _DtTermWidgetToAppContext(w);
1134 _DtTermAppLock(app);
1135 alf_state = ((DtTermWidget)w)->vt.td->tpd->autoLineFeed;
1136 _DtTermAppUnlock(app);
1140 void _DtTermSetCurrentWorkingDirectory(
1144 DtTermWidget vtw = (DtTermWidget) w;
1145 _DtTermWidgetToAppContext(w);
1147 _DtTermAppLock(app);
1148 vtw->term.subprocessCWD =
1149 XtRealloc(vtw->term.subprocessCWD, strlen(cwd) + 1);
1150 (void) strcpy(vtw->term.subprocessCWD, cwd);
1151 _DtTermAppUnlock(app);
1154 char *_DtTermGetCurrentWorkingDirectory(
1157 DtTermWidget vtw = (DtTermWidget) w;
1159 _DtTermWidgetToAppContext(w);
1161 _DtTermAppLock(app);
1162 cwd = vtw->term.subprocessCWD;
1163 _DtTermAppUnlock(app);