From 7c8babf9f91364988f80ac455926f98f0589adb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 21 Jun 2022 01:37:12 -0300 Subject: [PATCH] eterm: Refactor to eepp coding style. Added mouse support. Improved cursor support. --- include/eepp/system/color.hpp | 6 + projects/linux/ee.creator.user | 2 +- src/eepp/system/color.cpp | 22 + src/tools/eterm/eterm.cpp | 20 +- src/tools/eterm/eterminaldisplay.cpp | 427 +++--- src/tools/eterm/eterminaldisplay.hpp | 81 +- src/tools/eterm/system/autohandle.cpp | 10 +- src/tools/eterm/system/autohandle.hpp | 20 +- src/tools/eterm/system/ipipe.hpp | 6 +- src/tools/eterm/system/iprocess.hpp | 10 +- src/tools/eterm/system/iprocessfactory.hpp | 4 +- src/tools/eterm/system/pipe.cpp | 6 +- src/tools/eterm/system/pipe.hpp | 37 +- src/tools/eterm/system/process.cpp | 30 +- src/tools/eterm/system/process.hpp | 57 +- src/tools/eterm/system/processfactory.cpp | 10 +- src/tools/eterm/system/processfactory.hpp | 4 +- src/tools/eterm/terminal/ipseudoterminal.hpp | 6 +- src/tools/eterm/terminal/pseudoterminal.cpp | 34 +- src/tools/eterm/terminal/pseudoterminal.hpp | 41 +- src/tools/eterm/terminal/terminaldisplay.cpp | 26 +- src/tools/eterm/terminal/terminaldisplay.hpp | 59 +- src/tools/eterm/terminal/terminalemulator.cpp | 1169 +++++++++-------- src/tools/eterm/terminal/terminalemulator.hpp | 212 +-- src/tools/eterm/terminal/types.hpp | 48 +- 25 files changed, 1254 insertions(+), 1093 deletions(-) diff --git a/include/eepp/system/color.hpp b/include/eepp/system/color.hpp index e11b0528b..50114d686 100644 --- a/include/eepp/system/color.hpp +++ b/include/eepp/system/color.hpp @@ -162,6 +162,12 @@ class EE_API Color : public tColor { Colorf toHsl() const; + Color clone() const; + + Color invert() const; + + Color div( int divisor, bool divAlpha = false ); + std::string toHexString( const bool& prependHash = true ) const; std::string toRgbaString() const; diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 201468689..a756a5006 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/eepp/system/color.cpp b/src/eepp/system/color.cpp index 39cffaeb3..860744394 100644 --- a/src/eepp/system/color.cpp +++ b/src/eepp/system/color.cpp @@ -239,6 +239,28 @@ Colorf Color::toHsl() const { return hsl; } +Color Color::clone() const { + return Color( *this ); +} + +Color Color::invert() const { + Uint32 red = ( getValue() >> 24 ) & 0xFF; + Uint32 green = ( getValue() >> 16 ) & 0xFF; + Uint32 blue = ( getValue() >> 8 ) & 0xFF; + Uint32 alpha = ( getValue() >> 0 ) & 0xFF; + return Color( ( ~red ) & 0xFF, ( ~green ) & 0xFF, ( ~blue ) & 0xFF, alpha ); +} + +Color Color::div( int divisor, bool divAlpha ) { + Color c( *this ); + c.r /= divisor; + c.g /= divisor; + c.b /= divisor; + if ( divAlpha ) + c.a /= divisor; + return c; +} + std::string Color::toHexString( const bool& prependHashtag ) const { std::stringstream stream; if ( prependHashtag ) diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 624ad36e2..01cfcaf35 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -40,6 +40,7 @@ void inputCallback( InputEvent* event ) { break; } case InputEvent::VideoExpose: + terminal->setFocus( win->hasFocus() ); terminal->invalidate(); break; case InputEvent::VideoResize: { @@ -52,11 +53,11 @@ void inputCallback( InputEvent* event ) { void mainLoop() { win->getInput()->update(); - terminal->Update(); + terminal->update(); if ( terminal->isDirty() ) { win->clear(); - terminal->Draw( win->hasFocus() ); + terminal->draw(); win->display(); } else { win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); @@ -85,15 +86,7 @@ EE_MAIN_FUNC int main( int, char*[] ) { FontTrueType* fontMono = FontTrueType::New( "monospace" ); fontMono->loadFromFile( "assets/fonts/DejaVuSansMono.ttf" ); - if ( !terminal || terminal->HasTerminated() ) { - auto fontSize = PixelDensity::dpToPx( 12 ); - auto charWidth = fontMono->getGlyph( 'A', fontSize, false ).advance; - auto charHeight = terminal ? terminal->getFontSize() : fontSize; - Sizef contentRegion = win->getSize().asFloat(); - - auto columns = (int)std::floor( std::max( 1.0f, contentRegion.x / charWidth ) ); - auto rows = (int)std::floor( std::max( 1.0f, contentRegion.y / charHeight ) ); - + if ( !terminal || terminal->hasTerminated() ) { std::string shell; const char* shellenv = getenv( "SHELL" ); if ( shellenv != nullptr ) { @@ -102,9 +95,8 @@ EE_MAIN_FUNC int main( int, char*[] ) { shell = "/bin/bash"; } - terminal = ETerminalDisplay::Create( win, fontMono, columns, rows, shell, {}, "", 0 ); - terminal->setFontSize( charHeight ); - terminal->setSize( win->getSize().asFloat() ); + terminal = ETerminalDisplay::create( win, fontMono, PixelDensity::dpToPx( 12 ), + win->getSize().asFloat(), shell, {}, "", 0 ); } win->getInput()->pushCallback( &inputCallback ); diff --git a/src/tools/eterm/eterminaldisplay.cpp b/src/tools/eterm/eterminaldisplay.cpp index 77a1f0226..3d4278cc1 100644 --- a/src/tools/eterm/eterminaldisplay.cpp +++ b/src/tools/eterm/eterminaldisplay.cpp @@ -27,7 +27,8 @@ TerminalKeyMap::TerminalKeyMap( const TerminalKey keys[], size_t keysLen, } } -static TerminalShortcut shortcuts[] = { { KEY_INSERT, KEYMOD_SHIFT, ShortcutAction::PASTE, 0, 0 } }; +static TerminalShortcut shortcuts[] = { + { KEY_INSERT, KEYMOD_SHIFT, TerminalShortcutAction::PASTE, 0, 0 } }; static TerminalKey keys[] = { /* keysym mask string appkey appcursor */ @@ -309,24 +310,32 @@ static const Color colormapped[256] = { Color( 208, 208, 208 ), Color( 218, 218, 218 ), Color( 228, 228, 228 ), Color( 238, 238, 238 ) }; -std::shared_ptr -ETerminalDisplay::Create( EE::Window::Window* window, Font* font, - std::shared_ptr&& terminalEmulator, - TerminalConfig* config ) { +std::shared_ptr ETerminalDisplay::create( + EE::Window::Window* window, Font* font, const Float& fontSize, const Sizef& pixelsSize, + std::shared_ptr&& terminalEmulator, TerminalConfig* config ) { std::shared_ptr terminal = std::shared_ptr( - new ETerminalDisplay( window, font, terminalEmulator->GetNumColumns(), - terminalEmulator->GetNumRows(), config ) ); - terminal->m_terminal = std::move( terminalEmulator ); + new ETerminalDisplay( window, font, fontSize, pixelsSize, config ) ); + terminal->mTerminal = std::move( terminalEmulator ); return terminal; } static EE::System::IProcessFactory* g_processFactory = new EE::System::ProcessFactory(); +static Sizei gridSizeFromTermDimensions( Font* font, const Float& fontSize, + const Sizef& pixelsSize ) { + auto fontHeight = (Float)font->getFontHeight( fontSize ); + auto spaceCharAdvanceX = font->getGlyph( 'A', fontSize, false ).advance; + auto clipColumns = + (int)std::floor( std::max( 1.0f, pixelsSize.getWidth() / spaceCharAdvanceX ) ); + auto clipRows = (int)std::floor( std::max( 1.0f, pixelsSize.getHeight() / fontHeight ) ); + return { clipColumns, clipRows }; +} + std::shared_ptr -ETerminalDisplay::Create( EE::Window::Window* window, Font* font, int columns, int rows, - const std::string& program, const std::vector& args, - const std::string& workingDir, uint32_t options, - EE::System::IProcessFactory* processFactory ) { +ETerminalDisplay::create( EE::Window::Window* window, Font* font, const Float& fontSize, + const Sizef& pixelsSize, const std::string& program, + const std::vector& args, const std::string& workingDir, + uint32_t options, EE::System::IProcessFactory* processFactory ) { using namespace EE::System; TerminalConfig config{}; @@ -336,10 +345,11 @@ ETerminalDisplay::Create( EE::Window::Window* window, Font* font, int columns, i processFactory = g_processFactory; } + Sizei termSize( gridSizeFromTermDimensions( font, fontSize, pixelsSize ) ); std::unique_ptr pseudoTerminal = nullptr; std::vector argsV( args.begin(), args.end() ); - auto process = processFactory->CreateWithPseudoTerminal( program, argsV, workingDir, columns, - rows, pseudoTerminal ); + auto process = processFactory->createWithPseudoTerminal( + program, argsV, workingDir, termSize.getWidth(), termSize.getHeight(), pseudoTerminal ); if ( !pseudoTerminal ) { fprintf( stderr, "Failed to create pseudo terminal\n" ); @@ -352,186 +362,192 @@ ETerminalDisplay::Create( EE::Window::Window* window, Font* font, int columns, i } std::shared_ptr terminal = std::shared_ptr( - new ETerminalDisplay( window, font, columns, rows, &config ) ); - terminal->m_terminal = - TerminalEmulator::Create( std::move( pseudoTerminal ), std::move( process ), terminal ); + new ETerminalDisplay( window, font, fontSize, pixelsSize, &config ) ); + + terminal->mTerminal = + TerminalEmulator::create( std::move( pseudoTerminal ), std::move( process ), terminal ); return terminal; } -ETerminalDisplay::ETerminalDisplay( EE::Window::Window* window, Font* font, int columns, int rows, - TerminalConfig* config ) : - TerminalDisplay(), mWindow( window ), mFont( font ), m_columns( columns ), m_rows( rows ) { +ETerminalDisplay::ETerminalDisplay( EE::Window::Window* window, Font* font, const Float& fontSize, + const Sizef& pixelsSize, TerminalConfig* config ) : + TerminalDisplay(), + mWindow( window ), + mFont( font ), + mFontSize( fontSize ), + mSize( pixelsSize ) { + if ( config != nullptr ) { if ( config->options & OPTION_COLOR_EMOJI ) - m_useColorEmoji = true; + mUseColorEmoji = true; if ( config->options & OPTION_NO_BOXDRAWING ) - m_useBoxDrawing = false; + mUseBoxDrawing = false; if ( config->options & OPTION_PASTE_CRLF ) - m_pasteNewlineFix = true; + mPasteNewlineFix = true; } TerminalGlyph defaultGlyph; defaultGlyph.mode = ATTR_INVISIBLE; auto defaultColor = std::make_pair( 0U, "" ); - m_cursorg = defaultGlyph; - m_colors.resize( eeARRAY_SIZE( colornames ), defaultColor ); - m_buffer.resize( m_columns * m_rows, defaultGlyph ); + mCursorGlyph = defaultGlyph; + mColors.resize( eeARRAY_SIZE( colornames ), defaultColor ); + mBuffer.resize( mColumns * mRows, defaultGlyph ); ( (int&)mMode ) |= MODE_FOCUSED; if ( config != nullptr ) { if ( config->options & OPTION_COLOR_EMOJI ) - m_useColorEmoji = true; + mUseColorEmoji = true; if ( config->options & OPTION_NO_BOXDRAWING ) - m_useBoxDrawing = false; + mUseBoxDrawing = false; if ( config->options & OPTION_PASTE_CRLF ) - m_pasteNewlineFix = true; + mPasteNewlineFix = true; } } -void ETerminalDisplay::ResetColors() { +void ETerminalDisplay::resetColors() { for ( Uint32 i = 0; i < eeARRAY_SIZE( colornames ); i++ ) { - ResetColor( i, colornames[i] ); + resetColor( i, colornames[i] ); } } -int ETerminalDisplay::ResetColor( int index, const char* name ) { +int ETerminalDisplay::resetColor( int index, const char* name ) { if ( !name ) { - if ( index >= 0 && index < (int)m_colors.size() ) { + if ( index >= 0 && index < (int)mColors.size() ) { Color col = 0x000000FF; if ( index < 256 ) col = colormapped[index]; - m_colors[index].first = col; - m_colors[index].second = ""; + mColors[index].first = col; + mColors[index].second = ""; return 0; } } - if ( index >= 0 && index < (int)m_colors.size() ) { - m_colors[index].first = Color::fromString( name ); - m_colors[index].second = name; + if ( index >= 0 && index < (int)mColors.size() ) { + mColors[index].first = Color::fromString( name ); + mColors[index].second = name; } return 1; } -void ETerminalDisplay::Update() { - if ( m_terminal ) - m_terminal->Update(); +void ETerminalDisplay::update() { + if ( mClock.getElapsedTime().asSeconds() > 0.7 ) { + mMode ^= MODE_BLINK; + mClock.restart(); + invalidate(); + } + if ( mTerminal ) + mTerminal->update(); } -void ETerminalDisplay::Action( ShortcutAction action ) { - if ( action == ShortcutAction::PASTE ) { - auto clipboard = GetClipboard(); +void ETerminalDisplay::action( TerminalShortcutAction action ) { + if ( action == TerminalShortcutAction::PASTE ) { + auto clipboard = getClipboard(); auto clipboardLen = strlen( clipboard ); if ( clipboardLen > 0 ) { - m_terminal->Write( clipboard, clipboardLen ); + mTerminal->write( clipboard, clipboardLen ); } } } -bool ETerminalDisplay::HasTerminated() const { - return m_terminal->HasExited(); +bool ETerminalDisplay::hasTerminated() const { + return mTerminal->hasExited(); } -void ETerminalDisplay::SetTitle( const char* ) {} +void ETerminalDisplay::setTitle( const char* ) {} -void ETerminalDisplay::SetIconTitle( const char* ) {} +void ETerminalDisplay::setIconTitle( const char* ) {} -void ETerminalDisplay::SetClipboard( const char* text ) { +void ETerminalDisplay::setClipboard( const char* text ) { if ( text == nullptr ) return; mClipboard = text; mWindow->getClipboard()->setText( mClipboard ); } -const char* ETerminalDisplay::GetClipboard() const { +const char* ETerminalDisplay::getClipboard() const { mClipboard = mWindow->getClipboard()->getText(); return mClipboard.c_str(); } -bool ETerminalDisplay::DrawBegin( int columns, int rows ) { - if ( columns != m_columns || rows != m_rows ) { +bool ETerminalDisplay::drawBegin( int columns, int rows ) { + if ( columns != mColumns || rows != mRows ) { TerminalGlyph defaultGlyph{}; - m_buffer.resize( columns * rows, defaultGlyph ); - m_columns = columns; - m_rows = rows; + mBuffer.resize( columns * rows, defaultGlyph ); + mColumns = columns; + mRows = rows; invalidate(); } return ( ( mMode & MODE_VISIBLE ) != 0 ); } -void ETerminalDisplay::DrawLine( Line line, int x1, int y, int x2 ) { - memcpy( &m_buffer[y * m_columns + x1], line, ( x2 - x1 ) * sizeof( TerminalGlyph ) ); +void ETerminalDisplay::drawLine( Line line, int x1, int y, int x2 ) { + memcpy( &mBuffer[y * mColumns + x1], line, ( x2 - x1 ) * sizeof( TerminalGlyph ) ); for ( int i = x1; i < x2; i++ ) { - if ( m_terminal->selected( i, y ) ) { - m_buffer[y * m_columns + i].mode |= ATTR_REVERSE; + if ( mTerminal->selected( i, y ) ) { + mBuffer[y * mColumns + i].mode |= ATTR_REVERSE; } } invalidate(); } -void ETerminalDisplay::DrawCursor( int cx, int cy, TerminalGlyph g, int, int, TerminalGlyph ) { - if ( m_cursor != Vector2i( cx, cy ) || m_cursorg != g ) { - m_cursor.x = cx; - m_cursor.y = cy; - m_cursorg = g; +void ETerminalDisplay::drawCursor( int cx, int cy, TerminalGlyph g, int, int, TerminalGlyph ) { + if ( mCursor != Vector2i( cx, cy ) || mCursorGlyph != g ) { + mCursor.x = cx; + mCursor.y = cy; + mCursorGlyph = g; invalidate(); } } -void ETerminalDisplay::DrawEnd() {} +void ETerminalDisplay::drawEnd() {} -void ETerminalDisplay::Draw( bool hasFocus ) { - bool modeFocus = mMode & MODE_FOCUSED; - if ( hasFocus != modeFocus ) { - if ( hasFocus ) { - mMode |= MODE_FOCUSED | MODE_FOCUS; - } else { - mMode ^= MODE_FOCUS | MODE_FOCUSED; - } - } else { - mMode ^= MODE_FOCUS; - } - - Draw( mPosition ); +void ETerminalDisplay::draw() { + draw( mPosition ); } void ETerminalDisplay::onMouseMotion( const Vector2i& pos, const Uint32& flags ) { if ( ( flags & EE_BUTTON_LMASK ) && - ( m_terminal->getSelectionMode() == selection_mode::SEL_EMPTY || - m_terminal->getSelectionMode() == selection_mode::SEL_READY ) ) { + ( mTerminal->getSelectionMode() == TerminalSelectionMode::SEL_EMPTY || + mTerminal->getSelectionMode() == TerminalSelectionMode::SEL_READY ) ) { auto gridPos{ positionToGrid( pos ) }; - m_terminal->selextend( + mTerminal->selextend( gridPos.x, gridPos.y, mWindow->getInput()->getModState() == KEYMOD_SHIFT ? SEL_RECTANGULAR : SEL_REGULAR, 0 ); invalidate(); } + mTerminal->mousereport( TerminalMouseEventType::MouseMotion, positionToGrid( pos ), flags, + mWindow->getInput()->getModState() ); } void ETerminalDisplay::onMouseDown( const Vector2i& pos, const Uint32& flags ) { if ( ( flags & EE_BUTTON_LMASK ) && - ( m_terminal->getSelectionMode() == selection_mode::SEL_IDLE ) ) { + ( mTerminal->getSelectionMode() == TerminalSelectionMode::SEL_IDLE ) ) { auto gridPos{ positionToGrid( pos ) }; - m_terminal->selstart( gridPos.x, gridPos.y, 0 ); + mTerminal->selstart( gridPos.x, gridPos.y, 0 ); invalidate(); } + mTerminal->mousereport( TerminalMouseEventType::MouseButtonDown, positionToGrid( pos ), flags, + mWindow->getInput()->getModState() ); } -void ETerminalDisplay::onMouseUp( const Vector2i&, const Uint32& flags ) { +void ETerminalDisplay::onMouseUp( const Vector2i& pos, const Uint32& flags ) { if ( ( flags & EE_BUTTON_LMASK ) ) { - auto selection = m_terminal->getsel(); + auto selection = mTerminal->getsel(); if ( selection ) - SetClipboard( selection ); - m_terminal->selclear(); + setClipboard( selection ); + mTerminal->selclear(); invalidate(); } + mTerminal->mousereport( TerminalMouseEventType::MouseButtonRelease, positionToGrid( pos ), + flags, mWindow->getInput()->getModState() ); } -static inline Color GetCol( unsigned int terminalColor, - const std::vector>& colors ) { +static inline Color termColor( unsigned int terminalColor, + const std::vector>& colors ) { if ( ( terminalColor & ( 1 << 24 ) ) == 0 ) { return colors[terminalColor & 0xFF].first; } @@ -541,24 +557,15 @@ static inline Color GetCol( unsigned int terminalColor, #define BETWEEN( x, a, b ) ( ( a ) <= ( x ) && ( x ) <= ( b ) ) #define IS_SET( flag ) ( ( mMode & ( flag ) ) != 0 ) -#define COL32_R_SHIFT 24 -#define COL32_G_SHIFT 16 -#define COL32_B_SHIFT 8 -#define COL32_A_SHIFT 0 -void ETerminalDisplay::Draw( Vector2f pos ) { - m_drawing = true; - - if ( mClock.getElapsedTime().asSeconds() > 0.7 ) { - mMode ^= MODE_BLINK; - mClock.restart(); - } +void ETerminalDisplay::draw( Vector2f pos ) { + mDrawing = true; auto fontSize = (Float)mFont->getFontHeight( mFontSize ); auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false ).advance; - auto width = m_columns * spaceCharAdvanceX; - auto height = m_rows * fontSize; + auto width = mColumns * spaceCharAdvanceX; + auto height = mRows * fontSize; if ( width < mSize.getWidth() ) { pos.x = std::floor( pos.x + ( ( mSize.getWidth() - width ) / 2.0f ) ); @@ -570,57 +577,32 @@ void ETerminalDisplay::Draw( Vector2f pos ) { float x = 0.0f; float y = std::floor( pos.y ); const float line_height = fontSize; - auto defaultFg = GetCol( mEmulator->GetDefaultForeground(), m_colors ); - auto defaultBg = GetCol( mEmulator->GetDefaultBackground(), m_colors ); + auto defaultFg = termColor( mEmulator->getDefaultForeground(), mColors ); + auto defaultBg = termColor( mEmulator->getDefaultBackground(), mColors ); Primitives p; p.setForceDraw( false ); p.setColor( defaultBg ); p.drawRectangle( Rectf( mPosition.asFloat(), mSize.asFloat() ) ); - for ( int j = 0; j < m_rows; j++ ) { + for ( int j = 0; j < mRows; j++ ) { x = std::floor( pos.x ); if ( pos.y + line_height * j > mSize.getWidth() ) break; - for ( int i = 0; i < m_columns; i++ ) { - auto& glyph = m_buffer[j * m_columns + i]; - auto fg = GetCol( glyph.fg, m_colors ); - auto bg = GetCol( glyph.bg, m_colors ); + for ( int i = 0; i < mColumns; i++ ) { + auto& glyph = mBuffer[j * mColumns + i]; + auto fg = termColor( glyph.fg, mColors ); + auto bg = termColor( glyph.bg, mColors ); if ( IS_SET( MODE_REVERSE ) ) { - if ( fg == defaultFg ) { - fg = defaultBg; - } else { - Uint32 red = ( fg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( fg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( fg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( fg.getValue() >> COL32_A_SHIFT ) & 0xFF; - fg = Color( ( ~red ) & 0xFF, ( ~green ) & 0xFF, ( ~blue ) & 0xFF, alpha ); - } - - if ( bg == defaultBg ) { - bg = defaultFg; - } else { - Uint32 red = ( bg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( bg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( bg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( bg.getValue() >> COL32_A_SHIFT ) & 0xFF; - bg = Color( ( ~red ) & 0xFF, ( ~green ) & 0xFF, ( ~blue ) & 0xFF, alpha ); - } + fg = fg == defaultFg ? defaultBg : fg.invert(); + bg = bg == defaultBg ? defaultFg : bg.invert(); } - if ( ( glyph.mode & ATTR_BOLD_FAINT ) == ATTR_FAINT ) { - Uint32 red = ( fg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( fg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( fg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( fg.getValue() >> COL32_A_SHIFT ) & 0xFF; - red /= 2; - green /= 2; - blue /= 2; - fg = Color( red, green, blue, alpha ); - } + if ( ( glyph.mode & ATTR_BOLD_FAINT ) == ATTR_FAINT ) + fg = fg.div( 2 ); if ( glyph.mode & ATTR_REVERSE ) bg = fg; @@ -644,53 +626,28 @@ void ETerminalDisplay::Draw( Vector2f pos ) { y = std::floor( pos.y ); - for ( int j = 0; j < m_rows; j++ ) { + for ( int j = 0; j < mRows; j++ ) { x = std::floor( pos.x ); if ( pos.y + line_height * j > mSize.getWidth() ) break; - for ( int i = 0; i < m_columns; i++ ) { - auto& glyph = m_buffer[j * m_columns + i]; - auto fg = GetCol( glyph.fg, m_colors ); - auto bg = GetCol( glyph.bg, m_colors ); + for ( int i = 0; i < mColumns; i++ ) { + auto& glyph = mBuffer[j * mColumns + i]; + auto fg = termColor( glyph.fg, mColors ); + auto bg = termColor( glyph.bg, mColors ); Color temp{ Color::Transparent }; if ( ( glyph.mode & ATTR_BOLD_FAINT ) == ATTR_BOLD && BETWEEN( glyph.fg, 0, 7 ) ) - fg = GetCol( glyph.fg + 8, m_colors ); + fg = termColor( glyph.fg + 8, mColors ); if ( IS_SET( MODE_REVERSE ) ) { - if ( fg == defaultFg ) { - fg = defaultBg; - } else { - Uint32 red = ( fg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( fg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( fg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( fg.getValue() >> COL32_A_SHIFT ) & 0xFF; - fg = Color( ( ~red ) & 0xFF, ( ~green ) & 0xFF, ( ~blue ) & 0xFF, alpha ); - } - - if ( bg == defaultBg ) { - bg = defaultFg; - } else { - Uint32 red = ( bg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( bg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( bg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( bg.getValue() >> COL32_A_SHIFT ) & 0xFF; - bg = Color( ( ~red ) & 0xFF, ( ~green ) & 0xFF, ( ~blue ) & 0xFF, alpha ); - } + fg = fg == defaultFg ? defaultBg : fg.invert(); + bg = bg == defaultBg ? defaultFg : bg.invert(); } - if ( ( glyph.mode & ATTR_BOLD_FAINT ) == ATTR_FAINT ) { - Uint32 red = ( fg.getValue() >> COL32_R_SHIFT ) & 0xFF; - Uint32 green = ( fg.getValue() >> COL32_G_SHIFT ) & 0xFF; - Uint32 blue = ( fg.getValue() >> COL32_B_SHIFT ) & 0xFF; - Uint32 alpha = ( fg.getValue() >> COL32_A_SHIFT ) & 0xFF; - red /= 2; - green /= 2; - blue /= 2; - fg = Color( red, green, blue, alpha ); - } + if ( ( glyph.mode & ATTR_BOLD_FAINT ) == ATTR_FAINT ) + fg = fg.div( 2 ); if ( glyph.mode & ATTR_REVERSE ) { temp = fg; @@ -698,7 +655,7 @@ void ETerminalDisplay::Draw( Vector2f pos ) { bg = temp; } - if ( glyph.mode & ATTR_BLINK && mMode & MODE_BLINK ) + if ( glyph.mode & ATTR_BLINK && ( mMode & MODE_BLINK ) ) fg = bg; if ( glyph.mode & ATTR_INVISIBLE ) @@ -716,7 +673,7 @@ void ETerminalDisplay::Draw( Vector2f pos ) { gd->setDrawMode( GlyphDrawable::DrawMode::Text ); gd->draw( { x, y } ); - if ( glyph.mode & ATTR_BOXDRAW && m_useBoxDrawing ) { + if ( glyph.mode & ATTR_BOXDRAW && mUseBoxDrawing ) { // auto bd = TerminalEmulator::boxdrawindex( &glyph ); // drawbox( x, y, advanceX, line_height, fg, bg, bd, vtx_write ); } @@ -757,16 +714,16 @@ void ETerminalDisplay::Draw( Vector2f pos ) { if ( !IS_SET( MODE_HIDE ) ) { Color drawcol; if ( IS_SET( MODE_REVERSE ) ) { - if ( mEmulator->IsSelected( m_cursor.x, m_cursor.y ) ) { - drawcol = GetCol( mEmulator->GetDefaultCursorColor(), m_colors ); + if ( mEmulator->isSelected( mCursor.x, mCursor.y ) ) { + drawcol = termColor( mEmulator->getDefaultCursorColor(), mColors ); } else { - drawcol = GetCol( mEmulator->GetDefaultReverseCursorColor(), m_colors ); + drawcol = termColor( mEmulator->getDefaultReverseCursorColor(), mColors ); } } else { - drawcol = GetCol( mEmulator->IsSelected( m_cursor.x, m_cursor.y ) - ? mEmulator->GetDefaultReverseCursorColor() - : mEmulator->GetDefaultCursorColor(), - m_colors ); + drawcol = termColor( mEmulator->isSelected( mCursor.x, mCursor.y ) + ? mEmulator->getDefaultReverseCursorColor() + : mEmulator->getDefaultCursorColor(), + mColors ); } Vector2f a{}, b{}, c{}, d{}; @@ -778,40 +735,53 @@ void ETerminalDisplay::Draw( Vector2f pos ) { /* draw the new one */ if ( IS_SET( MODE_FOCUSED ) ) { switch ( mCursorMode ) { - case 7: /* st extension */ - m_cursorg.u = 0x2603; /* snowman (U+2603) */ - /* FALLTHROUGH */ - case 0: /* Blinking Block */ - case 1: /* Blinking Block (Default) */ - case 2: /* Steady Block */ - // TODO: Implement cursor glyph rendering - // xdrawglyph(g, cx, cy); - // break; - case 3: /* Blinking Underline */ - case cursor_mode::MAX_CURSOR: + case 7: /* st extension */ + mCursorGlyph.u = 0x2603; /* snowman (U+2603) */ + /* FALLTHROUGH */ + case 0: /* Blinking Block */ + case 1: { /* Blinking Block (Default) */ + if ( !( mMode & MODE_BLINK ) ) + break; + } + case 2: { /* Steady Block */ + auto* gd = mFont->getGlyphDrawable( mCursorGlyph.u, mFontSize ); + gd->setColor( termColor( mCursorGlyph.fg, mColors ) ); + gd->setDrawMode( GlyphDrawable::DrawMode::Text ); + gd->draw( { pos.x + borderpx + mCursor.x * spaceCharAdvanceX, + pos.y + borderpx + mCursor.y * line_height } ); + break; + } + case 3: { /* Blinking Underline */ + if ( !( mMode & MODE_BLINK ) ) + break; + } case 4: /* Steady Underline */ p.drawRectangle( Rectf( - { pos.x + borderpx + m_cursor.x * spaceCharAdvanceX, - pos.y + borderpx + ( m_cursor.y + 1 ) * line_height - cursorthickness }, + { pos.x + borderpx + mCursor.x * spaceCharAdvanceX, + pos.y + borderpx + ( mCursor.y + 1 ) * line_height - cursorthickness }, { spaceCharAdvanceX, cursorthickness } ) ); break; - case 5: /* Blinking bar */ + case 5: { /* Blinking bar */ + if ( !( mMode & MODE_BLINK ) ) + break; + } case 6: /* Steady bar */ - p.drawRectangle( Rectf( { pos.x + borderpx + m_cursor.x * spaceCharAdvanceX, - pos.y + m_cursor.y * line_height }, + case TerminalCursorMode::MAX_CURSOR: + p.drawRectangle( Rectf( { pos.x + borderpx + mCursor.x * spaceCharAdvanceX, + pos.y + mCursor.y * line_height }, { spaceCharAdvanceX, line_height } ) ); break; } } else { p.setFillMode( PrimitiveFillMode::DRAW_LINE ); - p.drawRectangle( Rectf( { pos.x + borderpx + m_cursor.x * spaceCharAdvanceX, - pos.y + borderpx + m_cursor.y * line_height }, + p.drawRectangle( Rectf( { pos.x + borderpx + mCursor.x * spaceCharAdvanceX, + pos.y + borderpx + mCursor.y * line_height }, { spaceCharAdvanceX, line_height } ) ); } } - m_drawing = false; - m_dirty = false; + mDrawing = false; + mDirty = false; } Vector2i ETerminalDisplay::positionToGrid( const Vector2i& pos ) { @@ -837,24 +807,20 @@ Vector2i ETerminalDisplay::positionToGrid( const Vector2i& pos ) { } void ETerminalDisplay::onSizeChange() { - auto fontSize = (Float)mFont->getFontHeight( mFontSize ); - auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false ).advance; - - auto clipColumns = (int)std::floor( std::max( 1.0f, mSize.getWidth() / spaceCharAdvanceX ) ); - auto clipRows = (int)std::floor( std::max( 1.0f, mSize.getHeight() / fontSize ) ); - - if ( clipColumns != m_terminal->GetNumColumns() || clipRows != m_terminal->GetNumRows() ) { - m_terminal->Resize( clipColumns, clipRows ); + Sizei gridSize( gridSizeFromTermDimensions( mFont, mFontSize, mSize ) ); + if ( gridSize.getWidth() != mTerminal->getNumColumns() || + gridSize.getHeight() != mTerminal->getNumRows() ) { + mTerminal->resize( gridSize.getWidth(), gridSize.getHeight() ); } } void ETerminalDisplay::onTextInput( const Uint32& chr ) { - if ( !m_terminal ) + if ( !mTerminal ) return; String input; input.push_back( chr ); std::string utf8Input( input.toUtf8() ); - m_terminal->Write( utf8Input.c_str(), utf8Input.size() ); + mTerminal->write( utf8Input.c_str(), utf8Input.size() ); } static Uint32 sanitizeMod( const Uint32& mod ) { @@ -889,7 +855,7 @@ void ETerminalDisplay::onKeyDown( const Keycode& keyCode, const Uint32& /*chr*/, } } - m_terminal->Write( &tmp, 1 ); + mTerminal->write( &tmp, 1 ); return; } } @@ -899,7 +865,7 @@ void ETerminalDisplay::onKeyDown( const Keycode& keyCode, const Uint32& /*chr*/, for ( auto& k : scIt->second ) { if ( ( k.mask == KEYMOD_CTRL_SHIFT_ALT_META || k.mask == smod ) && ( k.appkey == 0 || k.appkey < 0 ) && ( k.appcursor == 0 || k.appcursor > 0 ) ) { - Action( k.action ); + action( k.action ); return; } } @@ -911,7 +877,7 @@ void ETerminalDisplay::onKeyDown( const Keycode& keyCode, const Uint32& /*chr*/, if ( ( k.mask == KEYMOD_CTRL_SHIFT_ALT_META || k.mask == smod ) && ( k.appkey == 0 || k.appkey < 0 ) && ( k.appcursor == 0 || k.appcursor > 0 ) ) { if ( k.string.size() > 0 ) { - m_terminal->Write( k.string.c_str(), k.string.size() ); + mTerminal->write( k.string.c_str(), k.string.size() ); return; } break; @@ -925,7 +891,7 @@ void ETerminalDisplay::onKeyDown( const Keycode& keyCode, const Uint32& /*chr*/, if ( ( k.mask == KEYMOD_CTRL_SHIFT_ALT_META || k.mask == smod ) && ( k.appkey == 0 || k.appkey < 0 ) && ( k.appcursor == 0 || k.appcursor > 0 ) ) { if ( k.string.size() > 0 ) { - m_terminal->Write( k.string.c_str(), k.string.size() ); + mTerminal->write( k.string.c_str(), k.string.size() ); return; } break; @@ -938,8 +904,11 @@ Float ETerminalDisplay::getFontSize() const { return mFontSize; } -void ETerminalDisplay::setFontSize( Float FontSize ) { - mFontSize = FontSize; +void ETerminalDisplay::setFontSize( const Float& fontSize ) { + if ( mFontSize != fontSize ) { + mFontSize = fontSize; + onSizeChange(); + } } const Vector2f& ETerminalDisplay::getPosition() const { @@ -948,6 +917,7 @@ const Vector2f& ETerminalDisplay::getPosition() const { void ETerminalDisplay::setPosition( const Vector2f& position ) { mPosition = position; + invalidate(); } const Sizef& ETerminalDisplay::getSize() const { @@ -962,5 +932,22 @@ void ETerminalDisplay::setSize( const Sizef& size ) { } void ETerminalDisplay::invalidate() { - m_dirty = true; + mDirty = true; +} + +void ETerminalDisplay::setFocus( bool focus ) { + if ( focus == mFocus ) + return; + mFocus = focus; + bool modeFocus = mMode & MODE_FOCUSED; + if ( mFocus != modeFocus ) { + if ( mFocus ) { + mMode |= MODE_FOCUSED | MODE_FOCUS; + } else { + mMode ^= MODE_FOCUS | MODE_FOCUSED; + } + } else { + mMode ^= MODE_FOCUS; + } + invalidate(); } diff --git a/src/tools/eterm/eterminaldisplay.hpp b/src/tools/eterm/eterminaldisplay.hpp index cb01f72a9..2f96209c0 100644 --- a/src/tools/eterm/eterminaldisplay.hpp +++ b/src/tools/eterm/eterminaldisplay.hpp @@ -16,12 +16,12 @@ #include #include -using namespace EE::Terminal; using namespace EE; +using namespace EE::Terminal; using namespace EE::Window; using namespace EE::System; -enum class ShortcutAction { PASTE }; +enum class TerminalShortcutAction { PASTE }; enum TerminalOptions { OPTION_NONE = 0, @@ -53,7 +53,7 @@ struct TerminalScancode { struct TerminalShortcut { Keycode keysym; Uint32 mask; - ShortcutAction action; + TerminalShortcutAction action; int appkey; int appcursor; }; @@ -67,7 +67,7 @@ struct TerminalKeyMapEntry { struct TerminalKeyMapShortcut { Uint32 mask; - ShortcutAction action; + TerminalShortcutAction action; int appkey; int appcursor; }; @@ -112,36 +112,36 @@ static const Scancode asciiScancodeTable[] = { class ETerminalDisplay : public TerminalDisplay { public: static std::shared_ptr - Create( EE::Window::Window* window, Font* font, + create( EE::Window::Window* window, Font* font, const Float& fontSize, const Sizef& pixelsSize, std::shared_ptr&& terminalEmulator, TerminalConfig* config = 0 ); static std::shared_ptr - Create( EE::Window::Window* window, Font* font, int columns, int rows, + create( EE::Window::Window* window, Font* font, const Float& fontSize, const Sizef& pixelsSize, const std::string& program, const std::vector& args, const std::string& workingDir, uint32_t options = 0, EE::System::IProcessFactory* processFactory = nullptr ); - virtual void ResetColors(); - virtual int ResetColor( int index, const char* name ); + virtual void resetColors(); + virtual int resetColor( int index, const char* name ); - virtual void SetTitle( const char* title ); - virtual void SetIconTitle( const char* title ); + virtual void setTitle( const char* title ); + virtual void setIconTitle( const char* title ); - virtual void SetClipboard( const char* text ); - virtual const char* GetClipboard() const; + virtual void setClipboard( const char* text ); + virtual const char* getClipboard() const; - virtual bool DrawBegin( int columns, int rows ); - virtual void DrawLine( Line line, int x1, int y, int x2 ); - virtual void DrawCursor( int cx, int cy, TerminalGlyph g, int ox, int oy, TerminalGlyph og ); - virtual void DrawEnd(); + virtual bool drawBegin( int columns, int rows ); + virtual void drawLine( Line line, int x1, int y, int x2 ); + virtual void drawCursor( int cx, int cy, TerminalGlyph g, int ox, int oy, TerminalGlyph og ); + virtual void drawEnd(); - virtual void Update(); + virtual void update(); - void Action( ShortcutAction action ); + void action( TerminalShortcutAction action ); - bool HasTerminated() const; + bool hasTerminated() const; - void Draw( bool hasFocus ); + void draw(); virtual void onMouseMotion( const Vector2i& pos, const Uint32& flags ); @@ -156,7 +156,7 @@ class ETerminalDisplay : public TerminalDisplay { Float getFontSize() const; - void setFontSize( Float FontSize ); + void setFontSize( const Float& FontSize ); const Vector2f& getPosition() const; @@ -166,36 +166,41 @@ class ETerminalDisplay : public TerminalDisplay { void setSize( const Sizef& size ); - bool isDirty() const { return m_dirty; } + bool isDirty() const { return mDirty; } void invalidate(); + bool hasFocus() const { return mFocus; } + + void setFocus( bool focus ); + protected: EE::Window::Window* mWindow; - std::vector m_buffer; - std::vector> m_colors; - std::shared_ptr m_terminal; + std::vector mBuffer; + std::vector> mColors; + std::shared_ptr mTerminal; mutable std::string mClipboard; - Font* mFont; + Font* mFont{ nullptr }; Float mFontSize{ 12 }; Vector2f mPosition; Sizef mSize; - int m_columns{ 0 }; - int m_rows{ 0 }; - std::atomic m_dirty{ true }; - std::atomic m_drawing{ false }; - Vector2i m_cursor; - TerminalGlyph m_cursorg; - bool m_useBoxDrawing; - bool m_useColorEmoji; - bool m_pasteNewlineFix; + int mColumns{ 0 }; + int mRows{ 0 }; + std::atomic mDirty{ true }; + std::atomic mDrawing{ false }; + Vector2i mCursor; + TerminalGlyph mCursorGlyph; + bool mUseBoxDrawing; + bool mUseColorEmoji; + bool mPasteNewlineFix; + bool mFocus{ true }; Clock mClock; - ETerminalDisplay( EE::Window::Window* window, Font* font, int columns, int rows, - TerminalConfig* config ); + ETerminalDisplay( EE::Window::Window* window, Font* font, const Float& fontSize, + const Sizef& pixelsSize, TerminalConfig* config ); - void Draw( Vector2f pos ); + void draw( Vector2f pos ); Vector2i positionToGrid( const Vector2i& pos ); diff --git a/src/tools/eterm/system/autohandle.cpp b/src/tools/eterm/system/autohandle.cpp index d23efedb7..f89706ea1 100644 --- a/src/tools/eterm/system/autohandle.cpp +++ b/src/tools/eterm/system/autohandle.cpp @@ -32,13 +32,13 @@ EE::AutoHandle::AutoHandle( AutoHandle&& other ) : m_hHandle( other.m_hHandle ) other.m_hHandle = invalid_value(); } EE::AutoHandle::~AutoHandle() { - Release(); + release(); } EE::AutoHandle& EE::AutoHandle::operator=( AutoHandle&& other ) { if ( m_hHandle == other.m_hHandle ) return *this; - Release(); + release(); m_hHandle = other.m_hHandle; other.m_hHandle = invalid_value(); return *this; @@ -56,7 +56,7 @@ void EE::AutoHandle::Release() const { #else EE::AutoHandle::AutoHandle( int fd ) : m_hHandle( fd ) {} -void EE::AutoHandle::Release() const { +void EE::AutoHandle::release() const { if ( m_hHandle != -1 ) { close( m_hHandle ); } @@ -67,11 +67,11 @@ EE::AutoHandle::operator bool() const noexcept { return m_hHandle != invalid_value(); } -EE::AutoHandle::type* EE::AutoHandle::Get() { +EE::AutoHandle::type* EE::AutoHandle::get() { return &m_hHandle; } -const EE::AutoHandle::type* EE::AutoHandle::Get() const { +const EE::AutoHandle::type* EE::AutoHandle::get() const { return &m_hHandle; } diff --git a/src/tools/eterm/system/autohandle.hpp b/src/tools/eterm/system/autohandle.hpp index dd353503d..ea8424b8a 100644 --- a/src/tools/eterm/system/autohandle.hpp +++ b/src/tools/eterm/system/autohandle.hpp @@ -36,26 +36,32 @@ class AutoHandle final { using type = int; static constexpr type invalid_value(); #endif - private: - mutable type m_hHandle; - - public: explicit AutoHandle( type handle ); + AutoHandle(); + AutoHandle( AutoHandle&& other ); + ~AutoHandle(); AutoHandle& operator=( AutoHandle&& other ); + AutoHandle( const AutoHandle& ) = delete; + AutoHandle& operator=( const AutoHandle& ) = delete; explicit operator type() const noexcept; + operator bool() const noexcept; - type* Get(); - const type* Get() const; + type* get(); - void Release() const; + const type* get() const; + + void release() const; + + private: + mutable type m_hHandle; }; } // namespace EE diff --git a/src/tools/eterm/system/ipipe.hpp b/src/tools/eterm/system/ipipe.hpp index 861ef96e9..2ecad13c3 100644 --- a/src/tools/eterm/system/ipipe.hpp +++ b/src/tools/eterm/system/ipipe.hpp @@ -40,11 +40,11 @@ class IPipe { virtual ~IPipe() = default; - virtual bool IsTTY() const = 0; + virtual bool isTTY() const = 0; - virtual int Write( const char* s, size_t n ) = 0; + virtual int write( const char* s, size_t n ) = 0; - virtual int Read( char* buf, size_t n, bool block = false ) = 0; + virtual int read( char* buf, size_t n, bool block = false ) = 0; }; }} // namespace EE::System diff --git a/src/tools/eterm/system/iprocess.hpp b/src/tools/eterm/system/iprocess.hpp index 618abbbe5..6cb22b32d 100644 --- a/src/tools/eterm/system/iprocess.hpp +++ b/src/tools/eterm/system/iprocess.hpp @@ -39,15 +39,15 @@ class IProcess { IProcess& operator=( IProcess&& ) = delete; - virtual void CheckExitStatus() = 0; + virtual void checkExitStatus() = 0; - virtual bool HasExited() const = 0; + virtual bool hasExited() const = 0; - virtual int GetExitCode() const = 0; + virtual int getExitCode() const = 0; - virtual void Terminate() = 0; + virtual void terminate() = 0; - virtual void WaitForExit() = 0; + virtual void waitForExit() = 0; }; }} // namespace EE::System diff --git a/src/tools/eterm/system/iprocessfactory.hpp b/src/tools/eterm/system/iprocessfactory.hpp index fdf80f5a6..f3e3ca73d 100644 --- a/src/tools/eterm/system/iprocessfactory.hpp +++ b/src/tools/eterm/system/iprocessfactory.hpp @@ -46,14 +46,14 @@ class IProcessFactory { IProcessFactory& operator=( IProcessFactory&& ) = delete; - virtual std::unique_ptr CreateWithStdioPipe( const std::string& program, + virtual std::unique_ptr createWithStdioPipe( const std::string& program, const std::vector& args, const std::string& workingDirectory, std::unique_ptr& outPipe, bool withStderr = true ) = 0; virtual std::unique_ptr - CreateWithPseudoTerminal( const std::string& program, const std::vector& args, + createWithPseudoTerminal( const std::string& program, const std::vector& args, const std::string& workingDirectory, int numColumns, int numRows, std::unique_ptr& outPseudoTerminal ) = 0; }; diff --git a/src/tools/eterm/system/pipe.cpp b/src/tools/eterm/system/pipe.cpp index a2d526056..081343e19 100644 --- a/src/tools/eterm/system/pipe.cpp +++ b/src/tools/eterm/system/pipe.cpp @@ -8,11 +8,11 @@ using namespace EE::System; Pipe::Pipe( AutoHandle&& readHandle, AutoHandle&& writeHandle ) : m_hInput( std::move( readHandle ) ), m_hOutput( std::move( writeHandle ) ) {} -bool Pipe::IsTTY() const { +bool Pipe::isTTY() const { return false; } -int Pipe::Write( const char* s, size_t n ) { +int Pipe::write( const char* s, size_t n ) { constexpr size_t lim = 256; DWORD c = (DWORD)n; @@ -29,7 +29,7 @@ int Pipe::Write( const char* s, size_t n ) { return (int)c; } -int Pipe::Read( char* buf, size_t n, bool block ) { +int Pipe::read( char* buf, size_t n, bool block ) { DWORD available; DWORD read; diff --git a/src/tools/eterm/system/pipe.hpp b/src/tools/eterm/system/pipe.hpp index 48bc3ccad..9cda17eb9 100644 --- a/src/tools/eterm/system/pipe.hpp +++ b/src/tools/eterm/system/pipe.hpp @@ -30,6 +30,25 @@ namespace EE { namespace System { class Process; class Pipe : public IPipe { + public: + Pipe( Pipe&& ) = delete; + + Pipe( const Pipe& ) = delete; + + Pipe& operator=( Pipe&& ) = delete; + + Pipe& operator=( const Pipe& ) = delete; + + virtual ~Pipe() = default; + + virtual bool isTTY() const override; + + virtual int write( const char* s, size_t n ) override; + + virtual int read( char* buf, size_t n, bool block = false ) override; + + static bool CreatePipePair( std::unique_ptr& outPipeA, std::unique_ptr& outPipeB ); + private: friend class Process; #ifdef _WIN32 @@ -42,24 +61,6 @@ class Pipe : public IPipe { Pipe( AutoHandle&& handle ); #endif - public: - Pipe( Pipe&& ) = delete; - - Pipe( const Pipe& ) = delete; - - Pipe& operator=( Pipe&& ) = delete; - - Pipe& operator=( const Pipe& ) = delete; - - virtual ~Pipe() = default; - - virtual bool IsTTY() const override; - - virtual int Write( const char* s, size_t n ) override; - - virtual int Read( char* buf, size_t n, bool block = false ) override; - - static bool CreatePipePair( std::unique_ptr& outPipeA, std::unique_ptr& outPipeB ); }; }} // namespace EE::System diff --git a/src/tools/eterm/system/process.cpp b/src/tools/eterm/system/process.cpp index f85d1ac24..56f0c3189 100644 --- a/src/tools/eterm/system/process.cpp +++ b/src/tools/eterm/system/process.cpp @@ -51,7 +51,7 @@ Process::~Process() { } } -void Process::CheckExitStatus() { +void Process::checkExitStatus() { if ( m_status == ProcessStatus::EXITED ) { return; } @@ -67,7 +67,7 @@ void Process::CheckExitStatus() { m_exitCode = WEXITSTATUS( status ); } -void Process::Terminate() { +void Process::terminate() { if ( m_status == ProcessStatus::EXITED ) { return; } @@ -78,7 +78,7 @@ void Process::Terminate() { } } -void Process::WaitForExit() { +void Process::waitForExit() { if ( m_status == ProcessStatus::EXITED ) { return; } @@ -92,11 +92,11 @@ void Process::WaitForExit() { m_exitCode = WEXITSTATUS( status ); } -bool Process::HasExited() const { +bool Process::hasExited() const { return m_status == EE::System::ProcessStatus::EXITED; } -int Process::GetExitCode() const { +int Process::getExitCode() const { return m_status == ProcessStatus::EXITED ? m_exitCode : 255; } @@ -136,7 +136,7 @@ static void execshell( const char* cmd, const char* const* args ) { _exit( 1 ); } -std::unique_ptr Process::CreateWithPipe( const std::string& /*program*/, +std::unique_ptr Process::createWithPipe( const std::string& /*program*/, const std::vector& /*args*/, const std::string& /*workingDirectory*/, std::unique_ptr& outPipe, @@ -146,7 +146,7 @@ std::unique_ptr Process::CreateWithPipe( const std::string& /*program*/ } std::unique_ptr -Process::CreateWithPseudoTerminal( const std::string& program, const std::vector& args, +Process::createWithPseudoTerminal( const std::string& program, const std::vector& args, const std::string& /*workingDirectory*/, Terminal::PseudoTerminal& pseudoTerminal ) { int pid = fork(); @@ -183,7 +183,7 @@ Process::CreateWithPseudoTerminal( const std::string& program, const std::vector argsV.push_back( nullptr ); execshell( program.c_str(), argsV.data() ); } else { - pseudoTerminal.m_slave.Release(); + pseudoTerminal.m_slave.release(); return std::unique_ptr( new Process( pid ) ); } return nullptr; @@ -263,7 +263,7 @@ Process::~Process() { } } -void Process::CheckExitStatus() { +void Process::checkExitStatus() { if ( m_status == ProcessStatus::RUNNING ) { DWORD exitCode; if ( GetExitCodeProcess( (HANDLE)m_hProcess, &exitCode ) && exitCode != STILL_ACTIVE ) { @@ -273,15 +273,15 @@ void Process::CheckExitStatus() { } } -bool Process::HasExited() const { +bool Process::hasExited() const { return m_status == ProcessStatus::EXITED; } -int Process::GetExitCode() const { +int Process::getExitCode() const { return m_status == ProcessStatus::EXITED ? m_exitCode : STILL_ACTIVE; } -void Process::Terminate() { +void Process::terminate() { if ( m_status == ProcessStatus::RUNNING ) { TerminateProcess( (HANDLE)m_hProcess, EXIT_FAILURE ); m_exitCode = EXIT_FAILURE; @@ -290,7 +290,7 @@ void Process::Terminate() { } } -void Process::WaitForExit() { +void Process::waitForExit() { CheckExitStatus(); if ( m_status == ProcessStatus::RUNNING ) { @@ -298,7 +298,7 @@ void Process::WaitForExit() { } } -std::unique_ptr Process::CreateWithPipe( const std::string& program, +std::unique_ptr Process::createWithPipe( const std::string& program, const std::vector& args, const std::string& workingDirectory, std::unique_ptr& outPipe, @@ -377,7 +377,7 @@ std::unique_ptr Process::CreateWithPipe( const std::string& program, } std::unique_ptr -Process::CreateWithPseudoTerminal( const std::string& program, const std::vector& args, +Process::createWithPseudoTerminal( const std::string& program, const std::vector& args, const std::string& workingDirectory, Terminal::PseudoTerminal& pseudoTerminal ) { HRESULT hr{ E_UNEXPECTED }; diff --git a/src/tools/eterm/system/process.hpp b/src/tools/eterm/system/process.hpp index bbb33489d..6a9162e3c 100644 --- a/src/tools/eterm/system/process.hpp +++ b/src/tools/eterm/system/process.hpp @@ -39,6 +39,38 @@ namespace EE { namespace System { class Process final : public IProcess { + public: + ~Process(); + + Process( const Process& ) = delete; + + Process( Process&& ) = delete; + + Process& operator=( const Process& ) = delete; + + Process& operator=( Process&& ) = delete; + + virtual void checkExitStatus() override; + + virtual bool hasExited() const override; + + virtual int getExitCode() const override; + + virtual void terminate() override; + + virtual void waitForExit() override; + + static std::unique_ptr createWithPipe( const std::string& program, + const std::vector& args, + const std::string& workingDirectory, + std::unique_ptr& outPipe, + bool withStderr = true ); + + static std::unique_ptr + createWithPseudoTerminal( const std::string& program, const std::vector& args, + const std::string& workingDirectory, + Terminal::PseudoTerminal& pseudoTerminal ); + private: ProcessStatus m_status; bool m_leaveRunning; @@ -53,31 +85,6 @@ class Process final : public IProcess { Process( int pid ); #endif - - public: - ~Process(); - Process( const Process& ) = delete; - Process( Process&& ) = delete; - Process& operator=( const Process& ) = delete; - Process& operator=( Process&& ) = delete; - - virtual void CheckExitStatus() override; - virtual bool HasExited() const override; - virtual int GetExitCode() const override; - - virtual void Terminate() override; - virtual void WaitForExit() override; - - static std::unique_ptr CreateWithPipe( const std::string& program, - const std::vector& args, - const std::string& workingDirectory, - std::unique_ptr& outPipe, - bool withStderr = true ); - - static std::unique_ptr - CreateWithPseudoTerminal( const std::string& program, const std::vector& args, - const std::string& workingDirectory, - Terminal::PseudoTerminal& pseudoTerminal ); }; }} // namespace EE::System diff --git a/src/tools/eterm/system/processfactory.cpp b/src/tools/eterm/system/processfactory.cpp index 9194d9580..058b94cc3 100644 --- a/src/tools/eterm/system/processfactory.cpp +++ b/src/tools/eterm/system/processfactory.cpp @@ -4,27 +4,27 @@ using namespace EE::System; -std::unique_ptr ProcessFactory::CreateWithStdioPipe( const std::string& program, +std::unique_ptr ProcessFactory::createWithStdioPipe( const std::string& program, const std::vector& args, const std::string& workingDirectory, std::unique_ptr& outPipe, bool withStderr ) { - return Process::CreateWithPipe( program, args, workingDirectory, outPipe, withStderr ); + return Process::createWithPipe( program, args, workingDirectory, outPipe, withStderr ); } -std::unique_ptr ProcessFactory::CreateWithPseudoTerminal( +std::unique_ptr ProcessFactory::createWithPseudoTerminal( const std::string& program, const std::vector& args, const std::string& workingDirectory, int numColumns, int numRows, std::unique_ptr& outPseudoTerminal ) { outPseudoTerminal = nullptr; - auto pseudoTerminal = Terminal::PseudoTerminal::Create( numColumns, numRows ); + auto pseudoTerminal = Terminal::PseudoTerminal::create( numColumns, numRows ); if ( !pseudoTerminal ) { fprintf( stderr, "Failed to create pseudo terminal\n" ); return nullptr; } - auto process = System::Process::CreateWithPseudoTerminal( program, args, workingDirectory, + auto process = System::Process::createWithPseudoTerminal( program, args, workingDirectory, *pseudoTerminal ); if ( !process ) { fprintf( stderr, "Failed to spawn process\n" ); diff --git a/src/tools/eterm/system/processfactory.hpp b/src/tools/eterm/system/processfactory.hpp index 05be377dc..80cd2ce98 100644 --- a/src/tools/eterm/system/processfactory.hpp +++ b/src/tools/eterm/system/processfactory.hpp @@ -41,14 +41,14 @@ class ProcessFactory : public IProcessFactory { ProcessFactory& operator=( ProcessFactory&& ) = delete; - virtual std::unique_ptr CreateWithStdioPipe( const std::string& program, + virtual std::unique_ptr createWithStdioPipe( const std::string& program, const std::vector& args, const std::string& workingDirectory, std::unique_ptr& outPipe, bool withStderr = true ) override; virtual std::unique_ptr - CreateWithPseudoTerminal( const std::string& program, const std::vector& args, + createWithPseudoTerminal( const std::string& program, const std::vector& args, const std::string& workingDirectory, int numColumns, int numRows, std::unique_ptr& outPseudoTerminal ) override; }; diff --git a/src/tools/eterm/terminal/ipseudoterminal.hpp b/src/tools/eterm/terminal/ipseudoterminal.hpp index 4d12eb0ac..b4227d8c4 100644 --- a/src/tools/eterm/terminal/ipseudoterminal.hpp +++ b/src/tools/eterm/terminal/ipseudoterminal.hpp @@ -40,11 +40,11 @@ class IPseudoTerminal : public EE::System::IPipe { virtual ~IPseudoTerminal() = default; - virtual int GetNumColumns() const = 0; + virtual int getNumColumns() const = 0; - virtual int GetNumRows() const = 0; + virtual int getNumRows() const = 0; - virtual bool Resize( int columns, int rows ) = 0; + virtual bool resize( int columns, int rows ) = 0; }; }} // namespace EE::Terminal diff --git a/src/tools/eterm/terminal/pseudoterminal.cpp b/src/tools/eterm/terminal/pseudoterminal.cpp index 77ad21774..524f8198d 100644 --- a/src/tools/eterm/terminal/pseudoterminal.cpp +++ b/src/tools/eterm/terminal/pseudoterminal.cpp @@ -47,11 +47,11 @@ PseudoTerminal::PseudoTerminal( int columns, int rows, AutoHandle&& master, Auto m_master( std::move( master ) ), m_slave( std::move( slave ) ) {} -bool PseudoTerminal::IsTTY() const { +bool PseudoTerminal::isTTY() const { return true; } -bool PseudoTerminal::Resize( int columns, int rows ) { +bool PseudoTerminal::resize( int columns, int rows ) { struct winsize w; w.ws_row = rows; @@ -67,18 +67,18 @@ bool PseudoTerminal::Resize( int columns, int rows ) { return true; } -int PseudoTerminal::GetNumColumns() const { +int PseudoTerminal::getNumColumns() const { return m_columns; } -int PseudoTerminal::GetNumRows() const { +int PseudoTerminal::getNumRows() const { return m_rows; } -int PseudoTerminal::Write( const char* s, size_t n ) { +int PseudoTerminal::write( const char* s, size_t n ) { size_t c = n; while ( n > 0 ) { - ssize_t r = write( (int)m_master, s, n ); + ssize_t r = ::write( (int)m_master, s, n ); if ( r < 0 ) { return -1; } @@ -88,7 +88,7 @@ int PseudoTerminal::Write( const char* s, size_t n ) { return c; } -int PseudoTerminal::Read( char* s, size_t n, bool block ) { +int PseudoTerminal::read( char* s, size_t n, bool block ) { struct pollfd pfd; pfd.fd = (int)m_master; pfd.events = POLLIN; @@ -104,11 +104,11 @@ int PseudoTerminal::Read( char* s, size_t n, bool block ) { return -1; } } - ssize_t r = read( (int)m_master, s, n ); + ssize_t r = ::read( (int)m_master, s, n ); return (int)r; } -std::unique_ptr PseudoTerminal::Create( int columns, int rows ) { +std::unique_ptr PseudoTerminal::create( int columns, int rows ) { AutoHandle master; AutoHandle slave; @@ -119,7 +119,7 @@ std::unique_ptr PseudoTerminal::Create( int columns, int rows ) win.ws_col = columns; win.ws_row = rows; - if ( openpty( master.Get(), slave.Get(), nullptr, NULL, &win ) != 0 ) { + if ( openpty( master.get(), slave.get(), nullptr, NULL, &win ) != 0 ) { perror( "PseudoTerminal::Create(openpty)" ); return nullptr; } @@ -151,11 +151,11 @@ PseudoTerminal::PseudoTerminal( int columns, int rows, AutoHandle&& hInput, Auto m_size.y = (SHORT)rows; } -bool PseudoTerminal::IsTTY() const { +bool PseudoTerminal::isTTY() const { return true; } -bool PseudoTerminal::Resize( int columns, int rows ) { +bool PseudoTerminal::resize( int columns, int rows ) { HRESULT hr = ResizePseudoConsole( m_phPC, { (SHORT)columns, (SHORT)rows } ); if ( hr != S_OK ) { PrintErrorResult( hr ); @@ -166,7 +166,7 @@ bool PseudoTerminal::Resize( int columns, int rows ) { return true; } -int PseudoTerminal::Write( const char* s, size_t n ) { +int PseudoTerminal::write( const char* s, size_t n ) { constexpr size_t lim = 256; DWORD c = (DWORD)n; @@ -183,7 +183,7 @@ int PseudoTerminal::Write( const char* s, size_t n ) { return (int)c; } -int PseudoTerminal::Read( char* buf, size_t n, bool block ) { +int PseudoTerminal::read( char* buf, size_t n, bool block ) { DWORD available; DWORD read; @@ -203,15 +203,15 @@ int PseudoTerminal::Read( char* buf, size_t n, bool block ) { return (int)read; } -int PseudoTerminal::GetNumColumns() const { +int PseudoTerminal::getNumColumns() const { return m_size.x; } -int PseudoTerminal::GetNumRows() const { +int PseudoTerminal::getNumRows() const { return m_size.y; } -std::unique_ptr PseudoTerminal::Create( int columns, int rows ) { +std::unique_ptr PseudoTerminal::create( int columns, int rows ) { using Pointer = std::unique_ptr; HRESULT hr{ E_UNEXPECTED }; diff --git a/src/tools/eterm/terminal/pseudoterminal.hpp b/src/tools/eterm/terminal/pseudoterminal.hpp index d0d10319f..da51582f0 100644 --- a/src/tools/eterm/terminal/pseudoterminal.hpp +++ b/src/tools/eterm/terminal/pseudoterminal.hpp @@ -32,8 +32,31 @@ namespace EE { namespace System { class Process; } + namespace Terminal { class PseudoTerminal final : public IPseudoTerminal { + public: + virtual ~PseudoTerminal(); + + PseudoTerminal( PseudoTerminal&& ) = delete; + + PseudoTerminal( const PseudoTerminal& ) = delete; + + PseudoTerminal& operator=( PseudoTerminal&& ) = delete; + + PseudoTerminal& operator=( const PseudoTerminal& ) = delete; + + virtual bool isTTY() const override; + + virtual int getNumColumns() const override; + virtual int getNumRows() const override; + + virtual bool resize( int columns, int rows ) override; + virtual int write( const char* s, size_t n ) override; + virtual int read( char* buf, size_t n, bool block = false ) override; + + static std::unique_ptr create( int columns, int rows ); + private: friend class ::EE::System::Process; #ifdef _WIN32 @@ -55,24 +78,6 @@ class PseudoTerminal final : public IPseudoTerminal { PseudoTerminal( int columns, int rows, AutoHandle&& master, AutoHandle&& slave ); #endif - public: - virtual ~PseudoTerminal(); - - PseudoTerminal( PseudoTerminal&& ) = delete; - PseudoTerminal( const PseudoTerminal& ) = delete; - PseudoTerminal& operator=( PseudoTerminal&& ) = delete; - PseudoTerminal& operator=( const PseudoTerminal& ) = delete; - - virtual bool IsTTY() const override; - - virtual int GetNumColumns() const override; - virtual int GetNumRows() const override; - - virtual bool Resize( int columns, int rows ) override; - virtual int Write( const char* s, size_t n ) override; - virtual int Read( char* buf, size_t n, bool block = false ) override; - - static std::unique_ptr Create( int columns, int rows ); }; } // namespace Terminal } // namespace EE diff --git a/src/tools/eterm/terminal/terminaldisplay.cpp b/src/tools/eterm/terminal/terminaldisplay.cpp index 46170a58d..18cf2a8db 100644 --- a/src/tools/eterm/terminal/terminaldisplay.cpp +++ b/src/tools/eterm/terminal/terminaldisplay.cpp @@ -30,46 +30,46 @@ using namespace EE::Terminal; TerminalDisplay::TerminalDisplay() : mMode( MODE_VISIBLE ), mCursorMode( SteadyBar ), mEmulator( nullptr ) {} -void TerminalDisplay::Attach( TerminalEmulator* terminal ) { +void TerminalDisplay::attach( TerminalEmulator* terminal ) { assert( mEmulator == nullptr ); mEmulator = terminal; } -void TerminalDisplay::Detach( TerminalEmulator* terminal ) { +void TerminalDisplay::detach( TerminalEmulator* terminal ) { assert( mEmulator == terminal ); mEmulator = nullptr; } -void TerminalDisplay::Bell() {} +void TerminalDisplay::bell() {} -void TerminalDisplay::ResetColors() {} +void TerminalDisplay::resetColors() {} -int TerminalDisplay::ResetColor( int /*index*/, const char* /*name*/ ) { +int TerminalDisplay::resetColor( int /*index*/, const char* /*name*/ ) { return 0; } -void TerminalDisplay::SetMode( win_mode mode, int set ) { +void TerminalDisplay::setMode( TerminalWinMode mode, int set ) { int m = mMode; MODBIT( ( (int&)mMode ), set, mode ); if ( ( mMode & MODE_REVERSE ) != ( m & MODE_REVERSE ) && mEmulator ) { - mEmulator->Redraw(); + mEmulator->redraw(); } } -void TerminalDisplay::SetCursorMode( cursor_mode cursor ) { +void TerminalDisplay::setCursorMode( TerminalCursorMode cursor ) { mCursorMode = cursor; } -cursor_mode TerminalDisplay::GetCursorMode() const { +TerminalCursorMode TerminalDisplay::getCursorMode() const { return mCursorMode; } -void TerminalDisplay::SetTitle( const char* ) {} +void TerminalDisplay::setTitle( const char* ) {} -void TerminalDisplay::SetIconTitle( const char* ) {} +void TerminalDisplay::setIconTitle( const char* ) {} -void TerminalDisplay::SetClipboard( const char* ) {} +void TerminalDisplay::setClipboard( const char* ) {} -const char* TerminalDisplay::GetClipboard() const { +const char* TerminalDisplay::getClipboard() const { return ""; } diff --git a/src/tools/eterm/terminal/terminaldisplay.hpp b/src/tools/eterm/terminal/terminaldisplay.hpp index b26ff6d7e..ca31575b9 100644 --- a/src/tools/eterm/terminal/terminaldisplay.hpp +++ b/src/tools/eterm/terminal/terminaldisplay.hpp @@ -26,45 +26,60 @@ namespace EE { namespace Terminal { class TerminalEmulator; -class TerminalDisplay { - protected: - int mMode; - cursor_mode mCursorMode; - TerminalEmulator* mEmulator; +class TerminalDisplay { public: TerminalDisplay(); + virtual ~TerminalDisplay() = default; + TerminalDisplay( const TerminalDisplay& ) = delete; + TerminalDisplay( TerminalDisplay&& ) = delete; + TerminalDisplay& operator=( const TerminalDisplay& ) = delete; + TerminalDisplay& operator=( TerminalDisplay&& ) = delete; - virtual void Attach( TerminalEmulator* terminal ); - virtual void Detach( TerminalEmulator* terminal ); + virtual void attach( TerminalEmulator* terminal ); - virtual void Bell(); + virtual void detach( TerminalEmulator* terminal ); - virtual void ResetColors(); - virtual int ResetColor( int index, const char* name ); + virtual void bell(); - virtual void SetMode( win_mode mode, int set ); - inline bool GetMode( win_mode mode ) const { return mMode & mode; } + virtual void resetColors(); - virtual void SetCursorMode( cursor_mode cursor ); - virtual cursor_mode GetCursorMode() const; + virtual int resetColor( int index, const char* name ); - virtual void SetTitle( const char* title ); - virtual void SetIconTitle( const char* title ); + virtual void setMode( TerminalWinMode mode, int set ); - virtual void SetClipboard( const char* text ); - virtual const char* GetClipboard() const; + inline bool getMode( TerminalWinMode mode ) const { return mMode & mode; } - virtual bool DrawBegin( int columns, int rows ) = 0; - virtual void DrawLine( Line line, int x1, int y, int x2 ) = 0; - virtual void DrawCursor( int cx, int cy, TerminalGlyph g, int ox, int oy, + virtual void setCursorMode( TerminalCursorMode cursor ); + + virtual TerminalCursorMode getCursorMode() const; + + virtual void setTitle( const char* title ); + + virtual void setIconTitle( const char* title ); + + virtual void setClipboard( const char* text ); + + virtual const char* getClipboard() const; + + virtual bool drawBegin( int columns, int rows ) = 0; + + virtual void drawLine( Line line, int x1, int y, int x2 ) = 0; + + virtual void drawCursor( int cx, int cy, TerminalGlyph g, int ox, int oy, TerminalGlyph og ) = 0; - virtual void DrawEnd() = 0; + + virtual void drawEnd() = 0; + + protected: + int mMode; + TerminalCursorMode mCursorMode; + TerminalEmulator* mEmulator; }; }} // namespace EE::Terminal diff --git a/src/tools/eterm/terminal/terminalemulator.cpp b/src/tools/eterm/terminal/terminalemulator.cpp index 8038089cf..6faad9fa8 100644 --- a/src/tools/eterm/terminal/terminalemulator.cpp +++ b/src/tools/eterm/terminal/terminalemulator.cpp @@ -99,7 +99,8 @@ static const unsigned int tabspaces = 4; #define UTF_SIZ 4 /* macros */ -#define IS_SET( flag ) ( ( term.mode & ( flag ) ) != 0 ) + +#define IS_SET( flag ) ( ( mTerm.mode & ( flag ) ) != 0 ) #define ISCONTROLC0( c ) ( BETWEEN( c, 0, 0x1f ) || ( c ) == 0x7f ) #define ISCONTROLC1( c ) ( BETWEEN( c, 0x80, 0x9f ) ) #define ISCONTROL( c ) ( ISCONTROLC0( c ) || ISCONTROLC1( c ) ) @@ -289,104 +290,105 @@ char* base64dec( const char* src ) { } void TerminalEmulator::selinit( void ) { - sel.mode = SEL_IDLE; - sel.snap = 0; - sel.ob.x = -1; + mSel.mode = SEL_IDLE; + mSel.snap = 0; + mSel.ob.x = -1; } int TerminalEmulator::tlinelen( int y ) { - int i = term.col; + int i = mTerm.col; - if ( term.line[y][i - 1].mode & ATTR_WRAP ) + if ( mTerm.line[y][i - 1].mode & ATTR_WRAP ) return i; - while ( i > 0 && term.line[y][i - 1].u == ' ' ) + while ( i > 0 && mTerm.line[y][i - 1].u == ' ' ) --i; return i; } -selection_mode TerminalEmulator::getSelectionMode() const { - return (selection_mode)sel.mode; +TerminalSelectionMode TerminalEmulator::getSelectionMode() const { + return (TerminalSelectionMode)mSel.mode; } void TerminalEmulator::selstart( int col, int row, int snap ) { selclear(); - sel.mode = SEL_EMPTY; - sel.type = SEL_REGULAR; - sel.alt = IS_SET( MODE_ALTSCREEN ); - sel.snap = snap; - sel.oe.x = sel.ob.x = col; - sel.oe.y = sel.ob.y = row; + mSel.mode = SEL_EMPTY; + mSel.type = SEL_REGULAR; + mSel.alt = IS_SET( MODE_ALTSCREEN ); + mSel.snap = snap; + mSel.oe.x = mSel.ob.x = col; + mSel.oe.y = mSel.ob.y = row; selnormalize(); - if ( sel.snap != 0 ) - sel.mode = SEL_READY; - tsetdirt( sel.nb.y, sel.ne.y ); + if ( mSel.snap != 0 ) + mSel.mode = SEL_READY; + tsetdirt( mSel.nb.y, mSel.ne.y ); } void TerminalEmulator::selextend( int col, int row, int type, int done ) { int oldey, oldex, oldsby, oldsey, oldtype; - if ( sel.mode == SEL_IDLE ) + if ( mSel.mode == SEL_IDLE ) return; - if ( done && sel.mode == SEL_EMPTY ) { + if ( done && mSel.mode == SEL_EMPTY ) { selclear(); return; } - oldey = sel.oe.y; - oldex = sel.oe.x; - oldsby = sel.nb.y; - oldsey = sel.ne.y; - oldtype = sel.type; + oldey = mSel.oe.y; + oldex = mSel.oe.x; + oldsby = mSel.nb.y; + oldsey = mSel.ne.y; + oldtype = mSel.type; - sel.oe.x = col; - sel.oe.y = row; + mSel.oe.x = col; + mSel.oe.y = row; selnormalize(); - sel.type = type; + mSel.type = type; - if ( oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY ) - tsetdirt( MIN( sel.nb.y, oldsby ), MAX( sel.ne.y, oldsey ) ); + if ( oldey != mSel.oe.y || oldex != mSel.oe.x || oldtype != mSel.type || + mSel.mode == SEL_EMPTY ) + tsetdirt( MIN( mSel.nb.y, oldsby ), MAX( mSel.ne.y, oldsey ) ); - sel.mode = done ? SEL_IDLE : SEL_READY; + mSel.mode = done ? SEL_IDLE : SEL_READY; } void TerminalEmulator::selnormalize( void ) { int i; - if ( sel.type == SEL_REGULAR && sel.ob.y != sel.oe.y ) { - sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x; - sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x; + if ( mSel.type == SEL_REGULAR && mSel.ob.y != mSel.oe.y ) { + mSel.nb.x = mSel.ob.y < mSel.oe.y ? mSel.ob.x : mSel.oe.x; + mSel.ne.x = mSel.ob.y < mSel.oe.y ? mSel.oe.x : mSel.ob.x; } else { - sel.nb.x = MIN( sel.ob.x, sel.oe.x ); - sel.ne.x = MAX( sel.ob.x, sel.oe.x ); + mSel.nb.x = MIN( mSel.ob.x, mSel.oe.x ); + mSel.ne.x = MAX( mSel.ob.x, mSel.oe.x ); } - sel.nb.y = MIN( sel.ob.y, sel.oe.y ); - sel.ne.y = MAX( sel.ob.y, sel.oe.y ); + mSel.nb.y = MIN( mSel.ob.y, mSel.oe.y ); + mSel.ne.y = MAX( mSel.ob.y, mSel.oe.y ); - selsnap( &sel.nb.x, &sel.nb.y, -1 ); - selsnap( &sel.ne.x, &sel.ne.y, +1 ); + selsnap( &mSel.nb.x, &mSel.nb.y, -1 ); + selsnap( &mSel.ne.x, &mSel.ne.y, +1 ); /* expand selection over line breaks */ - if ( sel.type == SEL_RECTANGULAR ) + if ( mSel.type == SEL_RECTANGULAR ) return; - i = tlinelen( sel.nb.y ); - if ( i < sel.nb.x ) - sel.nb.x = i; - if ( tlinelen( sel.ne.y ) <= sel.ne.x ) - sel.ne.x = term.col - 1; + i = tlinelen( mSel.nb.y ); + if ( i < mSel.nb.x ) + mSel.nb.x = i; + if ( tlinelen( mSel.ne.y ) <= mSel.ne.x ) + mSel.ne.x = mTerm.col - 1; } int TerminalEmulator::selected( int x, int y ) { - if ( sel.mode == SEL_EMPTY || sel.ob.x == -1 || sel.alt != IS_SET( MODE_ALTSCREEN ) ) + if ( mSel.mode == SEL_EMPTY || mSel.ob.x == -1 || mSel.alt != IS_SET( MODE_ALTSCREEN ) ) return 0; - if ( sel.type == SEL_RECTANGULAR ) - return BETWEEN( y, sel.nb.y, sel.ne.y ) && BETWEEN( x, sel.nb.x, sel.ne.x ); + if ( mSel.type == SEL_RECTANGULAR ) + return BETWEEN( y, mSel.nb.y, mSel.ne.y ) && BETWEEN( x, mSel.nb.x, mSel.ne.x ); - return BETWEEN( y, sel.nb.y, sel.ne.y ) && ( y != sel.nb.y || x >= sel.nb.x ) && - ( y != sel.ne.y || x <= sel.ne.x ); + return BETWEEN( y, mSel.nb.y, mSel.ne.y ) && ( y != mSel.nb.y || x >= mSel.nb.x ) && + ( y != mSel.ne.y || x <= mSel.ne.x ); } void TerminalEmulator::selsnap( int* x, int* y, int direction ) { @@ -394,35 +396,35 @@ void TerminalEmulator::selsnap( int* x, int* y, int direction ) { int delim, prevdelim; TerminalGlyph *gp, *prevgp; - switch ( sel.snap ) { + switch ( mSel.snap ) { case SNAP_WORD: /* * Snap around if the word wraps around at the end or * beginning of a line. */ - prevgp = &term.line[*y][*x]; + prevgp = &mTerm.line[*y][*x]; prevdelim = ISDELIM( prevgp->u ); for ( ;; ) { newx = *x + direction; newy = *y; - if ( !BETWEEN( newx, 0, term.col - 1 ) ) { + if ( !BETWEEN( newx, 0, mTerm.col - 1 ) ) { newy += direction; - newx = ( newx + term.col ) % term.col; - if ( !BETWEEN( newy, 0, term.row - 1 ) ) + newx = ( newx + mTerm.col ) % mTerm.col; + if ( !BETWEEN( newy, 0, mTerm.row - 1 ) ) break; if ( direction > 0 ) yt = *y, xt = *x; else yt = newy, xt = newx; - if ( !( term.line[yt][xt].mode & ATTR_WRAP ) ) + if ( !( mTerm.line[yt][xt].mode & ATTR_WRAP ) ) break; } if ( newx >= tlinelen( newy ) ) break; - gp = &term.line[newy][newx]; + gp = &mTerm.line[newy][newx]; delim = ISDELIM( gp->u ); if ( !( gp->mode & ATTR_WDUMMY ) && ( delim != prevdelim || ( delim && gp->u != prevgp->u ) ) ) @@ -440,16 +442,16 @@ void TerminalEmulator::selsnap( int* x, int* y, int direction ) { * has set ATTR_WRAP at its end. Then the whole next or * previous line will be selected. */ - *x = ( direction < 0 ) ? 0 : term.col - 1; + *x = ( direction < 0 ) ? 0 : mTerm.col - 1; if ( direction < 0 ) { for ( ; *y > 0; *y += direction ) { - if ( !( term.line[*y - 1][term.col - 1].mode & ATTR_WRAP ) ) { + if ( !( mTerm.line[*y - 1][mTerm.col - 1].mode & ATTR_WRAP ) ) { break; } } } else if ( direction > 0 ) { - for ( ; *y < term.row - 1; *y += direction ) { - if ( !( term.line[*y][term.col - 1].mode & ATTR_WRAP ) ) { + for ( ; *y < mTerm.row - 1; *y += direction ) { + if ( !( mTerm.line[*y][mTerm.col - 1].mode & ATTR_WRAP ) ) { break; } } @@ -463,27 +465,27 @@ char* TerminalEmulator::getsel( void ) { int y, bufsize, lastx, linelen; TerminalGlyph *gp, *last; - if ( sel.ob.x == -1 ) + if ( mSel.ob.x == -1 ) return NULL; - bufsize = ( term.col + 1 ) * ( sel.ne.y - sel.nb.y + 1 ) * UTF_SIZ; + bufsize = ( mTerm.col + 1 ) * ( mSel.ne.y - mSel.nb.y + 1 ) * UTF_SIZ; ptr = str = (char*)xmalloc( bufsize ); /* append every set & selected glyph to the selection */ - for ( y = sel.nb.y; y <= sel.ne.y; y++ ) { + for ( y = mSel.nb.y; y <= mSel.ne.y; y++ ) { if ( ( linelen = tlinelen( y ) ) == 0 ) { *ptr++ = '\n'; continue; } - if ( sel.type == SEL_RECTANGULAR ) { - gp = &term.line[y][sel.nb.x]; - lastx = sel.ne.x; + if ( mSel.type == SEL_RECTANGULAR ) { + gp = &mTerm.line[y][mSel.nb.x]; + lastx = mSel.ne.x; } else { - gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0]; - lastx = ( sel.ne.y == y ) ? sel.ne.x : term.col - 1; + gp = &mTerm.line[y][mSel.nb.y == y ? mSel.nb.x : 0]; + lastx = ( mSel.ne.y == y ) ? mSel.ne.x : mTerm.col - 1; } - last = &term.line[y][MIN( lastx, linelen - 1 )]; + last = &mTerm.line[y][MIN( lastx, linelen - 1 )]; while ( last >= gp && last->u == ' ' ) --last; @@ -503,8 +505,8 @@ char* TerminalEmulator::getsel( void ) { * st. * FIXME: Fix the computer world. */ - if ( ( y < sel.ne.y || lastx >= linelen ) && - ( !( last->mode & ATTR_WRAP ) || sel.type == SEL_RECTANGULAR ) ) + if ( ( y < mSel.ne.y || lastx >= linelen ) && + ( !( last->mode & ATTR_WRAP ) || mSel.type == SEL_RECTANGULAR ) ) *ptr++ = '\n'; } *ptr = 0; @@ -512,11 +514,11 @@ char* TerminalEmulator::getsel( void ) { } void TerminalEmulator::selclear( void ) { - if ( sel.ob.x == -1 ) + if ( mSel.ob.x == -1 ) return; - sel.mode = SEL_IDLE; - sel.ob.x = -1; - tsetdirt( sel.nb.y, sel.ne.y ); + mSel.mode = SEL_IDLE; + mSel.ob.x = -1; + tsetdirt( mSel.nb.y, mSel.ne.y ); } void TerminalEmulator::_die( const char* errstr, ... ) { @@ -527,15 +529,15 @@ void TerminalEmulator::_die( const char* errstr, ... ) { va_start( ap, errstr ); vsnprintf( buf, 256, errstr, ap ); va_end( ap ); - LogError( buf ); - Terminate(); + logError( buf ); + terminate(); } size_t TerminalEmulator::ttyread( void ) { int ret, written; /* append read bytes to unprocessed bytes */ - ret = m_pty->Read( m_buf + m_buflen, LEN( m_buf ) - m_buflen ); + ret = mPty->read( mBuf + mBuflen, LEN( mBuf ) - mBuflen ); switch ( ret ) { case 0: @@ -544,12 +546,12 @@ size_t TerminalEmulator::ttyread( void ) { _die( "couldn't read from shell: %s\n", strerror( errno ) ); return 0; default: - m_buflen += ret; - written = twrite( m_buf, m_buflen, 0 ); - m_buflen -= written; + mBuflen += ret; + written = twrite( mBuf, mBuflen, 0 ); + mBuflen -= written; /* keep any incomplete UTF-8 byte sequence for the next call */ - if ( m_buflen > 0 ) - memmove( m_buf, m_buf + written, m_buflen ); + if ( mBuflen > 0 ) + memmove( mBuf, mBuf + written, mBuflen ); return ret; } @@ -583,22 +585,22 @@ void TerminalEmulator::ttywrite( const char* s, size_t n, int may_echo ) { } void TerminalEmulator::ttywriteraw( const char* s, size_t n ) { - if ( m_pty->Write( s, n ) < (int)n ) { + if ( mPty->write( s, n ) < (int)n ) { _die( "Failed to write to TTY" ); } } void TerminalEmulator::ttyhangup() { - if ( m_process ) - m_process->Terminate(); + if ( mProcess ) + mProcess->terminate(); } int TerminalEmulator::tattrset( int attr ) { int i, j; - for ( i = 0; i < term.row - 1; i++ ) { - for ( j = 0; j < term.col - 1; j++ ) { - if ( term.line[i][j].mode & attr ) + for ( i = 0; i < mTerm.row - 1; i++ ) { + for ( j = 0; j < mTerm.col - 1; j++ ) { + if ( mTerm.line[i][j].mode & attr ) return 1; } } @@ -609,19 +611,19 @@ int TerminalEmulator::tattrset( int attr ) { void TerminalEmulator::tsetdirt( int top, int bot ) { int i; - LIMIT( top, 0, term.row - 1 ); - LIMIT( bot, 0, term.row - 1 ); + LIMIT( top, 0, mTerm.row - 1 ); + LIMIT( bot, 0, mTerm.row - 1 ); for ( i = top; i <= bot; i++ ) - term.dirty[i] = 1; + mTerm.dirty[i] = 1; } void TerminalEmulator::tsetdirtattr( int attr ) { int i, j; - for ( i = 0; i < term.row - 1; i++ ) { - for ( j = 0; j < term.col - 1; j++ ) { - if ( term.line[i][j].mode & attr ) { + for ( i = 0; i < mTerm.row - 1; i++ ) { + for ( j = 0; j < mTerm.col - 1; j++ ) { + if ( mTerm.line[i][j].mode & attr ) { tsetdirt( i, i ); break; } @@ -630,17 +632,17 @@ void TerminalEmulator::tsetdirtattr( int attr ) { } void TerminalEmulator::tfulldirt( void ) { - tsetdirt( 0, term.row - 1 ); + tsetdirt( 0, mTerm.row - 1 ); } void TerminalEmulator::tcursor( int mode ) { - static TCursor c[2]; + static TerminalCursor c[2]; int alt = IS_SET( MODE_ALTSCREEN ); if ( mode == CURSOR_SAVE ) { - c[alt] = term.c; + c[alt] = mTerm.c; } else if ( mode == CURSOR_LOAD ) { - term.c = c[alt]; + mTerm.c = c[alt]; tmoveto( c[alt].x, c[alt].y ); } } @@ -648,49 +650,49 @@ void TerminalEmulator::tcursor( int mode ) { void TerminalEmulator::treset( void ) { uint i; - term.c = TCursor{}; - term.c.attr = TerminalGlyph{}; - term.c.attr.mode = ATTR_NULL; - term.c.attr.fg = defaultfg; - term.c.attr.bg = defaultbg; - term.c.x = 0; - term.c.y = 0; - term.c.state = CURSOR_DEFAULT; + mTerm.c = TerminalCursor{}; + mTerm.c.attr = TerminalGlyph{}; + mTerm.c.attr.mode = ATTR_NULL; + mTerm.c.attr.fg = mDefaultFg; + mTerm.c.attr.bg = mDefaultBg; + mTerm.c.x = 0; + mTerm.c.y = 0; + mTerm.c.state = CURSOR_DEFAULT; - memset( term.tabs, 0, term.col * sizeof( *term.tabs ) ); - for ( i = tabspaces; i < (uint)term.col; i += tabspaces ) - term.tabs[i] = 1; - term.top = 0; - term.bot = term.row - 1; - term.mode = MODE_WRAP | MODE_UTF8; - memset( term.trantbl, CS_USA, sizeof( term.trantbl ) ); - term.charset = 0; + memset( mTerm.tabs, 0, mTerm.col * sizeof( *mTerm.tabs ) ); + for ( i = tabspaces; i < (uint)mTerm.col; i += tabspaces ) + mTerm.tabs[i] = 1; + mTerm.top = 0; + mTerm.bot = mTerm.row - 1; + mTerm.mode = MODE_WRAP | MODE_UTF8; + memset( mTerm.trantbl, CS_USA, sizeof( mTerm.trantbl ) ); + mTerm.charset = 0; for ( i = 0; i < 2; i++ ) { tmoveto( 0, 0 ); tcursor( CURSOR_SAVE ); - tclearregion( 0, 0, term.col - 1, term.row - 1 ); + tclearregion( 0, 0, mTerm.col - 1, mTerm.row - 1 ); tswapscreen(); } } void TerminalEmulator::tnew( int col, int row ) { - term = Term{}; - term.c = TCursor{}; - term.c.attr = TerminalGlyph{}; - term.c.attr.fg = defaultfg; - term.c.attr.bg = defaultbg; + mTerm = Term{}; + mTerm.c = TerminalCursor{}; + mTerm.c.attr = TerminalGlyph{}; + mTerm.c.attr.fg = mDefaultFg; + mTerm.c.attr.bg = mDefaultBg; tresize( col, row ); treset(); } void TerminalEmulator::tswapscreen( void ) { - Line* tmp = term.line; + Line* tmp = mTerm.line; - term.line = term.alt; - term.alt = tmp; - term.mode ^= MODE_ALTSCREEN; + mTerm.line = mTerm.alt; + mTerm.alt = tmp; + mTerm.mode ^= MODE_ALTSCREEN; tfulldirt(); } @@ -698,15 +700,15 @@ void TerminalEmulator::tscrolldown( int orig, int n ) { int i; Line temp; - LIMIT( n, 0, term.bot - orig + 1 ); + LIMIT( n, 0, mTerm.bot - orig + 1 ); - tsetdirt( orig, term.bot - n ); - tclearregion( 0, term.bot - n + 1, term.col - 1, term.bot ); + tsetdirt( orig, mTerm.bot - n ); + tclearregion( 0, mTerm.bot - n + 1, mTerm.col - 1, mTerm.bot ); - for ( i = term.bot; i >= orig + n; i-- ) { - temp = term.line[i]; - term.line[i] = term.line[i - n]; - term.line[i - n] = temp; + for ( i = mTerm.bot; i >= orig + n; i-- ) { + temp = mTerm.line[i]; + mTerm.line[i] = mTerm.line[i - n]; + mTerm.line[i - n] = temp; } selscroll( orig, n ); @@ -716,31 +718,31 @@ void TerminalEmulator::tscrollup( int orig, int n ) { int i; Line temp; - LIMIT( n, 0, term.bot - orig + 1 ); + LIMIT( n, 0, mTerm.bot - orig + 1 ); - tclearregion( 0, orig, term.col - 1, orig + n - 1 ); - tsetdirt( orig + n, term.bot ); + tclearregion( 0, orig, mTerm.col - 1, orig + n - 1 ); + tsetdirt( orig + n, mTerm.bot ); - for ( i = orig; i <= term.bot - n; i++ ) { - temp = term.line[i]; - term.line[i] = term.line[i + n]; - term.line[i + n] = temp; + for ( i = orig; i <= mTerm.bot - n; i++ ) { + temp = mTerm.line[i]; + mTerm.line[i] = mTerm.line[i + n]; + mTerm.line[i + n] = temp; } selscroll( orig, -n ); } void TerminalEmulator::selscroll( int orig, int n ) { - if ( sel.ob.x == -1 ) + if ( mSel.ob.x == -1 ) return; - if ( BETWEEN( sel.nb.y, orig, term.bot ) != BETWEEN( sel.ne.y, orig, term.bot ) ) { + if ( BETWEEN( mSel.nb.y, orig, mTerm.bot ) != BETWEEN( mSel.ne.y, orig, mTerm.bot ) ) { selclear(); - } else if ( BETWEEN( sel.nb.y, orig, term.bot ) ) { - sel.ob.y += n; - sel.oe.y += n; - if ( sel.ob.y < term.top || sel.ob.y > term.bot || sel.oe.y < term.top || - sel.oe.y > term.bot ) { + } else if ( BETWEEN( mSel.nb.y, orig, mTerm.bot ) ) { + mSel.ob.y += n; + mSel.oe.y += n; + if ( mSel.ob.y < mTerm.top || mSel.ob.y > mTerm.bot || mSel.oe.y < mTerm.top || + mSel.oe.y > mTerm.bot ) { selclear(); } else { selnormalize(); @@ -749,62 +751,62 @@ void TerminalEmulator::selscroll( int orig, int n ) { } void TerminalEmulator::tnewline( int first_col ) { - int y = term.c.y; + int y = mTerm.c.y; - if ( y == term.bot ) { - tscrollup( term.top, 1 ); + if ( y == mTerm.bot ) { + tscrollup( mTerm.top, 1 ); } else { y++; } - tmoveto( first_col ? 0 : term.c.x, y ); + tmoveto( first_col ? 0 : mTerm.c.x, y ); } void TerminalEmulator::csiparse( void ) { - char *p = csiescseq.buf, *np; + char *p = mCsiescseq.buf, *np; long int v; - csiescseq.narg = 0; + mCsiescseq.narg = 0; if ( *p == '?' ) { - csiescseq.priv = 1; + mCsiescseq.priv = 1; p++; } - csiescseq.buf[csiescseq.len] = '\0'; - while ( p < csiescseq.buf + csiescseq.len ) { + mCsiescseq.buf[mCsiescseq.len] = '\0'; + while ( p < mCsiescseq.buf + mCsiescseq.len ) { np = NULL; v = strtol( p, &np, 10 ); if ( np == p ) v = 0; if ( v == LONG_MAX || v == LONG_MIN ) v = -1; - csiescseq.arg[csiescseq.narg++] = v; + mCsiescseq.arg[mCsiescseq.narg++] = v; p = np; - if ( *p != ';' || csiescseq.narg == ESC_ARG_SIZ ) + if ( *p != ';' || mCsiescseq.narg == ESC_ARG_SIZ ) break; p++; } - csiescseq.mode[0] = *p++; - csiescseq.mode[1] = ( p < csiescseq.buf + csiescseq.len ) ? *p : '\0'; + mCsiescseq.mode[0] = *p++; + mCsiescseq.mode[1] = ( p < mCsiescseq.buf + mCsiescseq.len ) ? *p : '\0'; } /* for absolute user moves, when decom is set */ void TerminalEmulator::tmoveato( int x, int y ) { - tmoveto( x, y + ( ( term.c.state & CURSOR_ORIGIN ) ? term.top : 0 ) ); + tmoveto( x, y + ( ( mTerm.c.state & CURSOR_ORIGIN ) ? mTerm.top : 0 ) ); } void TerminalEmulator::tmoveto( int x, int y ) { int miny, maxy; - if ( term.c.state & CURSOR_ORIGIN ) { - miny = term.top; - maxy = term.bot; + if ( mTerm.c.state & CURSOR_ORIGIN ) { + miny = mTerm.top; + maxy = mTerm.bot; } else { miny = 0; - maxy = term.row - 1; + maxy = mTerm.row - 1; } - term.c.state &= ~CURSOR_WRAPNEXT; - term.c.x = LIMIT( x, 0, term.col - 1 ); - term.c.y = LIMIT( y, miny, maxy ); + mTerm.c.state &= ~CURSOR_WRAPNEXT; + mTerm.c.x = LIMIT( x, 0, mTerm.col - 1 ); + mTerm.c.y = LIMIT( y, miny, maxy ); } void TerminalEmulator::tsetchar( Rune u, TerminalGlyph* attr, int x, int y ) { @@ -823,26 +825,26 @@ void TerminalEmulator::tsetchar( Rune u, TerminalGlyph* attr, int x, int y ) { /* * The table is proudly stolen from rxvt. */ - if ( term.trantbl[term.charset] == CS_GRAPHIC0 && BETWEEN( u, 0x41, 0x7e ) && + if ( mTerm.trantbl[mTerm.charset] == CS_GRAPHIC0 && BETWEEN( u, 0x41, 0x7e ) && vt100_0[u - 0x41] ) utf8decode( vt100_0[u - 0x41], &u, UTF_SIZ ); - if ( term.line[y][x].mode & ATTR_WIDE ) { - if ( x + 1 < term.col ) { - term.line[y][x + 1].u = ' '; - term.line[y][x + 1].mode &= ~ATTR_WDUMMY; + if ( mTerm.line[y][x].mode & ATTR_WIDE ) { + if ( x + 1 < mTerm.col ) { + mTerm.line[y][x + 1].u = ' '; + mTerm.line[y][x + 1].mode &= ~ATTR_WDUMMY; } - } else if ( term.line[y][x].mode & ATTR_WDUMMY ) { - term.line[y][x - 1].u = ' '; - term.line[y][x - 1].mode &= ~ATTR_WIDE; + } else if ( mTerm.line[y][x].mode & ATTR_WDUMMY ) { + mTerm.line[y][x - 1].u = ' '; + mTerm.line[y][x - 1].mode &= ~ATTR_WIDE; } - term.dirty[y] = 1; - term.line[y][x] = *attr; - term.line[y][x].u = u; + mTerm.dirty[y] = 1; + mTerm.line[y][x] = *attr; + mTerm.line[y][x].u = u; if ( isboxdraw( u ) ) - term.line[y][x].mode |= ATTR_BOXDRAW; + mTerm.line[y][x].mode |= ATTR_BOXDRAW; } void TerminalEmulator::tclearregion( int x1, int y1, int x2, int y2 ) { @@ -854,19 +856,19 @@ void TerminalEmulator::tclearregion( int x1, int y1, int x2, int y2 ) { if ( y1 > y2 ) temp = y1, y1 = y2, y2 = temp; - LIMIT( x1, 0, term.col - 1 ); - LIMIT( x2, 0, term.col - 1 ); - LIMIT( y1, 0, term.row - 1 ); - LIMIT( y2, 0, term.row - 1 ); + LIMIT( x1, 0, mTerm.col - 1 ); + LIMIT( x2, 0, mTerm.col - 1 ); + LIMIT( y1, 0, mTerm.row - 1 ); + LIMIT( y2, 0, mTerm.row - 1 ); for ( y = y1; y <= y2; y++ ) { - term.dirty[y] = 1; + mTerm.dirty[y] = 1; for ( x = x1; x <= x2; x++ ) { - gp = &term.line[y][x]; + gp = &mTerm.line[y][x]; if ( selected( x, y ) ) selclear(); - gp->fg = term.c.attr.fg; - gp->bg = term.c.attr.bg; + gp->fg = mTerm.c.attr.fg; + gp->bg = mTerm.c.attr.bg; gp->mode = 0; gp->u = ' '; } @@ -877,40 +879,40 @@ void TerminalEmulator::tdeletechar( int n ) { int dst, src, size; TerminalGlyph* line; - LIMIT( n, 0, term.col - term.c.x ); + LIMIT( n, 0, mTerm.col - mTerm.c.x ); - dst = term.c.x; - src = term.c.x + n; - size = term.col - src; - line = term.line[term.c.y]; + dst = mTerm.c.x; + src = mTerm.c.x + n; + size = mTerm.col - src; + line = mTerm.line[mTerm.c.y]; memmove( &line[dst], &line[src], size * sizeof( TerminalGlyph ) ); - tclearregion( term.col - n, term.c.y, term.col - 1, term.c.y ); + tclearregion( mTerm.col - n, mTerm.c.y, mTerm.col - 1, mTerm.c.y ); } void TerminalEmulator::tinsertblank( int n ) { int dst, src, size; TerminalGlyph* line; - LIMIT( n, 0, term.col - term.c.x ); + LIMIT( n, 0, mTerm.col - mTerm.c.x ); - dst = term.c.x + n; - src = term.c.x; - size = term.col - dst; - line = term.line[term.c.y]; + dst = mTerm.c.x + n; + src = mTerm.c.x; + size = mTerm.col - dst; + line = mTerm.line[mTerm.c.y]; memmove( &line[dst], &line[src], size * sizeof( TerminalGlyph ) ); - tclearregion( src, term.c.y, dst - 1, term.c.y ); + tclearregion( src, mTerm.c.y, dst - 1, mTerm.c.y ); } void TerminalEmulator::tinsertblankline( int n ) { - if ( BETWEEN( term.c.y, term.top, term.bot ) ) - tscrolldown( term.c.y, n ); + if ( BETWEEN( mTerm.c.y, mTerm.top, mTerm.bot ) ) + tscrolldown( mTerm.c.y, n ); } void TerminalEmulator::tdeleteline( int n ) { - if ( BETWEEN( term.c.y, term.top, term.bot ) ) - tscrollup( term.c.y, n ); + if ( BETWEEN( mTerm.c.y, mTerm.top, mTerm.bot ) ) + tscrollup( mTerm.c.y, n ); } int32_t TerminalEmulator::tdefcolor( int* attr, int* npar, int l ) { @@ -962,81 +964,81 @@ void TerminalEmulator::tsetattr( int* attr, int l ) { for ( i = 0; i < l; i++ ) { switch ( attr[i] ) { case 0: - term.c.attr.mode &= ~( ATTR_BOLD | ATTR_FAINT | ATTR_ITALIC | ATTR_UNDERLINE | - ATTR_BLINK | ATTR_REVERSE | ATTR_INVISIBLE | ATTR_STRUCK ); - term.c.attr.fg = defaultfg; - term.c.attr.bg = defaultbg; + mTerm.c.attr.mode &= ~( ATTR_BOLD | ATTR_FAINT | ATTR_ITALIC | ATTR_UNDERLINE | + ATTR_BLINK | ATTR_REVERSE | ATTR_INVISIBLE | ATTR_STRUCK ); + mTerm.c.attr.fg = mDefaultFg; + mTerm.c.attr.bg = mDefaultBg; break; case 1: - term.c.attr.mode |= ATTR_BOLD; + mTerm.c.attr.mode |= ATTR_BOLD; break; case 2: - term.c.attr.mode |= ATTR_FAINT; + mTerm.c.attr.mode |= ATTR_FAINT; break; case 3: - term.c.attr.mode |= ATTR_ITALIC; + mTerm.c.attr.mode |= ATTR_ITALIC; break; case 4: - term.c.attr.mode |= ATTR_UNDERLINE; + mTerm.c.attr.mode |= ATTR_UNDERLINE; break; case 5: /* slow blink */ /* FALLTHROUGH */ case 6: /* rapid blink */ - term.c.attr.mode |= ATTR_BLINK; + mTerm.c.attr.mode |= ATTR_BLINK; break; case 7: - term.c.attr.mode |= ATTR_REVERSE; + mTerm.c.attr.mode |= ATTR_REVERSE; break; case 8: - term.c.attr.mode |= ATTR_INVISIBLE; + mTerm.c.attr.mode |= ATTR_INVISIBLE; break; case 9: - term.c.attr.mode |= ATTR_STRUCK; + mTerm.c.attr.mode |= ATTR_STRUCK; break; case 22: - term.c.attr.mode &= ~( ATTR_BOLD | ATTR_FAINT ); + mTerm.c.attr.mode &= ~( ATTR_BOLD | ATTR_FAINT ); break; case 23: - term.c.attr.mode &= ~ATTR_ITALIC; + mTerm.c.attr.mode &= ~ATTR_ITALIC; break; case 24: - term.c.attr.mode &= ~ATTR_UNDERLINE; + mTerm.c.attr.mode &= ~ATTR_UNDERLINE; break; case 25: - term.c.attr.mode &= ~ATTR_BLINK; + mTerm.c.attr.mode &= ~ATTR_BLINK; break; case 27: - term.c.attr.mode &= ~ATTR_REVERSE; + mTerm.c.attr.mode &= ~ATTR_REVERSE; break; case 28: - term.c.attr.mode &= ~ATTR_INVISIBLE; + mTerm.c.attr.mode &= ~ATTR_INVISIBLE; break; case 29: - term.c.attr.mode &= ~ATTR_STRUCK; + mTerm.c.attr.mode &= ~ATTR_STRUCK; break; case 38: if ( ( idx = tdefcolor( attr, &i, l ) ) >= 0 ) - term.c.attr.fg = idx; + mTerm.c.attr.fg = idx; break; case 39: - term.c.attr.fg = defaultfg; + mTerm.c.attr.fg = mDefaultFg; break; case 48: if ( ( idx = tdefcolor( attr, &i, l ) ) >= 0 ) - term.c.attr.bg = idx; + mTerm.c.attr.bg = idx; break; case 49: - term.c.attr.bg = defaultbg; + mTerm.c.attr.bg = mDefaultBg; break; default: if ( BETWEEN( attr[i], 30, 37 ) ) { - term.c.attr.fg = attr[i] - 30; + mTerm.c.attr.fg = attr[i] - 30; } else if ( BETWEEN( attr[i], 40, 47 ) ) { - term.c.attr.bg = attr[i] - 40; + mTerm.c.attr.bg = attr[i] - 40; } else if ( BETWEEN( attr[i], 90, 97 ) ) { - term.c.attr.fg = attr[i] - 90 + 8; + mTerm.c.attr.fg = attr[i] - 90 + 8; } else if ( BETWEEN( attr[i], 100, 107 ) ) { - term.c.attr.bg = attr[i] - 100 + 8; + mTerm.c.attr.bg = attr[i] - 100 + 8; } else { fprintf( stderr, "erresc(default): gfx attr %d unknown\n", attr[i] ); csidump(); @@ -1049,15 +1051,15 @@ void TerminalEmulator::tsetattr( int* attr, int l ) { void TerminalEmulator::tsetscroll( int t, int b ) { int temp; - LIMIT( t, 0, term.row - 1 ); - LIMIT( b, 0, term.row - 1 ); + LIMIT( t, 0, mTerm.row - 1 ); + LIMIT( b, 0, mTerm.row - 1 ); if ( t > b ) { temp = t; t = b; b = temp; } - term.top = t; - term.bot = b; + mTerm.top = t; + mTerm.bot = b; } void TerminalEmulator::tsetmode( int priv, int set, int* args, int narg ) { @@ -1073,11 +1075,11 @@ void TerminalEmulator::tsetmode( int priv, int set, int* args, int narg ) { xsetmode( set, MODE_REVERSE ); break; case 6: /* DECOM -- Origin */ - MODBIT( term.c.state, set, CURSOR_ORIGIN ); + MODBIT( mTerm.c.state, set, CURSOR_ORIGIN ); tmoveato( 0, 0 ); break; case 7: /* DECAWM -- Auto wrap */ - MODBIT( term.mode, set, MODE_WRAP ); + MODBIT( mTerm.mode, set, MODE_WRAP ); break; case 0: /* Error (IGNORED) */ case 2: /* DECANM -- ANSI/VT52 (IGNORED) */ @@ -1122,17 +1124,17 @@ void TerminalEmulator::tsetmode( int priv, int set, int* args, int narg ) { xsetmode( set, MODE_8BIT ); break; case 1049: /* swap screen & set/restore cursor as xterm */ - if ( !allowaltscreen ) + if ( !mAllowAltScreen ) break; tcursor( ( set ) ? CURSOR_SAVE : CURSOR_LOAD ); /* FALLTHROUGH */ case 47: /* swap screen */ case 1047: - if ( !allowaltscreen ) + if ( !mAllowAltScreen ) break; alt = IS_SET( MODE_ALTSCREEN ); if ( alt ) { - tclearregion( 0, 0, term.col - 1, term.row - 1 ); + tclearregion( 0, 0, mTerm.col - 1, mTerm.row - 1 ); } if ( set ^ alt ) /* set is always 1 or 0 */ tswapscreen(); @@ -1167,13 +1169,13 @@ void TerminalEmulator::tsetmode( int priv, int set, int* args, int narg ) { xsetmode( set, MODE_KBDLOCK ); break; case 4: /* IRM -- Insertion-replacement */ - MODBIT( term.mode, set, MODE_INSERT ); + MODBIT( mTerm.mode, set, MODE_INSERT ); break; case 12: /* SRM -- Send/Receive */ - MODBIT( term.mode, !set, MODE_ECHO ); + MODBIT( mTerm.mode, !set, MODE_ECHO ); break; case 20: /* LNM -- Linefeed/new line */ - MODBIT( term.mode, set, MODE_CRLF ); + MODBIT( mTerm.mode, set, MODE_CRLF ); break; default: fprintf( stderr, "erresc: unknown set/reset mode %d\n", *args ); @@ -1189,7 +1191,7 @@ void TerminalEmulator::csihandle( void ) { std::shared_ptr dpy{}; - switch ( csiescseq.mode[0] ) { + switch ( mCsiescseq.mode[0] ) { default: unknown: fprintf( stderr, "erresc: unknown csi " ); @@ -1197,71 +1199,71 @@ void TerminalEmulator::csihandle( void ) { /* die(""); */ break; case '@': /* ICH -- Insert blank char */ - DEFAULT( csiescseq.arg[0], 1 ); - tinsertblank( csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tinsertblank( mCsiescseq.arg[0] ); break; case 'A': /* CUU -- Cursor Up */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( term.c.x, term.c.y - csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( mTerm.c.x, mTerm.c.y - mCsiescseq.arg[0] ); break; case 'B': /* CUD -- Cursor Down */ case 'e': /* VPR --Cursor Down */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( term.c.x, term.c.y + csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( mTerm.c.x, mTerm.c.y + mCsiescseq.arg[0] ); break; case 'i': /* MC -- Media Copy */ - switch ( csiescseq.arg[0] ) { + switch ( mCsiescseq.arg[0] ) { case 0: tdump(); break; case 1: - tdumpline( term.c.y ); + tdumpline( mTerm.c.y ); break; case 2: tdumpsel(); break; case 4: - term.mode &= ~MODE_PRINT; + mTerm.mode &= ~MODE_PRINT; break; case 5: - term.mode |= MODE_PRINT; + mTerm.mode |= MODE_PRINT; break; } break; case 'c': /* DA -- Device Attributes */ - if ( csiescseq.arg[0] == 0 ) + if ( mCsiescseq.arg[0] == 0 ) ttywrite( vtiden, strlen( vtiden ), 0 ); break; case 'b': /* REP -- if last char is printable print it more times */ - DEFAULT( csiescseq.arg[0], 1 ); - if ( term.lastc ) - while ( csiescseq.arg[0]-- > 0 ) - tputc( term.lastc ); + DEFAULT( mCsiescseq.arg[0], 1 ); + if ( mTerm.lastc ) + while ( mCsiescseq.arg[0]-- > 0 ) + tputc( mTerm.lastc ); break; case 'C': /* CUF -- Cursor Forward */ case 'a': /* HPR -- Cursor Forward */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( term.c.x + csiescseq.arg[0], term.c.y ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( mTerm.c.x + mCsiescseq.arg[0], mTerm.c.y ); break; case 'D': /* CUB -- Cursor Backward */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( term.c.x - csiescseq.arg[0], term.c.y ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( mTerm.c.x - mCsiescseq.arg[0], mTerm.c.y ); break; case 'E': /* CNL -- Cursor Down and first col */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( 0, term.c.y + csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( 0, mTerm.c.y + mCsiescseq.arg[0] ); break; case 'F': /* CPL -- Cursor Up and first col */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( 0, term.c.y - csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( 0, mTerm.c.y - mCsiescseq.arg[0] ); break; case 'g': /* TBC -- Tabulation clear */ - switch ( csiescseq.arg[0] ) { + switch ( mCsiescseq.arg[0] ) { case 0: /* clear current tab stop */ - term.tabs[term.c.x] = 0; + mTerm.tabs[mTerm.c.x] = 0; break; case 3: /* clear all the tabs */ - memset( term.tabs, 0, term.col * sizeof( *term.tabs ) ); + memset( mTerm.tabs, 0, mTerm.col * sizeof( *mTerm.tabs ) ); break; default: goto unknown; @@ -1269,106 +1271,106 @@ void TerminalEmulator::csihandle( void ) { break; case 'G': /* CHA -- Move to */ case '`': /* HPA */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveto( csiescseq.arg[0] - 1, term.c.y ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveto( mCsiescseq.arg[0] - 1, mTerm.c.y ); break; case 'H': /* CUP -- Move to */ case 'f': /* HVP */ - DEFAULT( csiescseq.arg[0], 1 ); - DEFAULT( csiescseq.arg[1], 1 ); - tmoveato( csiescseq.arg[1] - 1, csiescseq.arg[0] - 1 ); + DEFAULT( mCsiescseq.arg[0], 1 ); + DEFAULT( mCsiescseq.arg[1], 1 ); + tmoveato( mCsiescseq.arg[1] - 1, mCsiescseq.arg[0] - 1 ); break; case 'I': /* CHT -- Cursor Forward Tabulation tab stops */ - DEFAULT( csiescseq.arg[0], 1 ); - tputtab( csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tputtab( mCsiescseq.arg[0] ); break; case 'J': /* ED -- Clear screen */ - switch ( csiescseq.arg[0] ) { + switch ( mCsiescseq.arg[0] ) { case 0: /* below */ - tclearregion( term.c.x, term.c.y, term.col - 1, term.c.y ); - if ( term.c.y < term.row - 1 ) { - tclearregion( 0, term.c.y + 1, term.col - 1, term.row - 1 ); + tclearregion( mTerm.c.x, mTerm.c.y, mTerm.col - 1, mTerm.c.y ); + if ( mTerm.c.y < mTerm.row - 1 ) { + tclearregion( 0, mTerm.c.y + 1, mTerm.col - 1, mTerm.row - 1 ); } break; case 1: /* above */ - if ( term.c.y > 1 ) - tclearregion( 0, 0, term.col - 1, term.c.y - 1 ); - tclearregion( 0, term.c.y, term.c.x, term.c.y ); + if ( mTerm.c.y > 1 ) + tclearregion( 0, 0, mTerm.col - 1, mTerm.c.y - 1 ); + tclearregion( 0, mTerm.c.y, mTerm.c.x, mTerm.c.y ); break; case 2: /* all */ - tclearregion( 0, 0, term.col - 1, term.row - 1 ); + tclearregion( 0, 0, mTerm.col - 1, mTerm.row - 1 ); break; default: goto unknown; } break; case 'K': /* EL -- Clear line */ - switch ( csiescseq.arg[0] ) { + switch ( mCsiescseq.arg[0] ) { case 0: /* right */ - tclearregion( term.c.x, term.c.y, term.col - 1, term.c.y ); + tclearregion( mTerm.c.x, mTerm.c.y, mTerm.col - 1, mTerm.c.y ); break; case 1: /* left */ - tclearregion( 0, term.c.y, term.c.x, term.c.y ); + tclearregion( 0, mTerm.c.y, mTerm.c.x, mTerm.c.y ); break; case 2: /* all */ - tclearregion( 0, term.c.y, term.col - 1, term.c.y ); + tclearregion( 0, mTerm.c.y, mTerm.col - 1, mTerm.c.y ); break; } break; case 'S': /* SU -- Scroll line up */ - DEFAULT( csiescseq.arg[0], 1 ); - tscrollup( term.top, csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tscrollup( mTerm.top, mCsiescseq.arg[0] ); break; case 'T': /* SD -- Scroll line down */ - DEFAULT( csiescseq.arg[0], 1 ); - tscrolldown( term.top, csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tscrolldown( mTerm.top, mCsiescseq.arg[0] ); break; case 'L': /* IL -- Insert blank lines */ - DEFAULT( csiescseq.arg[0], 1 ); - tinsertblankline( csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tinsertblankline( mCsiescseq.arg[0] ); break; case 'l': /* RM -- Reset Mode */ - tsetmode( csiescseq.priv, 0, csiescseq.arg, csiescseq.narg ); + tsetmode( mCsiescseq.priv, 0, mCsiescseq.arg, mCsiescseq.narg ); break; case 'M': /* DL -- Delete lines */ - DEFAULT( csiescseq.arg[0], 1 ); - tdeleteline( csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tdeleteline( mCsiescseq.arg[0] ); break; case 'X': /* ECH -- Erase char */ - DEFAULT( csiescseq.arg[0], 1 ); - tclearregion( term.c.x, term.c.y, term.c.x + csiescseq.arg[0] - 1, term.c.y ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tclearregion( mTerm.c.x, mTerm.c.y, mTerm.c.x + mCsiescseq.arg[0] - 1, mTerm.c.y ); break; case 'P': /* DCH -- Delete char */ - DEFAULT( csiescseq.arg[0], 1 ); - tdeletechar( csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tdeletechar( mCsiescseq.arg[0] ); break; case 'Z': /* CBT -- Cursor Backward Tabulation tab stops */ - DEFAULT( csiescseq.arg[0], 1 ); - tputtab( -csiescseq.arg[0] ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tputtab( -mCsiescseq.arg[0] ); break; case 'd': /* VPA -- Move to */ - DEFAULT( csiescseq.arg[0], 1 ); - tmoveato( term.c.x, csiescseq.arg[0] - 1 ); + DEFAULT( mCsiescseq.arg[0], 1 ); + tmoveato( mTerm.c.x, mCsiescseq.arg[0] - 1 ); break; case 'h': /* SM -- Set terminal mode */ - tsetmode( csiescseq.priv, 1, csiescseq.arg, csiescseq.narg ); + tsetmode( mCsiescseq.priv, 1, mCsiescseq.arg, mCsiescseq.narg ); break; case 'm': /* SGR -- Terminal attribute (color) */ - tsetattr( csiescseq.arg, csiescseq.narg ); + tsetattr( mCsiescseq.arg, mCsiescseq.narg ); break; case 'n': /* DSR – Device Status Report (cursor position) */ - if ( csiescseq.arg[0] == 6 ) { - len = snprintf( buf, sizeof( buf ), "\033[%i;%iR", term.c.y + 1, term.c.x + 1 ); + if ( mCsiescseq.arg[0] == 6 ) { + len = snprintf( buf, sizeof( buf ), "\033[%i;%iR", mTerm.c.y + 1, mTerm.c.x + 1 ); ttywrite( buf, len, 0 ); } break; case 'r': /* DECSTBM -- Set Scrolling Region */ - if ( csiescseq.priv ) { + if ( mCsiescseq.priv ) { goto unknown; } else { - DEFAULT( csiescseq.arg[0], 1 ); - DEFAULT( csiescseq.arg[1], term.row ); - tsetscroll( csiescseq.arg[0] - 1, csiescseq.arg[1] - 1 ); + DEFAULT( mCsiescseq.arg[0], 1 ); + DEFAULT( mCsiescseq.arg[1], mTerm.row ); + tsetscroll( mCsiescseq.arg[0] - 1, mCsiescseq.arg[1] - 1 ); tmoveato( 0, 0 ); } break; @@ -1379,12 +1381,13 @@ void TerminalEmulator::csihandle( void ) { tcursor( CURSOR_LOAD ); break; case ' ': - switch ( csiescseq.mode[1] ) { + switch ( mCsiescseq.mode[1] ) { case 'q': /* DECSCUSR -- Set Cursor Style */ - if ( csiescseq.arg[0] < 0 || csiescseq.arg[0] < cursor_mode::MAX_CURSOR ) + if ( mCsiescseq.arg[0] < 0 || + mCsiescseq.arg[0] < TerminalCursorMode::MAX_CURSOR ) goto unknown; - dpy = m_dpy.lock(); - dpy->SetCursorMode( (cursor_mode)csiescseq.arg[0] ); + dpy = mDpy.lock(); + dpy->setCursorMode( (TerminalCursorMode)mCsiescseq.arg[0] ); break; default: goto unknown; @@ -1398,8 +1401,8 @@ void TerminalEmulator::csidump( void ) { uint c; fprintf( stderr, "ESC[" ); - for ( i = 0; i < csiescseq.len; i++ ) { - c = csiescseq.buf[i] & 0xff; + for ( i = 0; i < mCsiescseq.len; i++ ) { + c = mCsiescseq.buf[i] & 0xff; if ( isprint( c ) ) { putc( c, stderr ); } else if ( c == '\n' ) { @@ -1416,42 +1419,42 @@ void TerminalEmulator::csidump( void ) { } void TerminalEmulator::csireset( void ) { - memset( &csiescseq, 0, sizeof( csiescseq ) ); + memset( &mCsiescseq, 0, sizeof( mCsiescseq ) ); } void TerminalEmulator::strhandle( void ) { char *p = NULL, *dec; int j, narg, par; - term.esc &= ~( ESC_STR_END | ESC_STR ); + mTerm.esc &= ~( ESC_STR_END | ESC_STR ); strparse(); - par = ( narg = strescseq.narg ) ? atoi( strescseq.args[0] ) : 0; + par = ( narg = mStrescseq.narg ) ? atoi( mStrescseq.args[0] ) : 0; - std::shared_ptr dpy = m_dpy.lock(); + std::shared_ptr dpy = mDpy.lock(); - switch ( strescseq.type ) { + switch ( mStrescseq.type ) { case ']': /* OSC -- Operating System Command */ switch ( par ) { case 0: if ( narg > 1 ) { - dpy->SetTitle( strescseq.args[1] ); - dpy->SetIconTitle( strescseq.args[1] ); + dpy->setTitle( mStrescseq.args[1] ); + dpy->setIconTitle( mStrescseq.args[1] ); } return; case 1: if ( narg > 1 ) - dpy->SetIconTitle( strescseq.args[1] ); + dpy->setIconTitle( mStrescseq.args[1] ); return; case 2: if ( narg > 1 ) { - dpy->SetTitle( strescseq.args[1] ); + dpy->setTitle( mStrescseq.args[1] ); } return; case 52: - if ( narg > 2 && allowwindowops ) { - dec = base64dec( strescseq.args[2] ); + if ( narg > 2 && mAllowWindowOps ) { + dec = base64dec( mStrescseq.args[2] ); if ( dec ) { - SetClipboard( dec ); + setClipboard( dec ); free( dec ); } else { fprintf( stderr, "erresc: invalid base64\n" ); @@ -1461,11 +1464,11 @@ void TerminalEmulator::strhandle( void ) { case 4: /* color set */ if ( narg < 3 ) break; - p = strescseq.args[2]; + p = mStrescseq.args[2]; /* FALLTHROUGH */ case 104: /* color reset, here p = NULL */ - j = ( narg > 1 ) ? atoi( strescseq.args[1] ) : -1; - if ( ResetColor( j, p ) ) { + j = ( narg > 1 ) ? atoi( mStrescseq.args[1] ) : -1; + if ( resetColor( j, p ) ) { if ( par == 104 && narg <= 1 ) return; /* color reset without parameter */ fprintf( stderr, "erresc: invalid color j=%d, p=%s\n", j, @@ -1475,13 +1478,13 @@ void TerminalEmulator::strhandle( void ) { * TODO if defaultbg color is changed, borders * are dirty */ - Redraw(); + redraw(); } return; } break; case 'k': /* old title set compatibility */ - dpy->SetTitle( strescseq.args[0] ); + dpy->setTitle( mStrescseq.args[0] ); return; case 'P': /* DCS -- Device Control String */ case '_': /* APC -- Application Program Command */ @@ -1489,22 +1492,22 @@ void TerminalEmulator::strhandle( void ) { return; } - LogError( "erresc: unknown str " ); + logError( "erresc: unknown str " ); strdump(); } void TerminalEmulator::strparse( void ) { int c; - char* p = strescseq.buf; + char* p = mStrescseq.buf; - strescseq.narg = 0; - strescseq.buf[strescseq.len] = '\0'; + mStrescseq.narg = 0; + mStrescseq.buf[mStrescseq.len] = '\0'; if ( *p == '\0' ) return; - while ( strescseq.narg < STR_ARG_SIZ ) { - strescseq.args[strescseq.narg++] = p; + while ( mStrescseq.narg < STR_ARG_SIZ ) { + mStrescseq.args[mStrescseq.narg++] = p; while ( ( c = *p ) != ';' && c != '\0' ) ++p; if ( c == '\0' ) @@ -1517,9 +1520,9 @@ void TerminalEmulator::strdump( void ) { size_t i; uint c; - fprintf( stderr, "ESC%c", strescseq.type ); - for ( i = 0; i < strescseq.len; i++ ) { - c = strescseq.buf[i] & 0xff; + fprintf( stderr, "ESC%c", mStrescseq.type ); + for ( i = 0; i < mStrescseq.len; i++ ) { + c = mStrescseq.buf[i] & 0xff; if ( c == '\0' ) { putc( '\n', stderr ); return; @@ -1539,13 +1542,13 @@ void TerminalEmulator::strdump( void ) { } void TerminalEmulator::strreset( void ) { - auto old = strescseq.buf; - strescseq = STREscape{}; - strescseq.buf = (char*)xrealloc( old, STR_BUF_SIZ ); - strescseq.siz = STR_BUF_SIZ; + auto old = mStrescseq.buf; + mStrescseq = STREscape{}; + mStrescseq.buf = (char*)xrealloc( old, STR_BUF_SIZ ); + mStrescseq.siz = STR_BUF_SIZ; } -void TerminalEmulator::sendbreak( const Arg* ) { +void TerminalEmulator::sendbreak( const TerminalArg* ) { // TODO: Do something about this // if (tcsendbreak(cmdfd, 0)) // perror("Error sending break"); @@ -1561,15 +1564,15 @@ void TerminalEmulator::tprinter( const char* /*s*/, size_t /*len*/ ) { // } } -void TerminalEmulator::toggleprinter( const Arg* ) { - term.mode ^= MODE_PRINT; +void TerminalEmulator::toggleprinter( const TerminalArg* ) { + mTerm.mode ^= MODE_PRINT; } -void TerminalEmulator::printscreen( const Arg* ) { +void TerminalEmulator::printscreen( const TerminalArg* ) { tdump(); } -void TerminalEmulator::printsel( const Arg* ) { +void TerminalEmulator::printsel( const TerminalArg* ) { tdumpsel(); } @@ -1586,8 +1589,8 @@ void TerminalEmulator::tdumpline( int n ) { char buf[UTF_SIZ]; TerminalGlyph *bp, *end; - bp = &term.line[n][0]; - end = &bp[MIN( tlinelen( n ), term.col ) - 1]; + bp = &mTerm.line[n][0]; + end = &bp[MIN( tlinelen( n ), mTerm.col ) - 1]; if ( bp != end || bp->u != ' ' ) { for ( ; bp <= end; ++bp ) tprinter( buf, utf8encode( bp->u, buf ) ); @@ -1598,30 +1601,30 @@ void TerminalEmulator::tdumpline( int n ) { void TerminalEmulator::tdump( void ) { int i; - for ( i = 0; i < term.row; ++i ) + for ( i = 0; i < mTerm.row; ++i ) tdumpline( i ); } void TerminalEmulator::tputtab( int n ) { - int x = term.c.x; + int x = mTerm.c.x; if ( n > 0 ) { - while ( x < term.col && n-- ) - for ( ++x; x < term.col && !term.tabs[x]; ++x ) + while ( x < mTerm.col && n-- ) + for ( ++x; x < mTerm.col && !mTerm.tabs[x]; ++x ) /* nothing */; } else if ( n < 0 ) { while ( x > 0 && n++ ) - for ( --x; x > 0 && !term.tabs[x]; --x ) + for ( --x; x > 0 && !mTerm.tabs[x]; --x ) /* nothing */; } - term.c.x = LIMIT( x, 0, term.col - 1 ); + mTerm.c.x = LIMIT( x, 0, mTerm.col - 1 ); } void TerminalEmulator::tdefutf8( char ascii ) { if ( ascii == 'G' ) - term.mode |= MODE_UTF8; + mTerm.mode |= MODE_UTF8; else if ( ascii == '@' ) - term.mode &= ~MODE_UTF8; + mTerm.mode &= ~MODE_UTF8; } void TerminalEmulator::tdeftran( char ascii ) { @@ -1632,7 +1635,7 @@ void TerminalEmulator::tdeftran( char ascii ) { if ( ( p = strchr( cs, ascii ) ) == NULL ) { fprintf( stderr, "esc unhandled charset: ESC ( %c\n", ascii ); } else { - term.trantbl[term.icharset] = vcs[p - cs]; + mTerm.trantbl[mTerm.icharset] = vcs[p - cs]; } } @@ -1640,9 +1643,9 @@ void TerminalEmulator::tdectest( char c ) { int x, y; if ( c == '8' ) { /* DEC screen alignment test. */ - for ( x = 0; x < term.col; ++x ) { - for ( y = 0; y < term.row; ++y ) - tsetchar( 'E', &term.c.attr, x, y ); + for ( x = 0; x < mTerm.col; ++x ) { + for ( y = 0; y < mTerm.row; ++y ) + tsetchar( 'E', &mTerm.c.attr, x, y ); } } } @@ -1663,8 +1666,8 @@ void TerminalEmulator::tstrsequence( uchar c ) { break; } strreset(); - strescseq.type = c; - term.esc |= ESC_STR; + mStrescseq.type = c; + mTerm.esc |= ESC_STR; } void TerminalEmulator::tcontrolcode( uchar ascii ) { @@ -1673,10 +1676,10 @@ void TerminalEmulator::tcontrolcode( uchar ascii ) { tputtab( 1 ); return; case '\b': /* BS */ - tmoveto( term.c.x - 1, term.c.y ); + tmoveto( mTerm.c.x - 1, mTerm.c.y ); return; case '\r': /* CR */ - tmoveto( 0, term.c.y ); + tmoveto( 0, mTerm.c.y ); return; case '\f': /* LF */ case '\v': /* VT */ @@ -1685,25 +1688,25 @@ void TerminalEmulator::tcontrolcode( uchar ascii ) { tnewline( IS_SET( MODE_CRLF ) ); return; case '\a': /* BEL */ - if ( term.esc & ESC_STR_END ) { + if ( mTerm.esc & ESC_STR_END ) { /* backwards compatibility to xterm */ strhandle(); } else { - auto belDpyPtr = m_dpy.lock(); - belDpyPtr->Bell(); + auto belDpyPtr = mDpy.lock(); + belDpyPtr->bell(); } break; case '\033': /* ESC */ csireset(); - term.esc &= ~( ESC_CSI | ESC_ALTCHARSET | ESC_TEST ); - term.esc |= ESC_START; + mTerm.esc &= ~( ESC_CSI | ESC_ALTCHARSET | ESC_TEST ); + mTerm.esc |= ESC_START; return; case '\016': /* SO (LS1 -- Locking shift 1) */ case '\017': /* SI (LS0 -- Locking shift 0) */ - term.charset = 1 - ( ascii - '\016' ); + mTerm.charset = 1 - ( ascii - '\016' ); return; case '\032': /* SUB */ - tsetchar( '?', &term.c.attr, term.c.x, term.c.y ); + tsetchar( '?', &mTerm.c.attr, mTerm.c.x, mTerm.c.y ); /* FALLTHROUGH */ case '\030': /* CAN */ csireset(); @@ -1727,7 +1730,7 @@ void TerminalEmulator::tcontrolcode( uchar ascii ) { case 0x87: /* TODO: ESA */ break; case 0x88: /* HTS -- Horizontal tab stop */ - term.tabs[term.c.x] = 1; + mTerm.tabs[mTerm.c.x] = 1; break; case 0x89: /* TODO: HTJ */ case 0x8a: /* TODO: VTS */ @@ -1760,7 +1763,7 @@ void TerminalEmulator::tcontrolcode( uchar ascii ) { return; } /* only CAN, SUB, \a and C1 chars interrupt a sequence */ - term.esc &= ~( ESC_STR_END | ESC_STR ); + mTerm.esc &= ~( ESC_STR_END | ESC_STR ); } /* @@ -1770,13 +1773,13 @@ void TerminalEmulator::tcontrolcode( uchar ascii ) { int TerminalEmulator::eschandle( uchar ascii ) { switch ( ascii ) { case '[': - term.esc |= ESC_CSI; + mTerm.esc |= ESC_CSI; return 0; case '#': - term.esc |= ESC_TEST; + mTerm.esc |= ESC_TEST; return 0; case '%': - term.esc |= ESC_UTF8; + mTerm.esc |= ESC_UTF8; return 0; case 'P': /* DCS -- Device Control String */ case '_': /* APC -- Application Program Command */ @@ -1787,33 +1790,33 @@ int TerminalEmulator::eschandle( uchar ascii ) { return 0; case 'n': /* LS2 -- Locking shift 2 */ case 'o': /* LS3 -- Locking shift 3 */ - term.charset = 2 + ( ascii - 'n' ); + mTerm.charset = 2 + ( ascii - 'n' ); break; case '(': /* GZD4 -- set primary charset G0 */ case ')': /* G1D4 -- set secondary charset G1 */ case '*': /* G2D4 -- set tertiary charset G2 */ case '+': /* G3D4 -- set quaternary charset G3 */ - term.icharset = ascii - '('; - term.esc |= ESC_ALTCHARSET; + mTerm.icharset = ascii - '('; + mTerm.esc |= ESC_ALTCHARSET; return 0; case 'D': /* IND -- Linefeed */ - if ( term.c.y == term.bot ) { - tscrollup( term.top, 1 ); + if ( mTerm.c.y == mTerm.bot ) { + tscrollup( mTerm.top, 1 ); } else { - tmoveto( term.c.x, term.c.y + 1 ); + tmoveto( mTerm.c.x, mTerm.c.y + 1 ); } break; case 'E': /* NEL -- Next line */ tnewline( 1 ); /* always go to first col */ break; case 'H': /* HTS -- Horizontal tab stop */ - term.tabs[term.c.x] = 1; + mTerm.tabs[mTerm.c.x] = 1; break; case 'M': /* RI -- Reverse index */ - if ( term.c.y == term.top ) { - tscrolldown( term.top, 1 ); + if ( mTerm.c.y == mTerm.top ) { + tscrolldown( mTerm.top, 1 ); } else { - tmoveto( term.c.x, term.c.y - 1 ); + tmoveto( mTerm.c.x, mTerm.c.y - 1 ); } break; case 'Z': /* DECID -- Identify Terminal */ @@ -1822,7 +1825,7 @@ int TerminalEmulator::eschandle( uchar ascii ) { case 'c': /* RIS -- Reset to initial state */ treset(); resettitle(); - LoadColors(); + loadColors(); break; case '=': /* DECPAM -- Application keypad */ xsetmode( 1, MODE_APPKEYPAD ); @@ -1837,7 +1840,7 @@ int TerminalEmulator::eschandle( uchar ascii ) { tcursor( CURSOR_LOAD ); break; case '\\': /* ST -- String Terminator */ - if ( term.esc & ESC_STR_END ) + if ( mTerm.esc & ESC_STR_END ) strhandle(); break; default: @@ -1913,14 +1916,14 @@ void TerminalEmulator::tputc( Rune u ) { * receives a ESC, a SUB, a ST or any other C1 control * character. */ - if ( term.esc & ESC_STR ) { + if ( mTerm.esc & ESC_STR ) { if ( u == '\a' || u == 030 || u == 032 || u == 033 || ISCONTROLC1( u ) ) { - term.esc &= ~( ESC_START | ESC_STR ); - term.esc |= ESC_STR_END; + mTerm.esc &= ~( ESC_START | ESC_STR ); + mTerm.esc |= ESC_STR_END; goto check_control_code; } - if ( strescseq.len + len >= strescseq.siz ) { + if ( mStrescseq.len + len >= mStrescseq.siz ) { /* * Here is a bug in terminals. If the user never sends * some code to stop the str or esc command, then st @@ -1934,14 +1937,14 @@ void TerminalEmulator::tputc( Rune u ) { * term.esc = 0; * strhandle(); */ - if ( strescseq.siz > ( SIZE_MAX - UTF_SIZ ) / 2 ) + if ( mStrescseq.siz > ( SIZE_MAX - UTF_SIZ ) / 2 ) return; - strescseq.siz *= 2; - strescseq.buf = (char*)xrealloc( strescseq.buf, strescseq.siz ); + mStrescseq.siz *= 2; + mStrescseq.buf = (char*)xrealloc( mStrescseq.buf, mStrescseq.siz ); } - memmove( &strescseq.buf[strescseq.len], c, len ); - strescseq.len += len; + memmove( &mStrescseq.buf[mStrescseq.len], c, len ); + mStrescseq.len += len; return; } @@ -1956,60 +1959,60 @@ check_control_code: /* * control codes are not shown ever */ - if ( !term.esc ) - term.lastc = 0; + if ( !mTerm.esc ) + mTerm.lastc = 0; return; - } else if ( term.esc & ESC_START ) { - if ( term.esc & ESC_CSI ) { - csiescseq.buf[csiescseq.len++] = u; - if ( BETWEEN( u, 0x40, 0x7E ) || csiescseq.len >= sizeof( csiescseq.buf ) - 1 ) { - term.esc = 0; + } else if ( mTerm.esc & ESC_START ) { + if ( mTerm.esc & ESC_CSI ) { + mCsiescseq.buf[mCsiescseq.len++] = u; + if ( BETWEEN( u, 0x40, 0x7E ) || mCsiescseq.len >= sizeof( mCsiescseq.buf ) - 1 ) { + mTerm.esc = 0; csiparse(); csihandle(); } return; - } else if ( term.esc & ESC_UTF8 ) { + } else if ( mTerm.esc & ESC_UTF8 ) { tdefutf8( u ); - } else if ( term.esc & ESC_ALTCHARSET ) { + } else if ( mTerm.esc & ESC_ALTCHARSET ) { tdeftran( u ); - } else if ( term.esc & ESC_TEST ) { + } else if ( mTerm.esc & ESC_TEST ) { tdectest( u ); } else { if ( !eschandle( u ) ) return; /* sequence already finished */ } - term.esc = 0; + mTerm.esc = 0; /* * All characters which form part of a sequence are not * printed */ return; } - if ( selected( term.c.x, term.c.y ) ) + if ( selected( mTerm.c.x, mTerm.c.y ) ) selclear(); - gp = &term.line[term.c.y][term.c.x]; - if ( IS_SET( MODE_WRAP ) && ( term.c.state & CURSOR_WRAPNEXT ) ) { + gp = &mTerm.line[mTerm.c.y][mTerm.c.x]; + if ( IS_SET( MODE_WRAP ) && ( mTerm.c.state & CURSOR_WRAPNEXT ) ) { gp->mode |= ATTR_WRAP; tnewline( 1 ); - gp = &term.line[term.c.y][term.c.x]; + gp = &mTerm.line[mTerm.c.y][mTerm.c.x]; } - if ( IS_SET( MODE_INSERT ) && term.c.x + width < term.col ) - memmove( gp + width, gp, ( term.col - term.c.x - width ) * sizeof( TerminalGlyph ) ); + if ( IS_SET( MODE_INSERT ) && mTerm.c.x + width < mTerm.col ) + memmove( gp + width, gp, ( mTerm.col - mTerm.c.x - width ) * sizeof( TerminalGlyph ) ); - if ( term.c.x + width > term.col ) { + if ( mTerm.c.x + width > mTerm.col ) { tnewline( 1 ); - gp = &term.line[term.c.y][term.c.x]; + gp = &mTerm.line[mTerm.c.y][mTerm.c.x]; } - tsetchar( u, &term.c.attr, term.c.x, term.c.y ); - term.lastc = u; + tsetchar( u, &mTerm.c.attr, mTerm.c.x, mTerm.c.y ); + mTerm.lastc = u; if ( width == 2 ) { gp->mode |= ATTR_WIDE; - if ( term.c.x + 1 < term.col ) { + if ( mTerm.c.x + 1 < mTerm.col ) { gp[1].u = '\0'; gp[1].mode = ATTR_WDUMMY; } @@ -2018,10 +2021,10 @@ check_control_code: } } - if ( term.c.x + width < term.col ) { - tmoveto( term.c.x + width, term.c.y ); + if ( mTerm.c.x + width < mTerm.col ) { + tmoveto( mTerm.c.x + width, mTerm.c.y ); } else { - term.c.state |= CURSOR_WRAPNEXT; + mTerm.c.state |= CURSOR_WRAPNEXT; } } @@ -2057,10 +2060,10 @@ int TerminalEmulator::twrite( const char* buf, int buflen, int show_ctrl ) { void TerminalEmulator::tresize( int col, int row ) { int i; - int minrow = MIN( row, term.row ); - int mincol = MIN( col, term.col ); + int minrow = MIN( row, mTerm.row ); + int mincol = MIN( col, mTerm.col ); int* bp; - TCursor c; + TerminalCursor c; if ( col < 1 || row < 1 ) { fprintf( stderr, "tresize: error resizing to %dx%d\n", col, row ); @@ -2072,55 +2075,55 @@ void TerminalEmulator::tresize( int col, int row ) { * tscrollup would work here, but we can optimize to * memmove because we're freeing the earlier lines */ - for ( i = 0; i <= term.c.y - row; i++ ) { - free( term.line[i] ); - free( term.alt[i] ); + for ( i = 0; i <= mTerm.c.y - row; i++ ) { + free( mTerm.line[i] ); + free( mTerm.alt[i] ); } /* ensure that both src and dst are not NULL */ if ( i > 0 ) { - memmove( term.line, term.line + i, row * sizeof( Line ) ); - memmove( term.alt, term.alt + i, row * sizeof( Line ) ); + memmove( mTerm.line, mTerm.line + i, row * sizeof( Line ) ); + memmove( mTerm.alt, mTerm.alt + i, row * sizeof( Line ) ); } - for ( i += row; i < term.row; i++ ) { - free( term.line[i] ); - free( term.alt[i] ); + for ( i += row; i < mTerm.row; i++ ) { + free( mTerm.line[i] ); + free( mTerm.alt[i] ); } /* resize to new height */ - term.line = (Line*)xrealloc( term.line, row * sizeof( Line ) ); - term.alt = (Line*)xrealloc( term.alt, row * sizeof( Line ) ); - term.dirty = (int*)xrealloc( term.dirty, row * sizeof( *term.dirty ) ); - term.tabs = (int*)xrealloc( term.tabs, col * sizeof( *term.tabs ) ); + mTerm.line = (Line*)xrealloc( mTerm.line, row * sizeof( Line ) ); + mTerm.alt = (Line*)xrealloc( mTerm.alt, row * sizeof( Line ) ); + mTerm.dirty = (int*)xrealloc( mTerm.dirty, row * sizeof( *mTerm.dirty ) ); + mTerm.tabs = (int*)xrealloc( mTerm.tabs, col * sizeof( *mTerm.tabs ) ); /* resize each row to new width, zero-pad if needed */ for ( i = 0; i < minrow; i++ ) { - term.line[i] = (Line)xrealloc( term.line[i], col * sizeof( TerminalGlyph ) ); - term.alt[i] = (Line)xrealloc( term.alt[i], col * sizeof( TerminalGlyph ) ); + mTerm.line[i] = (Line)xrealloc( mTerm.line[i], col * sizeof( TerminalGlyph ) ); + mTerm.alt[i] = (Line)xrealloc( mTerm.alt[i], col * sizeof( TerminalGlyph ) ); } /* allocate any new rows */ for ( /* i = minrow */; i < row; i++ ) { - term.line[i] = (Line)xmalloc( col * sizeof( TerminalGlyph ) ); - term.alt[i] = (Line)xmalloc( col * sizeof( TerminalGlyph ) ); + mTerm.line[i] = (Line)xmalloc( col * sizeof( TerminalGlyph ) ); + mTerm.alt[i] = (Line)xmalloc( col * sizeof( TerminalGlyph ) ); } - if ( col > term.col ) { - bp = term.tabs + term.col; + if ( col > mTerm.col ) { + bp = mTerm.tabs + mTerm.col; - memset( bp, 0, sizeof( *term.tabs ) * ( col - term.col ) ); - while ( --bp > term.tabs && !*bp ) + memset( bp, 0, sizeof( *mTerm.tabs ) * ( col - mTerm.col ) ); + while ( --bp > mTerm.tabs && !*bp ) /* nothing */; - for ( bp += tabspaces; bp < term.tabs + col; bp += tabspaces ) + for ( bp += tabspaces; bp < mTerm.tabs + col; bp += tabspaces ) *bp = 1; } /* update terminal size */ - term.col = col; - term.row = row; + mTerm.col = col; + mTerm.row = row; /* reset scrolling region */ tsetscroll( 0, row - 1 ); /* make use of the LIMIT in tmoveto */ - tmoveto( term.c.x, term.c.y ); + tmoveto( mTerm.c.x, mTerm.c.y ); /* Clearing both screens (it makes dirty all lines) */ - c = term.c; + c = mTerm.c; for ( i = 0; i < 2; i++ ) { if ( mincol < col && 0 < minrow ) { tclearregion( mincol, 0, col - 1, minrow - 1 ); @@ -2131,69 +2134,151 @@ void TerminalEmulator::tresize( int col, int row ) { tswapscreen(); tcursor( CURSOR_LOAD ); } - term.c = c; + mTerm.c = c; } void TerminalEmulator::resettitle( void ) { - auto dpy = m_dpy.lock(); + auto dpy = mDpy.lock(); if ( dpy ) - dpy->SetTitle( NULL ); + dpy->setTitle( NULL ); } void TerminalEmulator::drawregion( TerminalDisplay& dpy, int x1, int y1, int x2, int y2 ) { int y; for ( y = y1; y < y2; y++ ) { - if ( !term.dirty[y] ) + if ( !mTerm.dirty[y] ) continue; - term.dirty[y] = 0; + mTerm.dirty[y] = 0; - dpy.DrawLine( term.line[y], x1, y, x2 ); + dpy.drawLine( mTerm.line[y], x1, y, x2 ); } } void TerminalEmulator::draw() { - int cx = term.c.x /*, ocx = term.ocx, ocy = term.ocy*/; + int cx = mTerm.c.x /*, ocx = term.ocx, ocy = term.ocy*/; { - auto dpy = m_dpy.lock(); + auto dpy = mDpy.lock(); if ( !dpy ) return; - dpy->DrawBegin( term.col, term.row ); + dpy->drawBegin( mTerm.col, mTerm.row ); /* adjust cursor position */ - LIMIT( term.ocx, 0, term.col - 1 ); - LIMIT( term.ocy, 0, term.row - 1 ); - if ( term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY ) - term.ocx--; - if ( term.line[term.c.y][cx].mode & ATTR_WDUMMY ) + LIMIT( mTerm.ocx, 0, mTerm.col - 1 ); + LIMIT( mTerm.ocy, 0, mTerm.row - 1 ); + if ( mTerm.line[mTerm.ocy][mTerm.ocx].mode & ATTR_WDUMMY ) + mTerm.ocx--; + if ( mTerm.line[mTerm.c.y][cx].mode & ATTR_WDUMMY ) cx--; - drawregion( *dpy, 0, 0, term.col, term.row ); + drawregion( *dpy, 0, 0, mTerm.col, mTerm.row ); - dpy->DrawCursor( cx, term.c.y, term.line[term.c.y][cx], term.ocx, term.ocy, - term.line[term.ocy][term.ocx] ); + dpy->drawCursor( cx, mTerm.c.y, mTerm.line[mTerm.c.y][cx], mTerm.ocx, mTerm.ocy, + mTerm.line[mTerm.ocy][mTerm.ocx] ); - term.ocx = cx; - term.ocy = term.c.y; + mTerm.ocx = cx; + mTerm.ocy = mTerm.c.y; - dpy->DrawEnd(); + dpy->drawEnd(); } // if (ocx != term.ocx || ocy != term.ocy) // xximspot(term.ocx, term.ocy); } -void TerminalEmulator::Redraw() { +void TerminalEmulator::redraw() { tfulldirt(); draw(); } void TerminalEmulator::xsetmode( int set, unsigned int mode ) { - auto dpy = m_dpy.lock(); - dpy->SetMode( (win_mode)mode, set ); + auto dpy = mDpy.lock(); + dpy->setMode( (TerminalWinMode)mode, set ); +} + +bool TerminalEmulator::xgetmode( const TerminalWinMode& mode ) { + auto dpy = mDpy.lock(); + return dpy->getMode( mode ); +} + +void TerminalEmulator::mousereport( const TerminalMouseEventType& type, const Vector2i& pos, + const Uint32& flags, const Uint32& mod ) { + if ( !xgetmode( MODE_MOUSEBTN ) && ( TerminalMouseEventType::MouseButtonDown == type || + TerminalMouseEventType::MouseButtonRelease == type ) ) + return; + + if ( !xgetmode( MODE_MOUSEMOTION ) && TerminalMouseEventType::MouseMotion == type ) + return; + + int len, btn, code; + char buf[40]; + static int ox, oy; + + for ( btn = 1; btn <= 11 && !( flags & ( 1 << ( btn - 1 ) ) ); btn++ ) + ; + + if ( type == TerminalMouseEventType::MouseMotion ) { + if ( pos.x == ox && pos.y == oy ) + return; + if ( !xgetmode( MODE_MOUSEMOTION ) && !xgetmode( MODE_MOUSEMANY ) ) + return; + /* MODE_MOUSEMOTION: no reporting if no button is pressed */ + if ( xgetmode( MODE_MOUSEMOTION ) && flags == 0 ) + return; + /* Set btn to lowest-numbered pressed button, or 12 if no + * buttons are pressed. */ + + code = 32; + } else { + /* Only buttons 1 through 11 can be encoded */ + if ( btn < 1 || btn > 11 ) + return; + if ( type == TerminalMouseEventType::MouseButtonRelease ) { + /* MODE_MOUSEX10: no button release reporting */ + if ( xgetmode( MODE_MOUSEX10 ) ) + return; + /* Don't send release events for the scroll wheel */ + if ( btn == 4 || btn == 5 ) + return; + } + code = 0; + } + + ox = pos.x; + oy = pos.y; + + /* Encode btn into code. If no button is pressed for a motion event in + * MODE_MOUSEMANY, then encode it as a release. */ + if ( ( !xgetmode( MODE_MOUSESGR ) && type == TerminalMouseEventType::MouseButtonRelease ) || + btn == 12 ) + code += 3; + else if ( btn >= 8 ) + code += 128 + btn - 8; + else if ( btn >= 4 ) + code += 64 + btn - 4; + else + code += btn - 1; + + if ( !xgetmode( MODE_MOUSEX10 ) ) { + code += ( ( mod & KEYMOD_SHIFT ) ? 4 : 0 ) + + ( ( mod & KEYMOD_LALT ) ? 8 : 0 ) /* meta key: alt */ + + ( ( mod & KEYMOD_CTRL ) ? 16 : 0 ); + } + + if ( xgetmode( MODE_MOUSESGR ) ) { + len = snprintf( buf, sizeof( buf ), "\033[<%d;%d;%d%c", code, pos.x + 1, pos.y + 1, + type == TerminalMouseEventType::MouseButtonRelease ? 'm' : 'M' ); + } else if ( pos.x < 223 && pos.y < 223 ) { + len = snprintf( buf, sizeof( buf ), "\033[M%c%c%c", 32 + code, 32 + pos.x + 1, + 32 + pos.y + 1 ); + } else { + return; + } + + ttywrite( buf, len, 0 ); } void TerminalEmulator::xsetpointermotion( int ) { @@ -2201,7 +2286,7 @@ void TerminalEmulator::xsetpointermotion( int ) { } std::unique_ptr -TerminalEmulator::Create( PtyPtr&& pty, ProcPtr&& process, +TerminalEmulator::create( PtyPtr&& pty, ProcPtr&& process, const std::shared_ptr& display ) { if ( !pty || !process ) { fprintf( stderr, "Must provide valid pseudoterminal and process" ); @@ -2214,33 +2299,33 @@ TerminalEmulator::Create( PtyPtr&& pty, ProcPtr&& process, TerminalEmulator::TerminalEmulator( PtyPtr&& pty, ProcPtr&& process, const std::shared_ptr& display ) : - m_dpy( display ), - m_pty( std::move( pty ) ), - m_process( std::move( process ) ), - m_colorsLoaded( false ), - m_exitCode( 1 ), - m_status( STARTING ), - m_buflen( 0 ), - defaultfg( 7 ), - defaultbg( 0 ), - defaultcs( 7 ), - defaultrcs( 0 ), - allowaltscreen( 1 ), - allowwindowops( 1 ) { - memset( m_buf, 0, sizeof( m_buf ) ); - memset( &term, 0, sizeof( term ) ); - memset( &sel, 0, sizeof( sel ) ); - memset( &csiescseq, 0, sizeof( csiescseq ) ); - memset( &strescseq, 0, sizeof( strescseq ) ); + mDpy( display ), + mPty( std::move( pty ) ), + mProcess( std::move( process ) ), + mColorsLoaded( false ), + mExitCode( 1 ), + mStatus( STARTING ), + mBuflen( 0 ), + mDefaultFg( 7 ), + mDefaultBg( 0 ), + mDefaultCs( 7 ), + mDefaultrCs( 0 ), + mAllowAltScreen( 1 ), + mAllowWindowOps( 1 ) { + memset( mBuf, 0, sizeof( mBuf ) ); + memset( &mTerm, 0, sizeof( mTerm ) ); + memset( &mSel, 0, sizeof( mSel ) ); + memset( &mCsiescseq, 0, sizeof( mCsiescseq ) ); + memset( &mStrescseq, 0, sizeof( mStrescseq ) ); - int col = m_pty->GetNumColumns(); - int row = m_pty->GetNumRows(); + int col = mPty->getNumColumns(); + int row = mPty->getNumRows(); tnew( col, row ); if ( display ) { - display->SetCursorMode( SteadyUnderline ); - display->Attach( this ); - LoadColors(); + display->setCursorMode( TerminalCursorMode::SteadyUnderline ); + display->attach( this ); + loadColors(); } selinit(); resettitle(); @@ -2248,71 +2333,71 @@ TerminalEmulator::TerminalEmulator( PtyPtr&& pty, ProcPtr&& process, TerminalEmulator::~TerminalEmulator() { { - auto dpy = m_dpy.lock(); + auto dpy = mDpy.lock(); if ( dpy ) - dpy->Detach( this ); + dpy->detach( this ); } - m_process->Terminate(); + mProcess->terminate(); } -void TerminalEmulator::LogError( const char* msg ) { +void TerminalEmulator::logError( const char* msg ) { fprintf( stderr, "%s\n", msg ); } -void TerminalEmulator::Terminate() { - if ( m_status == STARTING || m_status == RUNNING ) { - m_process->Terminate(); - m_exitCode = 1; - m_status = TERMINATED; +void TerminalEmulator::terminate() { + if ( mStatus == STARTING || mStatus == RUNNING ) { + mProcess->terminate(); + mExitCode = 1; + mStatus = TERMINATED; } } -void TerminalEmulator::OnProcessExit( int /*exitCode*/ ) {} +void TerminalEmulator::onProcessExit( int /*exitCode*/ ) {} -void TerminalEmulator::SetClipboard( const char* str ) { - auto dpy = m_dpy.lock(); +void TerminalEmulator::setClipboard( const char* str ) { + auto dpy = mDpy.lock(); if ( !dpy ) return; - dpy->SetClipboard( str ); + dpy->setClipboard( str ); } -void TerminalEmulator::LoadColors() { - auto dpy = m_dpy.lock(); +void TerminalEmulator::loadColors() { + auto dpy = mDpy.lock(); if ( !dpy ) return; - dpy->ResetColors(); + dpy->resetColors(); } -int TerminalEmulator::ResetColor( int i, const char* name ) { - auto dpy = m_dpy.lock(); +int TerminalEmulator::resetColor( int i, const char* name ) { + auto dpy = mDpy.lock(); if ( !dpy ) return 0; - return dpy->ResetColor( i, name ); + return dpy->resetColor( i, name ); } -bool TerminalEmulator::HasExited() const { - return m_status == TERMINATED; +bool TerminalEmulator::hasExited() const { + return mStatus == TERMINATED; } -int TerminalEmulator::GetExitCode() const { - return m_exitCode; +int TerminalEmulator::getExitCode() const { + return mExitCode; } -void TerminalEmulator::Resize( int columns, int rows ) { - if ( !m_pty->Resize( columns, rows ) ) { +void TerminalEmulator::resize( int columns, int rows ) { + if ( !mPty->resize( columns, rows ) ) { _die( "Failed to resize pty!" ); return; } tresize( columns, rows ); - Redraw(); + redraw(); } -void TerminalEmulator::Update() { - if ( m_status == TerminalEmulator::STARTING ) { - m_status = TerminalEmulator::RUNNING; - } else if ( m_status != TerminalEmulator::RUNNING ) { +void TerminalEmulator::update() { + if ( mStatus == TerminalEmulator::STARTING ) { + mStatus = TerminalEmulator::RUNNING; + } else if ( mStatus != TerminalEmulator::RUNNING ) { return; } @@ -2325,11 +2410,11 @@ void TerminalEmulator::Update() { draw(); - m_process->CheckExitStatus(); + mProcess->checkExitStatus(); - if ( m_process->HasExited() ) { - m_exitCode = m_process->GetExitCode(); - m_status = TERMINATED; - OnProcessExit( m_exitCode ); + if ( mProcess->hasExited() ) { + mExitCode = mProcess->getExitCode(); + mStatus = TERMINATED; + onProcessExit( mExitCode ); } } diff --git a/src/tools/eterm/terminal/terminalemulator.hpp b/src/tools/eterm/terminal/terminalemulator.hpp index 9390992ea..d4d238972 100644 --- a/src/tools/eterm/terminal/terminalemulator.hpp +++ b/src/tools/eterm/terminal/terminalemulator.hpp @@ -39,58 +39,67 @@ #include "ipseudoterminal.hpp" #include "terminaldisplay.hpp" #include "types.hpp" +#include +#include #include #include #include +using namespace EE; +using namespace EE::Math; +using namespace EE::Window; + namespace EE { namespace Terminal { + constexpr int ESC_BUF_SIZ = 512; constexpr int ESC_ARG_SIZ = 16; constexpr int STR_BUF_SIZ = ESC_BUF_SIZ; constexpr int STR_ARG_SIZ = ESC_ARG_SIZ; /* Internal representation of the screen */ -typedef struct { - int row; /* nb row */ - int col; /* nb col */ - Line* line; /* screen */ - Line* alt; /* alternate screen */ - int* dirty; /* dirtyness of lines */ - TCursor c; /* cursor */ - int ocx; /* old cursor col */ - int ocy; /* old cursor row */ - int top; /* top scroll limit */ - int bot; /* bottom scroll limit */ - int mode; /* terminal mode flags */ - int esc; /* escape state flags */ - char trantbl[4]; /* charset table translation */ - int charset; /* current charset */ - int icharset; /* selected charset for sequence */ +struct Term { + int row; /* nb row */ + int col; /* nb col */ + Line* line; /* screen */ + Line* alt; /* alternate screen */ + int* dirty; /* dirtyness of lines */ + TerminalCursor c; /* cursor */ + int ocx; /* old cursor col */ + int ocy; /* old cursor row */ + int top; /* top scroll limit */ + int bot; /* bottom scroll limit */ + int mode; /* terminal mode flags */ + int esc; /* escape state flags */ + char trantbl[4]; /* charset table translation */ + int charset; /* current charset */ + int icharset; /* selected charset for sequence */ int* tabs; Rune lastc; /* last printed char outside of sequence, 0 if control */ -} Term; +}; /* CSI Escape sequence structs */ /* ESC '[' [[ [] [;]] []] */ -typedef struct { +struct CSIEscape { char buf[ESC_BUF_SIZ]; /* raw string */ size_t len; /* raw string length */ char priv; int arg[ESC_ARG_SIZ]; int narg; /* nb of args */ char mode[2]; -} CSIEscape; +}; /* STR Escape sequence structs */ /* ESC type [[ [] [;]] ] ESC '\' */ -typedef struct { +struct STREscape { char type; /* ESC type ... */ char* buf; /* allocated raw string */ size_t siz; /* allocation size */ size_t len; /* raw string length */ char* args[STR_ARG_SIZ]; int narg; /* nb of args */ -} STREscape; +}; + +enum class TerminalMouseEventType { MouseMotion, MouseButtonDown, MouseButtonRelease }; class TerminalEmulator final { public: @@ -100,39 +109,106 @@ class TerminalEmulator final { static ushort boxdrawindex( const TerminalGlyph* g ); - private: - DpyPtr m_dpy; - PtyPtr m_pty; - ProcPtr m_process; + ~TerminalEmulator(); - bool m_colorsLoaded; - int m_exitCode; + TerminalEmulator( const TerminalEmulator& ) = delete; - enum { STARTING = 0, RUNNING, TERMINATED } m_status; + TerminalEmulator( TerminalEmulator&& ) = delete; - char m_buf[8192]; - int m_buflen; + TerminalEmulator& operator=( const TerminalEmulator& ) = delete; + + TerminalEmulator& operator=( TerminalEmulator&& ) = delete; + + static std::unique_ptr + create( PtyPtr&& pty, ProcPtr&& process, const std::shared_ptr& display ); + + void resize( int columns, int rows ); + + void redraw(); + + void logError( const char* err ); + + void update(); + + void terminate(); + + bool hasExited() const; + + int getExitCode() const; + + inline bool isSelected( int column, int row ) { return selected( column, row ); } + + inline uint32_t getDefaultForeground() const { return mDefaultFg; } + + inline uint32_t getDefaultBackground() const { return mDefaultBg; } + + inline uint32_t getDefaultCursorColor() const { return mDefaultCs; } + + inline uint32_t getDefaultReverseCursorColor() const { return mDefaultrCs; } + + inline int getNumColumns() const { return mTerm.col; } + + inline int getNumRows() const { return mTerm.row; } + + inline int write( const char* buf, size_t buflen ) { return mPty->write( buf, (int)buflen ); } + + void printscreen( const TerminalArg* ); + + void printsel( const TerminalArg* ); + + void sendbreak( const TerminalArg* ); + + void toggleprinter( const TerminalArg* ); + + TerminalSelectionMode getSelectionMode() const; + + void selclear(); + + void selinit(); + + void selstart( int, int, int ); + + void selextend( int, int, int, int ); + + int selected( int, int ); + + char* getsel(); + + void mousereport( const TerminalMouseEventType& type, const Vector2i& pos, const Uint32& flags, + const Uint32& mod ); private: - Term term; - Selection sel; - CSIEscape csiescseq; - STREscape strescseq; + DpyPtr mDpy; + PtyPtr mPty; + ProcPtr mProcess; - uint32_t defaultfg; - uint32_t defaultbg; - uint32_t defaultcs; - uint32_t defaultrcs; + bool mColorsLoaded; + int mExitCode; - int allowaltscreen; - int allowwindowops; + enum { STARTING = 0, RUNNING, TERMINATED } mStatus; - void SetClipboard( const char* str ); + char mBuf[8192]; + int mBuflen; - void LoadColors(); - int ResetColor( int x, const char* name ); + Term mTerm; + TerminalSelection mSel; + CSIEscape mCsiescseq; + STREscape mStrescseq; - void OnProcessExit( int exitCode ); + uint32_t mDefaultFg; + uint32_t mDefaultBg; + uint32_t mDefaultCs; + uint32_t mDefaultrCs; + + int mAllowAltScreen; + int mAllowWindowOps; + + void setClipboard( const char* str ); + + void loadColors(); + int resetColor( int x, const char* name ); + + void onProcessExit( int exitCode ); void csidump(); void csihandle(); @@ -200,15 +276,6 @@ class TerminalEmulator final { void resettitle(); - public: - void selclear(); - void selinit(); - void selstart( int, int, int ); - void selextend( int, int, int, int ); - int selected( int, int ); - char* getsel(); - - private: void xbell(); void xclipcopy(); @@ -217,49 +284,14 @@ class TerminalEmulator final { void xsettitle( char* ); int xsetcursor( int ); void xsetmode( int, unsigned int ); + bool xgetmode( const TerminalWinMode& ); + void xsetpointermotion( int ); void xsetsel( char* ); void xximspot( int, int ); - private: TerminalEmulator( PtyPtr&& pty, ProcPtr&& process, const std::shared_ptr& display ); - - public: - ~TerminalEmulator(); - TerminalEmulator( const TerminalEmulator& ) = delete; - TerminalEmulator( TerminalEmulator&& ) = delete; - TerminalEmulator& operator=( const TerminalEmulator& ) = delete; - TerminalEmulator& operator=( TerminalEmulator&& ) = delete; - - public: - static std::unique_ptr - Create( PtyPtr&& pty, ProcPtr&& process, const std::shared_ptr& display ); - - public: - void Resize( int columns, int rows ); - void Redraw(); - void LogError( const char* err ); - void Update(); - void Terminate(); - bool HasExited() const; - int GetExitCode() const; - inline bool IsSelected( int column, int row ) { return selected( column, row ); } - inline uint32_t GetDefaultForeground() const { return defaultfg; } - inline uint32_t GetDefaultBackground() const { return defaultbg; } - inline uint32_t GetDefaultCursorColor() const { return defaultcs; } - inline uint32_t GetDefaultReverseCursorColor() const { return defaultrcs; } - inline int GetNumColumns() const { return term.col; } - inline int GetNumRows() const { return term.row; } - inline int Write( const char* buf, size_t buflen ) { return m_pty->Write( buf, (int)buflen ); } - - public: - void printscreen( const Arg* ); - void printsel( const Arg* ); - void sendbreak( const Arg* ); - void toggleprinter( const Arg* ); - - selection_mode getSelectionMode() const; }; }} // namespace EE::Terminal diff --git a/src/tools/eterm/terminal/types.hpp b/src/tools/eterm/terminal/types.hpp index 4d319876c..b078c4763 100644 --- a/src/tools/eterm/terminal/types.hpp +++ b/src/tools/eterm/terminal/types.hpp @@ -26,7 +26,7 @@ namespace EE { namespace Terminal { -enum cursor_mode { +enum TerminalCursorMode { BlinkingBlock = 0, BlinkingBlockDefault = 1, SteadyBlock = 2, @@ -38,7 +38,7 @@ enum cursor_mode { MAX_CURSOR }; -enum win_mode { +enum TerminalWinMode { MODE_VISIBLE = 1 << 0, MODE_FOCUSED = 1 << 1, MODE_APPKEYPAD = 1 << 2, @@ -60,7 +60,7 @@ enum win_mode { MODE_MOUSE = MODE_MOUSEBTN | MODE_MOUSEMOTION | MODE_MOUSEX10 | MODE_MOUSEMANY, }; -enum glyph_attribute { +enum TerminalGlyphAttribute { ATTR_NULL = 0, ATTR_BOLD = 1 << 0, ATTR_FAINT = 1 << 1, @@ -78,11 +78,11 @@ enum glyph_attribute { ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, }; -enum selection_mode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 }; +enum TerminalSelectionMode { SEL_IDLE = 0, SEL_EMPTY = 1, SEL_READY = 2 }; -enum selection_type { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 }; +enum TerminalSelectionType { SEL_REGULAR = 1, SEL_RECTANGULAR = 2 }; -enum selection_snap { SNAP_WORD = 1, SNAP_LINE = 2 }; +enum TerminalSelectionSnap { SNAP_WORD = 1, SNAP_LINE = 2 }; typedef unsigned char uchar; typedef unsigned int uint; @@ -101,29 +101,27 @@ struct TerminalGlyph { return u == r.u && mode == r.mode && fg == r.fg && bg == r.bg; } - bool operator!=( const TerminalGlyph& r ) { - return !(*this == r); - } + bool operator!=( const TerminalGlyph& r ) { return !( *this == r ); } }; typedef TerminalGlyph* Line; -union Arg { +union TerminalArg { int i; uint ui; float f; const void* v; const char* s; - Arg() { memset( this, 0, sizeof( *this ) ); } - Arg( int x ) { i = x; } - Arg( uint x ) { ui = x; } - Arg( float x ) { f = x; } - Arg( const void* x ) { v = x; } - Arg( const char* x ) { s = x; } + TerminalArg() { memset( this, 0, sizeof( *this ) ); } + TerminalArg( int x ) { i = x; } + TerminalArg( uint x ) { ui = x; } + TerminalArg( float x ) { f = x; } + TerminalArg( const void* x ) { v = x; } + TerminalArg( const char* x ) { s = x; } }; -enum term_mode { +enum TermMode { MODE_WRAP = 1 << 0, MODE_INSERT = 1 << 1, MODE_ALTSCREEN = 1 << 2, @@ -133,13 +131,13 @@ enum term_mode { MODE_UTF8 = 1 << 6, }; -enum cursor_movement { CURSOR_SAVE, CURSOR_LOAD }; +enum TerminalCursorMovement { CURSOR_SAVE, CURSOR_LOAD }; -enum cursor_state { CURSOR_DEFAULT = 0, CURSOR_WRAPNEXT = 1, CURSOR_ORIGIN = 2 }; +enum TerminalCursorState { CURSOR_DEFAULT = 0, CURSOR_WRAPNEXT = 1, CURSOR_ORIGIN = 2 }; -enum charset { CS_GRAPHIC0, CS_GRAPHIC1, CS_UK, CS_USA, CS_MULTI, CS_GER, CS_FIN }; +enum TerminalCharset { CS_GRAPHIC0, CS_GRAPHIC1, CS_UK, CS_USA, CS_MULTI, CS_GER, CS_FIN }; -enum escape_state { +enum TerminalEscapeState { ESC_START = 1, ESC_CSI = 2, ESC_STR = 4, /* DCS, OSC, PM, APC */ @@ -149,14 +147,14 @@ enum escape_state { ESC_UTF8 = 64, }; -typedef struct { +struct TerminalCursor { TerminalGlyph attr; /* current char attributes */ int x; int y; char state; -} TCursor; +}; -typedef struct { +struct TerminalSelection { int mode; int type; int snap; @@ -172,6 +170,6 @@ typedef struct { } nb, ne, ob, oe; int alt; -} Selection; +}; }} // namespace EE::Terminal