-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for selection content in the dom.
- Loading branch information
1 parent
751c8fa
commit 6fafa2d
Showing
25 changed files
with
1,001 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2020 Arthur Sonzogni. All rights reserved. | ||
// Use of this source code is governed by the MIT license that can be found in | ||
// the LICENSE file. | ||
#include <string> // for char_traits, operator+, string, basic_string | ||
|
||
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical | ||
#include "ftxui/component/component_base.hpp" // for ComponentBase | ||
#include "ftxui/component/component_options.hpp" // for InputOption | ||
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive | ||
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border | ||
#include "ftxui/util/ref.hpp" // for Ref | ||
|
||
using namespace ftxui; | ||
|
||
Element LoremIpsum() { | ||
return vbox({ | ||
text("FTXUI: A powerful library for building user interfaces."), | ||
text("Enjoy a rich set of components and a declarative style."), | ||
text("Create beautiful and responsive UIs with minimal effort."), | ||
text("Join the community and experience the power of FTXUI."), | ||
}); | ||
} | ||
|
||
int main() { | ||
auto screen = ScreenInteractive::TerminalOutput(); | ||
|
||
auto quit = | ||
Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated()); | ||
|
||
int selection_change_counter = 0; | ||
std::string selection_content = ""; | ||
screen.SelectionChange([&] { | ||
selection_change_counter++; | ||
selection_content = screen.GetSelection(); | ||
}); | ||
|
||
// The components: | ||
auto renderer = Renderer(quit, [&] { | ||
return vbox({ | ||
text("Select changed: " + std::to_string(selection_change_counter) + | ||
" times"), | ||
text("Currently selected: "), | ||
paragraph(selection_content) | vscroll_indicator | frame | border | | ||
size(HEIGHT, EQUAL, 10), | ||
window(text("Horizontal split"), hbox({ | ||
LoremIpsum(), | ||
separator(), | ||
LoremIpsum(), | ||
separator(), | ||
LoremIpsum(), | ||
})), | ||
window(text("Vertical split"), vbox({ | ||
LoremIpsum(), | ||
separator(), | ||
LoremIpsum(), | ||
separator(), | ||
LoremIpsum(), | ||
})), | ||
window(text("Grid split with different style"), | ||
vbox({ | ||
hbox({ | ||
LoremIpsum(), | ||
separator(), | ||
LoremIpsum() // | ||
| selectionBackgroundColor(Color::Yellow) // | ||
| selectionColor(Color::Black) // | ||
| selectionStyleReset, | ||
separator(), | ||
LoremIpsum() | selectionColor(Color::Blue), | ||
}), | ||
separator(), | ||
hbox({ | ||
LoremIpsum() | selectionColor(Color::Red), | ||
separator(), | ||
LoremIpsum() | selectionStyle([](Pixel& pixel) { | ||
pixel.underlined_double = true; | ||
}), | ||
separator(), | ||
LoremIpsum(), | ||
}), | ||
})), | ||
quit->Render(), | ||
}); | ||
}); | ||
|
||
screen.Loop(renderer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Arthur Sonzogni. All rights reserved. | ||
// Use of this source code is governed by the MIT license that can be found in | ||
// the LICENSE file. | ||
|
||
#ifndef FTXUI_DOM_SELECTION_HPP | ||
#define FTXUI_DOM_SELECTION_HPP | ||
|
||
#include <functional> | ||
|
||
#include <sstream> | ||
#include "ftxui/screen/box.hpp" // for Box | ||
#include "ftxui/screen/pixel.hpp" // for Pixel | ||
|
||
namespace ftxui { | ||
|
||
/// @brief Represent a selection in the terminal. | ||
class Selection { | ||
public: | ||
Selection(); // Empty selection. | ||
Selection(int start_x, int start_y, int end_x, int end_y); | ||
|
||
const Box& GetBox() const; | ||
|
||
Selection SaturateHorizontal(Box box); | ||
Selection SaturateVertical(Box box); | ||
bool IsEmpty() const { return empty_; } | ||
|
||
void AddPart(const std::string& part, int y, int left, int right); | ||
std::string GetParts() { return parts_.str(); } | ||
|
||
private: | ||
Selection(int start_x, int start_y, int end_x, int end_y, Selection* parent); | ||
|
||
Selection* const parent_ = this; | ||
const bool empty_ = true; | ||
const int start_x_ = 0; | ||
const int start_y_ = 0; | ||
const int end_x_ = 0; | ||
const int end_y_ = 0; | ||
const Box box_ = {}; | ||
std::stringstream parts_; | ||
|
||
// The position of the last inserted part. | ||
int x_ = 0; | ||
int y_ = 0; | ||
}; | ||
|
||
} // namespace ftxui | ||
|
||
#endif /* end of include guard: FTXUI_DOM_SELECTION_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.