Skip to content

Commit 821dbf8

Browse files
committed
Add support for tmux control mode (#3656)
1 parent eefdfd8 commit 821dbf8

File tree

4 files changed

+14
-42
lines changed

4 files changed

+14
-42
lines changed

src/cascadia/TerminalApp/TmuxControl.cpp

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ namespace winrt::TerminalApp::implementation
267267

268268
// Tmux use one character to draw separator line, so we have to make the padding
269269
// plus two borders equals one character's width or height
270-
// Same reason, we have to disable the scrollbar, otherwise the local panes size
270+
// Same reason, we have to disable the scrollbar. Otherwise the local panes size
271271
// will not match Tmux's.
272272
_thickness.Left = _thickness.Right = int((_fontWidth - 2 * PaneBorderSize) / 2);
273273
_thickness.Top = _thickness.Bottom = int((_fontHeight - 2 * PaneBorderSize) / 2);
@@ -555,46 +555,9 @@ namespace winrt::TerminalApp::implementation
555555
search->second.initialized = true;
556556
});
557557

558-
control.CharSent([this, paneId](auto, auto& args) {
559-
auto ch = args.Character();
560-
std::wstring keys(1, static_cast<wchar_t>(ch));
561-
_SendKey(paneId, keys);
562-
});
563-
564-
control.KeySent([this, paneId](auto, auto& args) {
565-
auto keyDown = args.KeyDown();
566-
if (!keyDown)
567-
{
568-
return;
569-
}
570-
571-
auto ch = static_cast<VirtualKey>(args.VKey());
572-
std::wstring out = L"";
573-
if (ch == VirtualKey::Up)
574-
{
575-
out = L"\033[A";
576-
}
577-
else if (ch == VirtualKey::Down)
578-
{
579-
out = L"\033[B";
580-
}
581-
else if (ch == VirtualKey::Right)
582-
{
583-
out = L"\033[C";
584-
}
585-
else if (ch == VirtualKey::Left)
586-
{
587-
out = L"\033[D";
588-
}
589-
else if (ch == VirtualKey::Tab)
590-
{
591-
out = L"\t";
592-
}
593-
594-
if (out.size() > 0)
595-
{
596-
_SendKey(paneId, out);
597-
}
558+
connection.TerminalInput([this, paneId](auto keys) {
559+
std::wstring out{ keys };
560+
_SendKey(paneId, out);
598561
});
599562

600563
control.GotFocus([this, windowId, paneId](auto, auto) {

src/cascadia/TerminalConnection/DummyConnection.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
1515
{
1616
}
1717

18-
void DummyConnection::WriteInput(const winrt::array_view<const char16_t> /*buffer*/)
18+
void DummyConnection::WriteInput(const winrt::array_view<const char16_t> buffer)
1919
{
20+
const auto data = winrt_array_to_wstring_view(buffer);
21+
std::wstringstream prettyPrint;
22+
for (const auto& wch : data)
23+
{
24+
prettyPrint << wch;
25+
}
26+
TerminalInput.raise(prettyPrint.str());
2027
}
2128

2229
void DummyConnection::Resize(uint32_t /*rows*/, uint32_t /*columns*/) noexcept

src/cascadia/TerminalConnection/DummyConnection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
2222
ConnectionState State() const noexcept { return ConnectionState::Connected; }
2323

2424
til::event<TerminalOutputHandler> TerminalOutput;
25+
til::event<TerminalOutputHandler> TerminalInput;
2526
til::typed_event<ITerminalConnection, IInspectable> StateChanged;
2627

2728
bool _rawMode { false };

src/cascadia/TerminalConnection/DummyConnection.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.Terminal.TerminalConnection
99
runtimeclass DummyConnection : ITerminalConnection
1010
{
1111
DummyConnection();
12+
event TerminalOutputHandler TerminalInput;
1213
};
1314

1415
}

0 commit comments

Comments
 (0)