Skip to content

Commit

Permalink
Allow naming of the tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Jan 9, 2025
1 parent ca16c0e commit 044de05
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/contour/TerminalSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class TerminalSession: public QAbstractItemModel, public vtbackend::Terminal::Ev

QString title() const;
void setTitle(QString const& value) { terminal().setWindowTitle(value.toStdString()); }
std::string name() const { return terminal().windowTitle(); }

int pageLineCount() const noexcept { return unbox(_terminal.pageSize().lines); }

Expand Down
9 changes: 8 additions & 1 deletion src/contour/TerminalSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ class TerminalSessionManager: public QAbstractListModel
return;

_activeSession->terminal().setGuiTabInfoForStatusLine(vtbackend::TabsInfo {
.tabCount = _sessions.size(),
.tabs = std::ranges::transform_view(_sessions,
[](auto* session) {
return vtbackend::TabsInfo::Tab {
.name = session->name(),
.color = vtbackend::RGBColor { 0, 0, 0 },
};
})
| ranges::to<std::vector>(),
.activeTabPosition = 1 + getSessionIndexOf(_activeSession).value_or(0),
});
}
Expand Down
8 changes: 5 additions & 3 deletions src/vtbackend/StatusLineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <chrono>
#include <cstdio>
#include <format>
#include <optional>

using namespace std::string_view_literals;

Expand Down Expand Up @@ -156,6 +157,7 @@ std::optional<StatusLineDefinitions::Item> makeStatusLineItem(
styles,
activeColor,
activeBackground,
std::nullopt,
};
}

Expand Down Expand Up @@ -443,10 +445,10 @@ struct VTSerializer
auto const tabsInfo = vt.guiTabsInfoForStatusLine();

std::string fragment;
for (const auto position: std::views::iota(1u, tabsInfo.tabCount + 1))
for (const auto position: std::views::iota(1u, tabsInfo.tabs.size() + 1))
{
if (!fragment.empty())
fragment += ' ';
fragment += tabs.separator.value_or("|");

auto const isActivePosition = position == tabsInfo.activeTabPosition;
auto const activePositionStylized =
Expand All @@ -459,7 +461,7 @@ struct VTSerializer
fragment += makeBackgroundColor(tabs.activeBackground);
}

fragment += std::to_string(position);
fragment += tabsInfo.tabs[position - 1].name;

if (activePositionStylized)
fragment += SGRRESTORE();
Expand Down
1 change: 1 addition & 0 deletions src/vtbackend/StatusLineBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace StatusLineDefinitions
{
std::optional<RGBColor> activeColor;
std::optional<RGBColor> activeBackground;
std::optional<std::string> separator;
};

using Item = std::variant<
Expand Down
10 changes: 8 additions & 2 deletions src/vtbackend/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <mutex>
#include <stack>
#include <string_view>
#include <utility>

namespace vtbackend
{
Expand Down Expand Up @@ -209,7 +210,12 @@ class TraceHandler: public SequenceHandler

struct TabsInfo
{
size_t tabCount = 1;
struct Tab
{
std::string name;
Color color;
};
std::vector<Tab> tabs;
size_t activeTabPosition = 1;
};

Expand Down Expand Up @@ -966,7 +972,7 @@ class Terminal
void resetStatusLineDefinition();

TabsInfo guiTabsInfoForStatusLine() const noexcept { return _guiTabInfoForStatusLine; }
void setGuiTabInfoForStatusLine(TabsInfo info) { _guiTabInfoForStatusLine = info; }
void setGuiTabInfoForStatusLine(TabsInfo&& info) { _guiTabInfoForStatusLine = std::move(info); }

private:
void mainLoop();
Expand Down

0 comments on commit 044de05

Please sign in to comment.