Example #1
0
BOOL BEEncoder::EncodeString(LPSTRING s)
{
    WriteRawInt(s->GetLength());
    WriteChar(':');
    WriteRawString(s);
    return TRUE;
}
Example #2
0
 void
 TerminalDisplay::DisplayInfo(const std::vector<std::string>& Options) {
   char infoColIdx = 0;
   if (GetContext()->GetColorizer()) {
      infoColIdx = GetContext()->GetColorizer()->GetInfoColor();
   }
   WriteRawString("\n", 1);
   for (size_t i = 0, n = Options.size(); i < n; ++i) {
     Text t(Options[i], infoColIdx);
     WriteWrappedElement(t, 0, 0, (size_t) -1);
     WriteRawString("\n", 1);
   }
   // Reset position
   Detach();
   Attach();
 }
Example #3
0
 void
 TerminalDisplay::NotifyResetInput() {
   Attach();
   if (IsTTY()) {
     WriteRawString("\n", 1);
   }
   fWriteLen = 0;
   fWritePos = Pos();
 }
Example #4
0
 void
 TerminalDisplayUnix::MoveInternal(char What, size_t n) {
   static const char cmd[] = "\x1b[";
   if (!IsTTY()) return;
   std::string text;
   for (size_t i = 0; i < n; ++i) {
     text += cmd;
     text += What;
   }
   WriteRawString(text.c_str(), text.length());
 }
Example #5
0
void VDJSONWriter::WriteMemberName(const wchar_t *name, size_t len) {
	if (!mbFirstItem)
		Write(L",", 1);
	mbFirstItem = false;

	WriteLine();
	WriteIndent();

	WriteRawString(name, len);
	Write(L": ", 2);
}
Example #6
0
 void
 TerminalDisplayWin::CheckCursorPos() {
   // Did something print something on the screen?
   // I.e. did the cursor move?
   CONSOLE_SCREEN_BUFFER_INFO CSI;
   if (::GetConsoleScreenBufferInfo(fOut, &CSI)) {
     if (CSI.dwCursorPosition.X != fWritePos.fCol
       || CSI.dwCursorPosition.Y != fWritePos.fLine + fStartLine) {
       fStartLine = CSI.dwCursorPosition.Y;
       if (CSI.dwCursorPosition.X) {
         // Whooa - where are we?! Newline and cross fingers:
         WriteRawString("\n", 1);
         ++fStartLine;
       }
       fWritePos.fCol = 0;
       fWritePos.fLine = 0;
       Redraw();
     }
   }
 }
Example #7
0
 void
 TerminalDisplayWin::Attach() {
   // set to noecho
   if (fIsAttached) return;
   if (IsTTY() && !::SetConsoleMode(fOut, fMyMode)) {
     ShowError("attaching to console output");
   }
   CONSOLE_SCREEN_BUFFER_INFO Info;
   if (IsTTY()) {
     if (!::GetConsoleScreenBufferInfo(fOut, &Info)) {
       ShowError("attaching / getting console info");
     } else {
       fStartLine = Info.dwCursorPosition.Y;
       if (Info.dwCursorPosition.X) {
         // Whooa - where are we?! Newline and cross fingers:
         WriteRawString("\n", 1);
         ++fStartLine;
       }
     }
   }
   fIsAttached = true;
 }
Example #8
0
  void
  TerminalDisplayUnix::SetColor(char CIdx, const Color& C) {
    if (!IsTTY()) return;

    // Default color, reset previous bold etc.
    static const char text[] = {(char)0x1b, '[', '0', 'm'};
    WriteRawString(text, sizeof(text));

    if (CIdx == 0) return;

    if (fNColors == 256) {
      int ANSIIdx = GetClosestColorIdx256(C);
      static const char preamble[] = {'\x1b', '[', '3', '8', ';', '5', ';', 0};
      std::string buf(preamble);
      if (ANSIIdx > 100) {
        buf += '0' + (ANSIIdx / 100);
      }
      if (ANSIIdx > 10) {
        buf += '0' + ((ANSIIdx / 10) % 10);
      }
      buf += '0' + (ANSIIdx % 10);
      buf +=  "m";
      WriteRawString(buf.c_str(), buf.length());
    } else {
      int ANSIIdx = GetClosestColorIdx16(C);
      char buf[] = {'\x1b', '[', '3', static_cast<char>('0' + (ANSIIdx % 8)), 'm', 0};
      if (ANSIIdx > 7) buf[2] += 6;
      WriteRawString(buf, 5);
    }

    if (C.fModifiers & Color::kModUnderline) {
      WriteRawString("\033[4m", 4);
    }
    if (C.fModifiers & Color::kModBold) {
      WriteRawString("\033[1m", 4);
    }
    if (C.fModifiers & Color::kModInverse) {
      WriteRawString("\033[7m", 4);
    }

  }
