⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 awterm.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
              2 : bClearHorizontalTabStop(bX+1);
              3 : begin
                    if bY > bPageHeight-1 then
                      Start := bPageHeight
                    else
                      Start := bY+1;
                    bClearVerticalTabStop(Start);
                  end;
              4,
              5 : begin
                    FillChar(bHorizTabStop^, SizeOf(THorizontalTabStop), 0);
                    for Limit := 1 to (cWidth div DefTabStop) do
                      bSetHorizontalTabStop(Limit*DefTabStop);
                  end;
              6 : FillChar(bVertiTabStop^, SizeOf(TVerticalTabStop), 0);
            end;
          end;
        eCVT : {etANSI}
          begin
            if bY < bPageHeight-1 then begin
              bY := bGetNextTabStop(bY+1, Y, bVertiTabStop^,
                                  SizeOf(TVerticalTabStop))-1;

            {Update the caret position}
            bMoveCaret;
            end;
          end;
        eHTJ : {etANSI}
          begin
            X := (bGetNextTabStop(bX+1, 1, bHorizTabStop^,
                                 SizeOf(THorizontalTabStop))-1)-bX;
            Start := (bY*bWidth)+bX;
            Limit := Start+X;
            if Limit > ((bY+1)*bWidth) then
              Limit := ((bY+1)*bWidth);
            if Limit < ((bY+1)*bWidth) then begin
              MoveSize := bWidth-(X+bX);
              Move(bScreenBuffer^[Start], bScreenBuffer^[Limit], MoveSize);
              Move(bAttrBuffer^[Start], bAttrBuffer^[Limit], MoveSize);
              Move(bAttrBufferB^[Start], bAttrBufferB^[Limit], MoveSize);
              Move(bExtAttrBuffer^[Start], bExtAttrBuffer^[Limit], MoveSize);
            end;
            Inc(bX, X);
            ClearPart(Start, Limit);
          end;
        eHTS : {etANSI, etVT100}
          begin
            bSetHorizontalTabStop(bX+1);
          end;
        eTBC : {etANSI}
          begin
            case X of
              0 : bClearHorizontalTabStop(bX+1);
              1 : begin
                    if bY > bPageHeight-1 then
                      Start := bPageHeight
                    else
                      Start := bY+1;
                    bClearVerticalTabStop(Start);
                  end;
              2,
              3 : begin
                    FillChar(bHorizTabStop^, SizeOf(THorizontalTabStop), 0);
                    for Limit := 1 to (cWidth div DefTabStop) do
                      bSetHorizontalTabStop(Limit*DefTabStop);
                  end;
              4 : FillChar(bVertiTabStop^, SizeOf(TVerticalTabStop), 0);
            end;
          end;
        eVTS : {etANSI}
          begin
            if bY > bPageHeight-1 then
              Start := bPageHeight
            else
              Start := bY+1;
            bSetVerticalTabStop(Start);
          end;
        eDECSTBM : {etVT100}
          begin
            cMarginTop := X;
            cMarginBottom := Y;
            bX := bXPos;
            bY := bYPos;
            bInMargins := (cMarginTop = 1);

            {Update the caret position}
            bMoveCaret;
          end;
      end;
    end;
  end;

  procedure TBuffer.bMoveCaret;
    {-Set new caret position}
  begin
    if bFocused then
      SetCaretPos((bX-bXPos)*bCharWidth, (bY-bYPos)*bCharHeight);
  end;

  function TBuffer.bCurLineLength : Word;
    {-Return the length of the current line}
  var
    I : Word;
    Start, Stop : Word;
  begin
    {Find index of end of current line}
    Stop := (bY*bWidth)+bWidth-1;
    Start := (Stop+1)-bWidth;
    for I := Stop downto Start do
      if bScreenBuffer^[I] <> ' ' then begin
        bCurLineLength := (I-Start)+1;
        Exit;
      end;

    {Empty line if we get here}
    bCurLineLength := 0;
  end;

  function TBuffer.bNeedPaint : Bool;
    {-Return True if the RedrawRect is not empty}
  begin
    bNeedPaint := (bRedrawRect.Top - bRedrawRect.Bottom) <> 0;
  end;

  procedure TBuffer.bForcePaint;
    {-Force paint message}
  var
    Rect : TRect;
  begin
    if bNeedPaint then begin
      InvalidateRect(bWnd, @bRedrawRect, False);
      FillChar(bRedrawRect, Sizeof(bRedrawRect), 0);
    end;

    if (bNeedVScroll <> 0) or (bNeedHScroll <> 0) then begin
      {Scroll the client area}
      with Rect do begin
        GetClientRect(bWnd, Rect);
        if not bScrollBack then begin
          Bottom := bCharHeight*cMarginBottom;
          Top := bCharHeight*(cMarginTop-1);                       
        end;
      end;
      ScrollWindow(bWnd, bNeedHScroll, bNeedVScroll, @Rect, nil);

      {Invalidate horizontal non-integral portion of window}
      if bNeedVScroll < 0 then begin
        GetClientRect(bWnd, Rect);
        if not bScrollBack then
          Rect.Bottom := bCharHeight*cMarginBottom;
        Rect.Top := (Rect.Bottom + bNeedVScroll) - bCharHeight;
        InvalidateRect(bWnd, @Rect, True);
      end;

      {Update scroll thumbs}
      if bNeedVScroll <> 0 then
        bUpdateScrollThumb(True);
      if bNeedHScroll <> 0 then
        bUpdateScrollThumb(False);

      {Reset scroll indicators}
      bNeedVScroll := 0;
      bNeedHScroll := 0;

      {Force an update}
      UpdateWindow(bWnd);
    end;

    {User status}
    bPostStatusMsg;
  end;

  procedure TBuffer.bUpdateScrollThumb(Vert : Bool);
    {-Update scroll thumb}
  var
    Current : Word;
    Check : Integer;
  begin
    if Vert then begin
      {Update vertical scroll bar}
      if bScrollBack then
        Current := bYPos+1
      else begin
        Check := bMaxY-bYPos;
        if bPageHeight >= Check then
          Current := bPageHeight - Check
        else
          Current := Check;
      end;
      SetScrollPos(bWnd, sb_Vert, Current-1, True);
    end else begin
      {Update horizontal scrollbar}
      SetScrollPos(bWnd, sb_Horz, bXPos, True);
    end;
  end;

  procedure TBuffer.bScroll(X, Y : Integer);
    {-Handle scrollback and scroll PageHeight within window}
  begin
    if bScrollBack then begin
      {ScrollBack mode}
      if (Y < 0) and (bYPos > 0) then begin
        {Scroll down}
        Y := Abs(Y);
        if Y > bYPos then
          Y := bYPos;
        Dec(bYPos, Y);
        Inc(bNeedVScroll, bCharHeight*Y);
      end else if (Y > 0) and ((bYPos+cHeight) <= bMaxY) then begin
        {Scroll up}
        if (bYPos+Y) > (bMaxY-cHeight+1) then
          Y := (bMaxY-cHeight)-bYPos+1;
        Inc(bYPos, Y);
        Inc(bNeedVScroll, -bCharHeight*Y);
      end;
    end else if (cHeight < bPageHeight) then begin
      {Handle scrolling bPageHeight lines within smaller window}
      if (Y < 0) and (bMaxY-bYPos+1 < bPageHeight) then begin
        {Scroll down}
        Y := Abs(Y);
        if (Y = bPageHeight) then
          {PgUp request, just goto top}
          Y := bYPos-(bMaxY-(bPageHeight-1));
        if (Y > bYPos) then
          Y := bYPos;
        Dec(bYPos, Y);
        Inc(bNeedVScroll, bCharHeight*Y);
      end else if (Y > 0) and (bYPos+cHeight <= bMaxY) then begin
        {Scroll up}
        if (Y= bPageHeight) then
          {PgDn request, just goto bottom}
          Y := (bMaxY-cHeight)-bYPos+1;
        Inc(bYPos, Y);
        Inc(bNeedVScroll, -bCharHeight*Y);
      end;
    end;

    {Horizontal scrolling is same in either mode}
    if (X < 0) and (bXPos <> 0) then begin
      {Scroll left}
      X := Abs(X);
      if X > bXPos then
        X := bXPos;
      Inc(bNeedHScroll, bCharWidth*X);
      Dec(bXPos, X);
    end else if (X > 0) and (bXPos+cWidth < bWidth) then begin
      {Scroll right}
      if X+bXPos+cWidth > bWidth then
        X := bWidth-(bXPos+cWidth);
      Dec(bNeedHScroll, bCharWidth*X);
      Inc(bXPos, X);
    end;

    {Update scroll thumbs}
    bUpdateScrollThumb(True);
    bUpdateScrollThumb(False);

    {Force a paint message}
    bForcePaint;
  end;

  procedure TBuffer.bGotoTop(Vert : Boolean);
    {-Handle "goto top" requests}
  var
    Y : Integer;
  begin
    if Vert then begin
      {Vertical "top" request}
      if bScrollBack then begin
        {ScrollBack mode}
        bYPos := 0;
        InvalidateRect(bWnd, nil, False);
      end else begin
        {Goto top of window}
        Y := bYPos-(bMaxY-(bPageHeight-1));
        if (Y > bYPos) then
          Y := bYPos;
        Dec(bYPos, Y);
        Inc(bNeedVScroll, bCharHeight*Y);
      end;
    end else begin
      {Horizontal "top" request}
      bXPos := 0;
      InvalidateRect(bWnd, nil, False);
    end;

    {Update scroll thumbs}
    bUpdateScrollThumb(True);
    bUpdateScrollThumb(False);

    {User status}
    bPostStatusMsg;
  end;

  procedure TBuffer.bGotoBottom(Vert : Boolean);
    {-Handle "goto bottom" requests}
  var
    Y : Integer;
  begin
    if Vert then begin
      {Vertical "bottom" request}
      if bScrollBack then begin
        {ScrollBack mode}
        if bMaxY > cHeight then
          bYPos := bMaxY-cHeight
        else
          bYPos := 1;
        InvalidateRect(bWnd, nil, False);
      end else begin
        {Goto bottom of window}
        Y := (bMaxY-cHeight)-bYPos+1;
        Inc(bYPos, Y);
        Inc(bNeedVScroll, -bCharHeight*Y);
      end;
    end else begin
      {Horizontal "bottom" request}
      bXPos := bWidth-cWidth;
      InvalidateRect(bWnd, nil, False);
    end;

    {Update scroll thumbs}
    bUpdateScrollThumb(True);
    bUpdateScrollThumb(False);

    {User status}
    bPostStatusMsg;
  end;

  function TBuffer.bConvertToRow(I : Integer) : Word;
    {-Return the row for this pixel value}
  var
    Row : Word;
  begin
    if I < 0 then
      I := 0;
    if bCharHeight <> 0 then begin
      Row := I div bCharHeight;
      if (I mod bCharHeight = 0) and (I <> 0) then
        Dec(Row);
      Inc(Row, bYPos);
    end else
      Row := 0;
    bConvertToRow := Row;
  end;

  function TBuffer.bConvertToCol(I : Integer) : Word;
    {-Return the col for this pixel value}
  var
    Col : Word;
  begin
    if I < 0 then
      I := 0;
    if bCharWidth <> 0 then begin
      Col := I div bCharWidth;
      if (I mod bCharHeight = 0) and (I <> 0) then
        Dec(Col);
      Inc(Col, bXPos);
    end else
      Col := 0;
    bConvertToCol := Col;
  end;

  procedure TBuffer.bResetMarking;
    {-Get rid of current marking}
  begin
    bMarking := False;
    bMarked := False;
    bOffScreen := False;
    bMarkAnchorX := 0;
    bMarkAnchorY := 0;
    bMarkStartX := 0;
    bMarkStartY := 0;
    bMarkEndX := 0;
    bMarkEndY := 0;
    bScrollTimer := 0;
  end;

  procedure TBuffer.bFixMarking(NewX, NewY : Word);
    {-Set new mark limit}
  begin
    if (NewY > bMarkAnchorY) or
       ((NewY = bMarkAnchorY) and (NewX > bMarkAnchorX)) then begin
      {Note new end}
      bMarkEndX := NewX;
      bMarkEndY := NewY;
      bMarkStartX := bMarkAnchorX;
      bMarkStartY := bMarkAnchorY;
    end else if (NewY < bMarkAnchorY) or
       ((NewY = bMarkAnchorY) and (NewX < bMarkAnchorX)) then begin
      {Note new start}
      bMarkStartX := NewX;
      bMarkStartY := NewY;
      bMarkEndX := bMarkAnchorX;
      bMarkEndY := bMarkAnchorY;
    end;
  end;

  procedure TBuffer.bUpdateMarks(RawX, RawY : Integer);
    {-Update new mouse position}
  var
    NewX, NewY : Word;
  begin
    if bMarki

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -