mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
namespace cleanup
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "sharing/linux/tui/ui/home_screen.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
namespace {
|
||||
|
||||
std::string GetHostname() {
|
||||
@@ -16,7 +17,7 @@ std::string GetHostname() {
|
||||
|
||||
} // namespace
|
||||
|
||||
TuiApp::TuiApp() : screen_(ftxui::ScreenInteractive::Fullscreen()) {
|
||||
TuiApp::TuiApp() : screen_(ScreenInteractive::Fullscreen()) {
|
||||
hostname_ = GetHostname();
|
||||
screen_.TrackMouse(true);
|
||||
}
|
||||
@@ -34,20 +35,20 @@ int TuiApp::Run() {
|
||||
},
|
||||
});
|
||||
|
||||
auto app = ftxui::CatchEvent(
|
||||
component, [this](ftxui::Event event) { return HandleEvent(event); });
|
||||
auto app =
|
||||
CatchEvent(component, [this](Event event) { return HandleEvent(event); });
|
||||
|
||||
screen_.Loop(app);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool TuiApp::HandleEvent(ftxui::Event event) {
|
||||
if (event == ftxui::Event::Character('q') || event == ftxui::Event::Escape) {
|
||||
bool TuiApp::HandleEvent(Event event) {
|
||||
if (event == Event::Character('q') || event == Event::Escape) {
|
||||
screen_.ExitLoopClosure()();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event == ftxui::Event::Backspace && current_page_ == Page::Sharing) {
|
||||
if (event == Event::Backspace && current_page_ == Page::Sharing) {
|
||||
current_page_ = Page::FilePicker;
|
||||
selected_file_.clear();
|
||||
return true;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
class TuiApp {
|
||||
public:
|
||||
@@ -15,9 +16,9 @@ class TuiApp {
|
||||
int Run();
|
||||
|
||||
private:
|
||||
bool HandleEvent(ftxui::Event event);
|
||||
bool HandleEvent(Event event);
|
||||
|
||||
ftxui::ScreenInteractive screen_;
|
||||
ScreenInteractive screen_;
|
||||
ZenityFilePicker file_picker_;
|
||||
Page current_page_ = Page::FilePicker;
|
||||
std::string hostname_;
|
||||
|
||||
@@ -13,6 +13,19 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "brand",
|
||||
srcs = [
|
||||
"brand.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"brand.h",
|
||||
],
|
||||
deps = [
|
||||
"@ftxui//:ftxui",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "file_picker_card",
|
||||
srcs = [
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Element Brand();
|
||||
Element Brand();
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
#include "sharing/linux/tui/components/file_icon.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Element FileIcon(FileIconSize size) {
|
||||
Element FileIcon(FileIconSize size) {
|
||||
if (size == FileIconSize::Small) {
|
||||
return ftxui::vbox({
|
||||
ftxui::text(" ______ ") | ftxui::center,
|
||||
ftxui::text(" / | | ") | ftxui::center,
|
||||
ftxui::text(" /__| | ") | ftxui::center,
|
||||
ftxui::text(" | ----- | ") | ftxui::center,
|
||||
ftxui::text(" | ----- | ") | ftxui::center,
|
||||
ftxui::text(" |_______| ") | ftxui::center,
|
||||
return vbox({
|
||||
text(" ______ ") | center,
|
||||
text(" / | | ") | center,
|
||||
text(" /__| | ") | center,
|
||||
text(" | ----- | ") | center,
|
||||
text(" | ----- | ") | center,
|
||||
text(" |_______| ") | center,
|
||||
});
|
||||
}
|
||||
|
||||
return ftxui::vbox({
|
||||
ftxui::text(" __________ ") | ftxui::center,
|
||||
ftxui::text(" / | | ") | ftxui::center,
|
||||
ftxui::text(" /__| | ") | ftxui::center,
|
||||
ftxui::text(" | --------- | ") | ftxui::center,
|
||||
ftxui::text(" | --------- | ") | ftxui::center,
|
||||
ftxui::text(" | --------- | ") | ftxui::center,
|
||||
ftxui::text(" | --------- | ") | ftxui::center,
|
||||
ftxui::text(" |___________| ") | ftxui::center,
|
||||
return vbox({
|
||||
text(" __________ ") | center,
|
||||
text(" / | | ") | center,
|
||||
text(" /__| | ") | center,
|
||||
text(" | --------- | ") | center,
|
||||
text(" | --------- | ") | center,
|
||||
text(" | --------- | ") | center,
|
||||
text(" | --------- | ") | center,
|
||||
text(" |___________| ") | center,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
enum class FileIconSize {
|
||||
Large,
|
||||
Small,
|
||||
};
|
||||
|
||||
ftxui::Element FileIcon(FileIconSize size);
|
||||
Element FileIcon(FileIconSize size);
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -9,61 +9,59 @@
|
||||
#include "sharing/linux/tui/palette.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Component FilePickerCard(FilePickerCardOptions options) {
|
||||
auto picker_box = std::make_shared<ftxui::Box>();
|
||||
Component FilePickerCard(FilePickerCardOptions options) {
|
||||
auto picker_box = std::make_shared<Box>();
|
||||
auto hovered = std::make_shared<bool>(false);
|
||||
|
||||
auto card = ftxui::Renderer([picker_box, hovered] {
|
||||
auto card = Renderer([picker_box, hovered] {
|
||||
auto picker_card =
|
||||
ftxui::vbox({
|
||||
FileIcon(FileIconSize::Large) | ftxui::color(Palette::secondary),
|
||||
ftxui::separatorEmpty(),
|
||||
ftxui::text("Select file to share") | ftxui::bold | ftxui::center,
|
||||
vbox({
|
||||
FileIcon(FileIconSize::Large) | color(Palette::secondary),
|
||||
separatorEmpty(),
|
||||
text("Select file to share") | bold | center,
|
||||
}) |
|
||||
ftxui::borderStyled(*hovered ? Palette::primary : Palette::secondary) |
|
||||
ftxui::size(ftxui::WIDTH, ftxui::GREATER_THAN, 33) |
|
||||
ftxui::size(ftxui::HEIGHT, ftxui::EQUAL, 13) |
|
||||
ftxui::reflect(*picker_box);
|
||||
borderStyled(*hovered ? Palette::primary : Palette::secondary) |
|
||||
size(WIDTH, GREATER_THAN, 33) | size(HEIGHT, EQUAL, 13) |
|
||||
reflect(*picker_box);
|
||||
|
||||
return ftxui::vbox({
|
||||
ftxui::filler(),
|
||||
ftxui::hbox({
|
||||
ftxui::filler(),
|
||||
return vbox({
|
||||
filler(),
|
||||
hbox({
|
||||
filler(),
|
||||
picker_card,
|
||||
ftxui::filler(),
|
||||
filler(),
|
||||
}),
|
||||
ftxui::filler(),
|
||||
filler(),
|
||||
}) |
|
||||
ftxui::flex;
|
||||
flex;
|
||||
});
|
||||
|
||||
return ftxui::CatchEvent(
|
||||
card, [picker_box, hovered, options](ftxui::Event event) {
|
||||
if (!event.is_mouse()) {
|
||||
return false;
|
||||
}
|
||||
return CatchEvent(card, [picker_box, hovered, options](Event event) {
|
||||
if (!event.is_mouse()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mouse = event.mouse();
|
||||
bool inside_picker =
|
||||
mouse.x >= picker_box->x_min && mouse.x <= picker_box->x_max &&
|
||||
mouse.y >= picker_box->y_min && mouse.y <= picker_box->y_max;
|
||||
auto mouse = event.mouse();
|
||||
bool inside_picker =
|
||||
mouse.x >= picker_box->x_min && mouse.x <= picker_box->x_max &&
|
||||
mouse.y >= picker_box->y_min && mouse.y <= picker_box->y_max;
|
||||
|
||||
*hovered = inside_picker;
|
||||
*hovered = inside_picker;
|
||||
|
||||
if (!inside_picker || mouse.button != ftxui::Mouse::Left ||
|
||||
mouse.motion != ftxui::Mouse::Pressed ||
|
||||
options.file_picker == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (!inside_picker || mouse.button != Mouse::Left ||
|
||||
mouse.motion != Mouse::Pressed || options.file_picker == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string path = options.file_picker->PickFile();
|
||||
if (!path.empty() && options.on_file_selected) {
|
||||
options.on_file_selected(path);
|
||||
}
|
||||
std::string path = options.file_picker->PickFile();
|
||||
if (!path.empty() && options.on_file_selected) {
|
||||
options.on_file_selected(path);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
#include "sharing/linux/tui/file_picker.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
struct FilePickerCardOptions {
|
||||
FilePicker* file_picker = nullptr;
|
||||
std::function<void(std::string)> on_file_selected;
|
||||
};
|
||||
|
||||
ftxui::Component FilePickerCard(FilePickerCardOptions options);
|
||||
Component FilePickerCard(FilePickerCardOptions options);
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
+11
-10
@@ -3,22 +3,23 @@
|
||||
#include "ftxui/screen/color.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
struct Palette {
|
||||
inline static const ftxui::Color primary =
|
||||
ftxui::Color::RGB(0xF1, 0xF9, 0xF6); // Off-white mint tint
|
||||
inline static const Color primary =
|
||||
Color::RGB(0xF1, 0xF9, 0xF6); // Off-white mint tint
|
||||
|
||||
inline static const ftxui::Color secondary =
|
||||
ftxui::Color::RGB(0x8A, 0xAF, 0xA4); // Muted sage gray
|
||||
inline static const Color secondary =
|
||||
Color::RGB(0x8A, 0xAF, 0xA4); // Muted sage gray
|
||||
|
||||
inline static const ftxui::Color accent =
|
||||
ftxui::Color::RGB(0xA3, 0xD9, 0xC9); // Original Mint Leaf
|
||||
inline static const Color accent =
|
||||
Color::RGB(0xA3, 0xD9, 0xC9); // Original Mint Leaf
|
||||
|
||||
inline static const ftxui::Color active =
|
||||
ftxui::Color::RGB(0x23, 0x3D, 0x34); // Deep forest green tint
|
||||
inline static const Color active =
|
||||
Color::RGB(0x23, 0x3D, 0x34); // Deep forest green tint
|
||||
|
||||
inline static const ftxui::Color base =
|
||||
ftxui::Color::RGB(0x12, 0x1D, 0x1A); // Near-black deep mint/charcoal
|
||||
inline static const Color base =
|
||||
Color::RGB(0x12, 0x1D, 0x1A); // Near-black deep mint/charcoal
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -10,6 +10,7 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
"@ftxui//:ftxui",
|
||||
"//sharing/linux/tui/components:brand"
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -3,18 +3,17 @@
|
||||
#include "sharing/linux/tui/palette.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Element FileSelectedScreen(const std::string& selected_file) {
|
||||
return ftxui::vbox({
|
||||
ftxui::text("File selected") | ftxui::bold | ftxui::center |
|
||||
ftxui::color(Palette::primary),
|
||||
ftxui::separator(),
|
||||
ftxui::paragraph(selected_file) | ftxui::center,
|
||||
ftxui::separatorEmpty(),
|
||||
ftxui::text("Press Backspace to choose another file") |
|
||||
ftxui::dim | ftxui::center,
|
||||
Element FileSelectedScreen(const std::string& selected_file) {
|
||||
return vbox({
|
||||
text("File selected") | bold | center | color(Palette::primary),
|
||||
separator(),
|
||||
paragraph(selected_file) | center,
|
||||
separatorEmpty(),
|
||||
text("Press Backspace to choose another file") | dim | center,
|
||||
}) |
|
||||
ftxui::borderStyled(Palette::primary) | ftxui::flex;
|
||||
borderStyled(Palette::primary) | flex;
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Element FileSelectedScreen(const std::string& selected_file);
|
||||
Element FileSelectedScreen(const std::string& selected_file);
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Element HomeHeader();
|
||||
Element HomeHeader();
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
#include "sharing/linux/tui/ui/sidebar.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
ftxui::Component HomeScreen(HomeScreenOptions options) {
|
||||
Component HomeScreen(HomeScreenOptions options) {
|
||||
auto file_picker_card =
|
||||
FilePickerCard({.file_picker = options.file_picker,
|
||||
.on_file_selected = options.on_file_selected});
|
||||
|
||||
return ftxui::Renderer(file_picker_card, [file_picker_card, options] {
|
||||
return Renderer(file_picker_card, [file_picker_card, options] {
|
||||
const std::string selected_file =
|
||||
options.selected_file == nullptr ? "" : *options.selected_file;
|
||||
const Page current_page = options.current_page == nullptr
|
||||
@@ -25,18 +26,17 @@ ftxui::Component HomeScreen(HomeScreenOptions options) {
|
||||
? file_picker_card->Render()
|
||||
: FileSelectedScreen(selected_file);
|
||||
|
||||
return ftxui::vbox({
|
||||
HomeHeader() | ftxui::color(Palette::accent),
|
||||
ftxui::separator(),
|
||||
ftxui::hbox({
|
||||
return vbox({
|
||||
HomeHeader() | color(Palette::accent),
|
||||
separator(),
|
||||
hbox({
|
||||
Sidebar({.hostname = options.hostname,
|
||||
.selected_file = selected_file}),
|
||||
main_panel | ftxui::flex,
|
||||
}) | ftxui::flex,
|
||||
main_panel | flex,
|
||||
}) | flex,
|
||||
}) |
|
||||
ftxui::bgcolor(Palette::base) |
|
||||
ftxui::size(ftxui::WIDTH, ftxui::GREATER_THAN, 80) |
|
||||
ftxui::size(ftxui::HEIGHT, ftxui::GREATER_THAN, 24);
|
||||
bgcolor(Palette::base) | size(WIDTH, GREATER_THAN, 80) |
|
||||
size(HEIGHT, GREATER_THAN, 24);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "sharing/linux/tui/page.h"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
struct HomeScreenOptions {
|
||||
std::string hostname;
|
||||
@@ -17,6 +18,6 @@ struct HomeScreenOptions {
|
||||
std::function<void(std::string)> on_file_selected;
|
||||
};
|
||||
|
||||
ftxui::Component HomeScreen(HomeScreenOptions options);
|
||||
Component HomeScreen(HomeScreenOptions options);
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
@@ -8,15 +8,12 @@ using namespace ftxui;
|
||||
|
||||
Element Sidebar(const SidebarState& state) {
|
||||
auto visible_as_box =
|
||||
window(
|
||||
text(" Visible as "),
|
||||
vbox({
|
||||
text(""),
|
||||
text(state.hostname) | bold | center,
|
||||
text(""),
|
||||
})) |
|
||||
size(WIDTH, GREATER_THAN, 24) |
|
||||
size(HEIGHT, EQUAL, 5);
|
||||
window(text(" Visible as "), vbox({
|
||||
text(""),
|
||||
text(state.hostname) | bold | center,
|
||||
text(""),
|
||||
})) |
|
||||
size(WIDTH, GREATER_THAN, 24) | size(HEIGHT, EQUAL, 5);
|
||||
|
||||
if (state.selected_file.empty()) {
|
||||
return vbox({
|
||||
@@ -28,13 +25,12 @@ Element Sidebar(const SidebarState& state) {
|
||||
return vbox({
|
||||
visible_as_box,
|
||||
filler(),
|
||||
window(
|
||||
text(" Selected to share ") | center,
|
||||
vbox({
|
||||
FileIcon(FileIconSize::Small) | color(Palette::accent),
|
||||
text(""),
|
||||
paragraph(state.selected_file) | dim,
|
||||
})) |
|
||||
window(text(" Selected to share ") | center,
|
||||
vbox({
|
||||
FileIcon(FileIconSize::Small) | color(Palette::accent),
|
||||
text(""),
|
||||
paragraph(state.selected_file) | dim,
|
||||
})) |
|
||||
size(WIDTH, EQUAL, 24),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace nearby::sharing::linux_tui {
|
||||
using namespace ftxui;
|
||||
|
||||
struct SidebarState {
|
||||
std::string hostname;
|
||||
std::string selected_file;
|
||||
};
|
||||
|
||||
ftxui::Element Sidebar(const SidebarState& state);
|
||||
Element Sidebar(const SidebarState& state);
|
||||
|
||||
} // namespace nearby::sharing::linux_tui
|
||||
|
||||
Reference in New Issue
Block a user