Example #9
0
 void
 TerminalDisplay::NotifyError() {
   Attach();
   WriteRawString("\x07", 1);
 }
Example #10
0
  size_t
  TerminalDisplay::WriteWrappedElement(const Text& Element, size_t TextOffset,
                                       size_t WriteOffset, size_t Requested) {
    size_t Start = TextOffset;
    size_t Remaining = Requested;

    size_t Available = Element.length() - Start;
    if (Requested == (size_t) -1) {
      Requested = Available;
    }

    if (Available > 0) {
      if (Available < Remaining) {
        Remaining = Available;
      }

      while (Remaining > 0) {
        size_t numThisLine = Remaining;

        // How much can this line hold?
        size_t numToEOL = GetWidth() - ((Start + WriteOffset) % GetWidth());
        if (!numToEOL) {
          MoveDown();
          ++fWritePos.fLine;
          MoveFront();
          fWritePos.fCol = 0;
          numToEOL = GetWidth();
        }
        if (numThisLine > numToEOL) {
          numThisLine = numToEOL;
        }

        if (GetContext()->GetColorizer()) {
          // We only write same-color chunks; how long is it?
          const std::vector<char>& Colors = Element.GetColors();
          char ThisColor = Colors[Start];
          size_t numSameColor = 1;
          while (numSameColor < numThisLine
                 && ThisColor == Colors[Start + numSameColor])
            ++numSameColor;
          numThisLine = numSameColor;

          if (ThisColor != fPrevColor) {
            Color C;
            GetContext()->GetColorizer()->GetColor(ThisColor, C);
            SetColor(ThisColor, C);
            fPrevColor = ThisColor;
          }
        }

        WriteRawString(Element.GetText().c_str() + Start, numThisLine);
        fWritePos = IndexToPos(PosToIndex(fWritePos) + numThisLine);
        if (numThisLine == numToEOL) {
          ActOnEOL();
        }

        Start += numThisLine;
        Remaining -= numThisLine;
      }
    }

    if (Requested == Available) {
      size_t VisL = fWriteLen / GetWidth();
      size_t Wrote = WriteOffset + TextOffset + Requested;
      size_t WroteL = Wrote / GetWidth();
      size_t NumToEOL = GetWidth() - (Wrote % GetWidth());
      if (fWriteLen > Wrote && NumToEOL > 0) {
        // Wrote less and not at EOL
        EraseToRight();
      }
      if (WroteL < VisL) {
        Pos prevWC = GetCursor();
        MoveFront();
        fWritePos.fCol = 0;
        for (size_t l = WroteL + 1; l <= VisL; ++l) {
          MoveDown();
          ++fWritePos.fLine;
          EraseToRight();
        }
        Move(prevWC);
      }
    }
    return Remaining;
  }
Example #11
0
 ////////////////////////////////////////////////////////////////////////////////
 /// Invoke this on EOL. Writes out space backspace, to wrap to the next line.
 /// Otherwise, we stay on the same line and the input gets pushed upwards.
 void
 TerminalDisplayUnix::ActOnEOL() {
   if (!IsTTY()) return;
   WriteRawString(" \b", 2);
   //MoveUp();
 }
Example #12
0
 ////////////////////////////////////////////////////////////////////////////////
 /// Erases the input to the right of the cursor.
 void
 TerminalDisplayUnix::EraseToRight() {
   static const char text[] = {(char)0x1b, '[', 'K'}; // ESC[K
   if (!IsTTY()) return;
   WriteRawString(text, sizeof(text));
 }
Example #13
0
 void
 TerminalDisplayUnix::MoveFront() {
   static const char text[] = {(char)0x1b, '[', '1', 'G'};
   if (!IsTTY()) return;
   WriteRawString(text, sizeof(text));
 }
Example #14
0
void VDJSONWriter::WriteString(const wchar_t *s, size_t len) {
	BeginValue();
	WriteRawString(s, len);
}