diff --git a/src/apps/terminal/TermConst.h b/src/apps/terminal/TermConst.h index 31cb7f4d2d..72532df888 100644 --- a/src/apps/terminal/TermConst.h +++ b/src/apps/terminal/TermConst.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2015, Haiku. + * Copyright 2001-2023, Haiku, Inc. All rights reserved. * Copyright (c) 2003-4 Kian Duffy * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * @@ -81,6 +81,7 @@ static const uint32 MSG_SET_TERMINAL_COLORS = 'setc'; static const uint32 MSG_RESET_TERMINAL_COLORS = 'rstc'; static const uint32 MSG_QUIT_TERMNAL = 'qutt'; static const uint32 MSG_ENABLE_META_KEY = 'emtk'; +static const uint32 MSG_ENABLE_BRACKETED_PASTE = 'ebkp'; static const uint32 MSG_REPORT_MOUSE_EVENT = 'mous'; static const uint32 MSG_SAVE_WINDOW_POSITION = 'swps'; static const uint32 MSG_MOVE_TAB_LEFT = 'mvtl'; diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index adcb2359a5..e1e9511d26 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2013, Haiku, Inc. + * Copyright 2001-2023, Haiku, Inc. All rights reserved. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * Distributed under the terms of the MIT license. @@ -1420,6 +1420,10 @@ TermParse::_DecPrivateModeSet(int value) fBuffer->SaveCursor(); fBuffer->UseAlternateScreenBuffer(true); break; + case 2004: + // Enable bracketed paste mode + fBuffer->EnableBracketedPasteMode(true); + break; } } @@ -1498,6 +1502,10 @@ TermParse::_DecPrivateModeReset(int value) fBuffer->UseNormalScreenBuffer(); fBuffer->RestoreCursor(); break; + case 2004: + // Disable bracketed paste mode + fBuffer->EnableBracketedPasteMode(false); + break; } } diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 6d2e77af0d..5fae17eddb 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2014, Haiku, Inc. + * Copyright 2001-2023, Haiku, Inc. All rights reserved. * Copyright 2003-2004 Kian Duffy, myob@users.sourceforge.net * Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai. * All rights reserved. Distributed under the terms of the MIT license. @@ -316,6 +316,7 @@ TermView::_InitObject(const ShellParameters& shellParameters) fUseOptionAsMetaKey = false; fInterpretMetaKey = true; fMetaKeySendsEscape = true; + fUseBracketedPaste = false; fReportX10MouseEvent = false; fReportNormalMouseEvent = false; fReportButtonMouseEvent = false; @@ -922,7 +923,13 @@ TermView::Paste(BClipboard *clipboard) ssize_t numBytes; if (clipMsg->FindData("text/plain", B_MIME_TYPE, (const void**)&text, &numBytes) == B_OK ) { + if (fUseBracketedPaste) + fShell->Write(BEGIN_BRACKETED_PASTE_CODE, strlen(BEGIN_BRACKETED_PASTE_CODE)); + _WritePTY(text, numBytes); + + if (fUseBracketedPaste) + fShell->Write(END_BRACKETED_PASTE_CODE, strlen(END_BRACKETED_PASTE_CODE)); } clipboard->Unlock(); @@ -1892,6 +1899,13 @@ TermView::MessageReceived(BMessage *message) fMetaKeySendsEscape = enable; break; } + case MSG_ENABLE_BRACKETED_PASTE: + { + bool enable; + if (message->FindBool("enableBracketedPaste", &enable) == B_OK) + fUseBracketedPaste = enable; + break; + } case MSG_REPORT_MOUSE_EVENT: { bool value; diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 7220fef11c..f74be5fa9b 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2013, Haiku, Inc. + * Copyright 2001-2023, Haiku, Inc. All rights reserved. * Copyright (c) 2003-4 Kian Duffy * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * @@ -353,6 +353,7 @@ private: bool fUseOptionAsMetaKey; bool fInterpretMetaKey; bool fMetaKeySendsEscape; + bool fUseBracketedPaste; // mouse int32 fMouseButtons; diff --git a/src/apps/terminal/TerminalBuffer.cpp b/src/apps/terminal/TerminalBuffer.cpp index d05abdf32c..6581d58fb8 100644 --- a/src/apps/terminal/TerminalBuffer.cpp +++ b/src/apps/terminal/TerminalBuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013, Haiku, Inc. All rights reserved. + * Copyright 2013-2023, Haiku, Inc. All rights reserved. * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. * @@ -113,6 +113,17 @@ TerminalBuffer::EnableMetaKeySendsEscape(bool enable) } +void +TerminalBuffer::EnableBracketedPasteMode(bool enable) +{ + if (fListenerValid) { + BMessage message(MSG_ENABLE_BRACKETED_PASTE); + message.AddBool("enableBracketedPaste", enable); + fListener.SendMessage(&message); + } +} + + void TerminalBuffer::ReportX10MouseEvent(bool reportX10MouseEvent) { diff --git a/src/apps/terminal/TerminalBuffer.h b/src/apps/terminal/TerminalBuffer.h index 3894de7426..73b375bed5 100644 --- a/src/apps/terminal/TerminalBuffer.h +++ b/src/apps/terminal/TerminalBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright 2013, Haiku, Inc. All rights reserved. + * Copyright 2013-2023, Haiku, Inc. All rights reserved. * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. * @@ -56,6 +56,7 @@ public: void EnableInterpretMetaKey(bool enable); void EnableMetaKeySendsEscape(bool enable); + void EnableBracketedPasteMode(bool enable); void ReportX10MouseEvent(bool report); void ReportNormalMouseEvent(bool report); diff --git a/src/apps/terminal/VTkeymap.h b/src/apps/terminal/VTkeymap.h index ca05584b72..f98be1ca74 100644 --- a/src/apps/terminal/VTkeymap.h +++ b/src/apps/terminal/VTkeymap.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2003-4 Kian Duffy - * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. + * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files or portions @@ -83,6 +83,9 @@ #define PAGE_UP_KEY_CODE "\033[5~" #define PAGE_DOWN_KEY_CODE "\033[6~" +#define BEGIN_BRACKETED_PASTE_CODE "\033[200~" +#define END_BRACKETED_PASTE_CODE "\033[201~" + //#define IS_DOWN_KEY(x) (info.key_states[(x) / 8] & key_state_table[(x) % 8]) #define IS_DOWN_KEY(x) \ (info.key_states[(x) >> 3] & (1 << (7 - ((x) % 8))))