/*
* Ricochet - A minimalist CLI web browser for fast, distraction-free navigation.
* Copyright (C) 2026 Richard Qin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#pragma once
#include "ricochet/tui/document.hh"
#include "ricochet/tui/view.hh"
#include
#include
#include
#include
#include
namespace ricochet::tui {
struct TabInfo
{
TabId id {};
std::string title {};
std::string display_url {};
std::optional loading_task {};
};
struct SyncTabs
{
// Vector order is tab order. Request IDs acknowledge create/close actions.
std::vector tabs {};
std::optional active {};
std::vector completed_requests {};
};
struct NavigationStarted
{
TabId tab {};
RequestId request {};
TaskId task {};
std::string display_target {};
};
struct CommitDocument
{
TabId tab {};
RequestId navigation {};
Document document;
std::optional restore {};
};
struct TextCorrespondence
{
// The producer identifies identical text in the two revisions, including every
// changed portion crossed by a selection. This is not an inferred text diff.
TextRange source {};
TextRange target {};
};
struct PositionMapping
{
DocumentVersion source {};
DocumentVersion target {};
std::vector text {};
};
enum class ViewRetention : std::uint8_t
{
Reset,
PreserveUnchanged
};
struct UpdateDocument
{
TabId tab {};
RequestId navigation {};
DocumentVersion source {};
Document document;
ViewRetention retention { ViewRetention::PreserveUnchanged };
std::optional mapping {};
};
struct LocateView
{
DocumentScope scope {};
std::variant target {};
};
// Values are keyed by control identity, never by field name or action URL.
// These business messages may carry passwords; ViewSnapshot deliberately does not.
using ControlValue = std::variant>;
struct ControlDraft
{
ControlId control {};
ControlValue value {};
};
struct FieldError
{
ControlId control {};
std::string message {};
};
struct FormFeedback
{
DocumentScope scope {};
FormId form {};
RequestId request {};
DraftRevision draft_revision {};
std::vector errors {};
std::vector normalized_values {};
};
struct ActionFailed
{
RequestId request {};
std::optional tab {};
std::string summary {};
std::optional details {};
};
struct ExitDecision
{
RequestId request {};
bool approved { false };
std::optional explanation {};
};
enum class CopyStatus : std::uint8_t
{
Confirmed,
Dispatched,
Unavailable,
Failed
};
// The host's injected clipboard provider completes a CopySelection request once.
// Dispatched must not be used as confirmation that a terminal accepted the text.
struct CopyResult
{
RequestId request {};
CopyStatus status { CopyStatus::Unavailable };
std::string summary {};
};
using HostUpdate = std::variant;
enum class OpenTarget : std::uint8_t
{
CurrentTab,
NewTab
};
struct OpenLocation
{
RequestId request {};
TabId tab {};
std::string input {};
OpenTarget target { OpenTarget::CurrentTab };
};
struct OpenLink
{
RequestId request {};
DocumentScope source {};
LinkId link {};
std::string target {};
OpenTarget destination { OpenTarget::CurrentTab };
};
enum class NavigationCommand : std::uint8_t
{
Back,
Forward,
Reload
};
struct Navigate
{
RequestId request {};
TabId tab {};
std::optional document {};
NavigationCommand command { NavigationCommand::Reload };
};
struct CreateTab
{ RequestId request {}; };
struct CloseTab
{
RequestId request {};
TabId tab {};
};
enum class FormOperation : std::uint8_t
{
Submit,
Reset
};
struct FormAction
{
RequestId request {};
DocumentScope scope {};
FormId form {};
std::optional button {};
DraftRevision draft_revision {};
FormOperation operation { FormOperation::Submit };
std::vector values {};
};
struct ExportSelection
{
RequestId request {};
DocumentScope source {};
// Already extracted from one view snapshot; passwords are masked.
std::string text {};
};
struct CopySelection
{
RequestId request {};
DocumentScope source {};
DraftRevision draft_revision {};
// Frozen before dispatch; later cursor/selection changes cannot change this copy.
// Password content is already masked. Clipboard providers never receive drafts.
std::string text {};
};
struct RequestExit
{
RequestId request {};
std::optional active {};
std::vector views {};
};
using UserAction = std::variant;
} // namespace ricochet::tui