1 /* 2 * Copyright 2012-2015, Adrien Destugues, pulkomandy@gmail.com 3 * Distributed under the terms of the MIT licence. 4 */ 5 6 7 #include <String.h> 8 #include <View.h> 9 10 extern "C" { 11 #include <vterm.h> 12 } 13 14 15 class TermView: public BView 16 { 17 public: 18 TermView(); 19 TermView(BRect bounds); 20 ~TermView(); 21 22 void AttachedToWindow(); 23 void Draw(BRect updateRect); 24 void FrameResized(float width, float height); 25 void GetPreferredSize(float* width, float* height); 26 void KeyDown(const char* bytes, int32 numBytes); 27 void MessageReceived(BMessage* message); 28 void SetLineTerminator(BString bytes); 29 30 void PushBytes(const char* bytes, const size_t length); 31 32 private: 33 void _Init(); 34 35 VTermRect _PixelsToGlyphs(BRect pixels) const; 36 BRect _GlyphsToPixels(const VTermRect& glyphs) const; 37 BRect _GlyphsToPixels(const int width, const int height) 38 const; 39 void _GetCell(VTermPos pos, VTermScreenCell& cell); 40 41 void _Damage(VTermRect rect); 42 void _MoveCursor(VTermPos pos, VTermPos oldPos, 43 int visible); 44 void _PushLine(int cols, const VTermScreenCell* cells); 45 46 static int _Damage(VTermRect rect, void* user); 47 static int _MoveCursor(VTermPos pos, VTermPos oldPos, 48 int visible, void* user); 49 static int _PushLine(int cols, const VTermScreenCell* cells, 50 void* user); 51 static int _PopLine(int cols, const VTermScreenCell* cells, 52 void* user); 53 54 private: 55 VTerm* fTerm; 56 VTermScreen* fTermScreen; 57 BList fScrollBuffer; 58 int fFontWidth; 59 int fFontHeight; 60 61 BString fLineTerminator; 62 63 static const VTermScreenCallbacks sScreenCallbacks; 64 65 static const int kDefaultWidth = 80; 66 static const int kDefaultHeight = 25; 67 static const int kBorderSpacing = 3; 68 static const int kScrollBackSize = 10000; 69 }; 70