Plan clipboard text actions in app core
This commit is contained in:
@@ -182,6 +182,10 @@ struct PlanCursorVisibilityArgs {
|
||||
bool visible = false;
|
||||
};
|
||||
|
||||
struct PlanClipboardWriteArgs {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct SimulateAppSessionArgs {
|
||||
bool has_canvas = true;
|
||||
bool new_document = false;
|
||||
@@ -563,6 +567,26 @@ const char* cursor_visibility_action_name(pp::app::CursorVisibilityAction action
|
||||
return "hide-cursor";
|
||||
}
|
||||
|
||||
const char* clipboard_read_action_name(pp::app::ClipboardReadAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
case pp::app::ClipboardReadAction::read_text:
|
||||
return "read-text";
|
||||
}
|
||||
|
||||
return "read-text";
|
||||
}
|
||||
|
||||
const char* clipboard_write_action_name(pp::app::ClipboardWriteAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
case pp::app::ClipboardWriteAction::write_text:
|
||||
return "write-text";
|
||||
}
|
||||
|
||||
return "write-text";
|
||||
}
|
||||
|
||||
pp::foundation::Result<float> parse_float_arg(std::string_view text)
|
||||
{
|
||||
float value = 0.0F;
|
||||
@@ -608,6 +632,8 @@ void print_help()
|
||||
<< " plan-display-file [--path FILE]\n"
|
||||
<< " plan-keyboard-visibility [--visible]\n"
|
||||
<< " plan-cursor-visibility [--visible]\n"
|
||||
<< " plan-clipboard-read\n"
|
||||
<< " plan-clipboard-write [--text TEXT]\n"
|
||||
<< " load-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
<< " record-render [--width N] [--height N] [--exercise-clear]\n"
|
||||
@@ -2120,6 +2146,52 @@ int plan_cursor_visibility(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plan_clipboard_read(int, char**)
|
||||
{
|
||||
const auto decision = pp::app::plan_clipboard_read();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-clipboard-read\""
|
||||
<< ",\"decision\":\"" << clipboard_read_action_name(decision)
|
||||
<< "\"}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_clipboard_write_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanClipboardWriteArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--text") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.text = argv[++i];
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_clipboard_write(int argc, char** argv)
|
||||
{
|
||||
PlanClipboardWriteArgs args;
|
||||
const auto status = parse_plan_clipboard_write_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-clipboard-write", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto decision = pp::app::plan_clipboard_write(args.text);
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-clipboard-write\""
|
||||
<< ",\"state\":{\"text\":\"" << json_escape(args.text)
|
||||
<< "\"},\"decision\":\"" << clipboard_write_action_name(decision)
|
||||
<< "\"}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_export_target_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -4307,6 +4379,14 @@ int main(int argc, char** argv)
|
||||
return plan_cursor_visibility(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-clipboard-read") {
|
||||
return plan_clipboard_read(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-clipboard-write") {
|
||||
return plan_clipboard_write(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "load-project") {
|
||||
return load_project(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user