syntax = "proto3";

import "action.proto";
import "event.proto";
import "file.proto";
import "command.proto";
import "message.proto";
import "resize.proto";
import "plugin_permission.proto";
import "input_mode.proto";
import "key.proto";

package api.plugin_command;

enum CommandName {
  Subscribe = 0;
  Unsubscribe = 1;
  SetSelectable = 2;
  GetPluginIds = 3;
  GetZellijVersion = 4;
  OpenFile = 5;
  OpenFileFloating = 6;
  OpenTerminal = 7;
  OpenTerminalFloating = 8;
  OpenCommandPane = 9;
  OpenCommandPaneFloating = 10;
  SwitchTabTo = 11;
  SetTimeout = 12;
  ExecCmd = 13;
  PostMessageTo = 14;
  PostMessageToPlugin = 15;
  HideSelf = 16;
  ShowSelf = 17;
  SwitchToMode = 18;
  NewTabsWithLayout = 19;
  NewTab = 20;
  GoToNextTab = 21;
  GoToPreviousTab = 22;
  Resize = 23;
  ResizeWithDirection = 24;
  FocusNextPane = 25;
  FocusPreviousPane = 26;
  MoveFocus = 27;
  MoveFocusOrTab = 28;
  Detach = 29;
  EditScrollback = 30;
  Write = 31;
  WriteChars = 32;
  ToggleTab = 33;
  MovePane = 34;
  MovePaneWithDirection = 35;
  ClearScreen = 36;
  ScrollUp = 37;
  ScrollDown = 38;
  ScrollToTop = 39;
  ScrollToBottom = 40;
  PageScrollUp = 41;
  PageScrollDown = 42;
  ToggleFocusFullscreen = 43;
  TogglePaneFrames = 44;
  TogglePaneEmbedOrEject = 45;
  UndoRenamePane = 46;
  CloseFocus = 47;
  ToggleActiveTabSync = 48;
  CloseFocusedTab = 49;
  UndoRenameTab = 50;
  QuitZellij = 51;
  PreviousSwapLayout = 52;
  NextSwapLayout = 53;
  GoToTabName = 54;
  FocusOrCreateTab = 55;
  GoToTab = 56;
  StartOrReloadPlugin = 57;
  CloseTerminalPane = 58;
  ClosePluginPane = 59;
  FocusTerminalPane = 60;
  FocusPluginPane = 61;
  RenameTerminalPane = 62;
  RenamePluginPane = 63;
  RenameTab = 64;
  ReportCrash = 65;
  RequestPluginPermissions = 66;
  SwitchSession = 67;
  OpenTerminalInPlace = 68;
  OpenCommandInPlace = 69;
  OpenFileInPlace = 70;
  RunCommand = 71;
  WebRequest = 72;
  DeleteDeadSession = 73;
  DeleteAllDeadSessions = 74;
  RenameSession = 75;
  UnblockCliPipeInput = 76;
  BlockCliPipeInput = 77;
  CliPipeOutput = 78;
  MessageToPlugin = 79;
  DisconnectOtherClients = 80;
  KillSessions = 81;
  ScanHostFolder = 82;
  WatchFilesystem = 83;
  DumpSessionLayout = 84;
  CloseSelf = 85;
  NewTabsWithLayoutInfo = 86;
  Reconfigure = 87;
  HidePaneWithId = 88;
  ShowPaneWithId = 89;
  OpenCommandPaneBackground = 90;
  RerunCommandPane = 91;
  ResizePaneIdWithDirection = 92;
  EditScrollbackForPaneWithId = 93;
  WriteToPaneId = 94;
  WriteCharsToPaneId = 95;
  MovePaneWithPaneId = 96;
  MovePaneWithPaneIdInDirection = 97;
  ClearScreenForPaneId = 98;
  ScrollUpInPaneId = 99;
  ScrollDownInPaneId = 100;
  ScrollToTopInPaneId = 101;
  ScrollToBottomInPaneId = 102;
  PageScrollUpInPaneId = 103;
  PageScrollDownInPaneId = 104;
  TogglePaneIdFullscreen = 105;
  TogglePaneEmbedOrEjectForPaneId = 106;
  CloseTabWithIndex = 107;
  BreakPanesToNewTab = 108;
  BreakPanesToTabWithIndex = 109;
  ReloadPlugin = 110;
  LoadNewPlugin = 111;
  RebindKeys = 112;
  ListClients = 113;
  ChangeHostFolder = 114;
  SetFloatingPanePinned = 115;
  StackPanes = 116;
  ChangeFloatingPanesCoordinates = 117;
  OpenCommandPaneNearPlugin = 118;
  OpenTerminalNearPlugin = 119;
  OpenTerminalFloatingNearPlugin = 120;
  OpenTerminalInPlaceOfPlugin = 121;
  OpenCommandPaneFloatingNearPlugin = 122;
  OpenCommandPaneInPlaceOfPlugin = 123;
  OpenFileNearPlugin = 124;
  OpenFileFloatingNearPlugin = 125;
  OpenFileInPlaceOfPlugin = 126;
  StartWebServer = 127;
  GroupAndUngroupPanes = 128;
  HighlightAndUnhighlightPanes = 129;
  CloseMultiplePanes = 130;
  FloatMultiplePanes = 131;
  EmbedMultiplePanes = 132;
  ShareCurrentSession = 133;
  StopSharingCurrentSession = 134;
  StopWebServer = 135;
  QueryWebServerStatus = 136;
  SetSelfMouseSelectionSupport = 137;
  GenerateWebLoginToken = 138;
  RevokeWebLoginToken = 139;
  ListWebLoginTokens = 140;
  RevokeAllWebLoginTokens = 141;
  RenameWebLoginToken = 142;
  InterceptKeyPresses = 143;
  ClearKeyPressesIntercepts = 144;
  ReplacePaneWithExistingPane = 155;
}

message PluginCommand {
  CommandName name = 1;
  oneof payload {
    SubscribePayload subscribe_payload = 2;
    UnsubscribePayload unsubscribe_payload = 3;
    bool set_selectable_payload = 4;
    OpenFilePayload open_file_payload = 5;
    OpenFilePayload open_file_floating_payload = 6;
    OpenFilePayload open_terminal_payload = 7;
    OpenFilePayload open_terminal_floating_payload = 8;
    OpenCommandPanePayload open_command_pane_payload = 9;
    OpenCommandPanePayload open_command_pane_floating_payload = 10;
    SwitchTabToPayload switch_tab_to_payload = 11;
    SetTimeoutPayload set_timeout_payload = 12;
    ExecCmdPayload exec_cmd_payload = 13;
    PluginMessagePayload post_message_to_payload = 14;
    PluginMessagePayload post_message_to_plugin_payload = 15;
    bool show_self_payload = 16;
    action.SwitchToModePayload switch_to_mode_payload = 17;
    string new_tabs_with_layout_payload = 18;
    ResizePayload resize_payload = 19;
    ResizePayload resize_with_direction_payload = 20;
    MovePayload move_focus_payload = 21;
    MovePayload move_focus_or_tab_payload = 22;
    bytes write_payload = 23;
    string write_chars_payload = 24;
    MovePayload move_pane_with_direction_payload = 25;
    string go_to_tab_name_payload = 26;
    string focus_or_create_tab_payload = 27;
    uint32 go_to_tab_payload = 28;
    string start_or_reload_plugin_payload = 29;
    uint32 close_terminal_pane_payload = 30;
    uint32 close_plugin_pane_payload = 31;
    action.PaneIdAndShouldFloat focus_terminal_pane_payload = 32;
    action.PaneIdAndShouldFloat focus_plugin_pane_payload = 33;
    IdAndNewName rename_terminal_pane_payload = 34;
    IdAndNewName rename_plugin_pane_payload = 35;
    IdAndNewName rename_tab_payload = 36;
    string report_crash_payload = 37;
    RequestPluginPermissionPayload request_plugin_permission_payload = 38;
    SwitchSessionPayload switch_session_payload = 39;
    OpenFilePayload open_file_in_place_payload = 40;
    OpenFilePayload open_terminal_in_place_payload = 41;
    OpenCommandPanePayload open_command_pane_in_place_payload = 42;
    RunCommandPayload run_command_payload = 43;
    WebRequestPayload web_request_payload = 44;
    string delete_dead_session_payload = 45;
    string rename_session_payload = 46;
    string unblock_cli_pipe_input_payload = 47;
    string block_cli_pipe_input_payload = 48;
    CliPipeOutputPayload cli_pipe_output_payload = 49;
    MessageToPluginPayload message_to_plugin_payload = 50;
    KillSessionsPayload kill_sessions_payload = 60;
    string scan_host_folder_payload = 61;
    NewTabsWithLayoutInfoPayload new_tabs_with_layout_info_payload = 62;
    ReconfigurePayload reconfigure_payload = 63;
    HidePaneWithIdPayload hide_pane_with_id_payload = 64;
    ShowPaneWithIdPayload show_pane_with_id_payload = 65;
    OpenCommandPanePayload open_command_pane_background_payload = 66;
    RerunCommandPanePayload rerun_command_pane_payload = 67;
    ResizePaneIdWithDirectionPayload resize_pane_id_with_direction_payload = 68;
    EditScrollbackForPaneWithIdPayload edit_scrollback_for_pane_with_id_payload = 69;
    WriteToPaneIdPayload write_to_pane_id_payload = 70;
    WriteCharsToPaneIdPayload write_chars_to_pane_id_payload = 71;
    MovePaneWithPaneIdPayload move_pane_with_pane_id_payload = 72;
    MovePaneWithPaneIdInDirectionPayload move_pane_with_pane_id_in_direction_payload = 73;
    ClearScreenForPaneIdPayload clear_screen_for_pane_id_payload = 74;
    ScrollUpInPaneIdPayload scroll_up_in_pane_id_payload = 75;
    ScrollDownInPaneIdPayload scroll_down_in_pane_id_payload = 76;
    ScrollToTopInPaneIdPayload scroll_to_top_in_pane_id_payload = 77;
    ScrollToBottomInPaneIdPayload scroll_to_bottom_in_pane_id_payload = 78;
    PageScrollUpInPaneIdPayload page_scroll_up_in_pane_id_payload = 79;
    PageScrollDownInPaneIdPayload page_scroll_down_in_pane_id_payload = 80;
    TogglePaneIdFullscreenPayload toggle_pane_id_fullscreen_payload = 81;
    TogglePaneEmbedOrEjectForPaneIdPayload toggle_pane_embed_or_eject_for_pane_id_payload = 82;
    CloseTabWithIndexPayload close_tab_with_index_payload = 83;
    BreakPanesToNewTabPayload break_panes_to_new_tab_payload = 84;
    BreakPanesToTabWithIndexPayload break_panes_to_tab_with_index_payload = 85;
    ReloadPluginPayload reload_plugin_payload = 86;
    LoadNewPluginPayload load_new_plugin_payload = 87;
    RebindKeysPayload rebind_keys_payload = 88;
    ChangeHostFolderPayload change_host_folder_payload = 89;
    SetFloatingPanePinnedPayload set_floating_pane_pinned_payload = 90;
    StackPanesPayload stack_panes_payload = 91;
    ChangeFloatingPanesCoordinatesPayload change_floating_panes_coordinates_payload = 92;
    OpenCommandPaneNearPluginPayload open_command_pane_near_plugin_payload = 93;
    OpenTerminalNearPluginPayload open_terminal_near_plugin_payload = 94;
    OpenTerminalFloatingNearPluginPayload open_terminal_floating_near_plugin_payload = 95;
    OpenTerminalInPlaceOfPluginPayload open_terminal_in_place_of_plugin_payload = 96;
    OpenCommandPaneFloatingNearPluginPayload open_command_pane_floating_near_plugin_payload = 97;
    OpenCommandPaneInPlaceOfPluginPayload open_command_pane_in_place_of_plugin_payload = 98;
    OpenFileNearPluginPayload open_file_near_plugin_payload = 99;
    OpenFileFloatingNearPluginPayload open_file_floating_near_plugin_payload = 100;
    OpenFileInPlaceOfPluginPayload open_file_in_place_of_plugin_payload = 101;
    GroupAndUngroupPanesPayload group_and_ungroup_panes_payload = 102;
    HighlightAndUnhighlightPanesPayload highlight_and_unhighlight_panes_payload = 103;
    CloseMultiplePanesPayload close_multiple_panes_payload = 104;
    FloatMultiplePanesPayload float_multiple_panes_payload = 105;
    EmbedMultiplePanesPayload embed_multiple_panes_payload = 106;
    SetSelfMouseSelectionSupportPayload set_self_mouse_selection_support_payload = 107;
    GenerateWebLoginTokenPayload generate_web_login_token_payload = 108;
    RevokeWebLoginTokenPayload revoke_web_login_token_payload = 109;
    RenameWebLoginTokenPayload rename_web_login_token_payload = 110;
    ReplacePaneWithExistingPanePayload replace_pane_with_existing_pane_payload = 111;
  }
}

message ReplacePaneWithExistingPanePayload {
  PaneId pane_id_to_replace = 1;
  PaneId existing_pane_id = 2;
}

message RenameWebLoginTokenPayload {
  string old_name = 1;
  string new_name = 2;
}

message RevokeWebLoginTokenPayload {
  string token_label = 1;
}

message GenerateWebLoginTokenPayload {
  optional string token_label = 1;
}

message SetSelfMouseSelectionSupportPayload {
  bool support_mouse_selection = 1;
}

message EmbedMultiplePanesPayload {
  repeated PaneId pane_ids = 1;
}

message FloatMultiplePanesPayload {
  repeated PaneId pane_ids = 1;
}

message CloseMultiplePanesPayload {
  repeated PaneId pane_ids = 1;
}

message HighlightAndUnhighlightPanesPayload {
  repeated PaneId pane_ids_to_highlight = 1;
  repeated PaneId pane_ids_to_unhighlight = 2;
}

message GroupAndUngroupPanesPayload {
  repeated PaneId pane_ids_to_group = 1;
  repeated PaneId pane_ids_to_ungroup = 2;
}

message OpenFileInPlaceOfPluginPayload {
  file.File file_to_open = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
  bool close_plugin_after_replace = 4;
}

message OpenFileFloatingNearPluginPayload {
  file.File file_to_open = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message OpenFileNearPluginPayload {
  file.File file_to_open = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message OpenCommandPaneInPlaceOfPluginPayload {
  command.Command command_to_run = 1;
  repeated ContextItem context = 3;
  bool close_plugin_after_replace = 4;
}

message OpenCommandPaneFloatingNearPluginPayload {
  command.Command command_to_run = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message OpenTerminalInPlaceOfPluginPayload {
  file.File file_to_open = 1;
  repeated ContextItem context = 3;
  bool close_plugin_after_replace = 4;
}

message OpenTerminalFloatingNearPluginPayload {
  file.File file_to_open = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message OpenTerminalNearPluginPayload {
  file.File file_to_open = 1;
  repeated ContextItem context = 3;
}

message OpenCommandPaneNearPluginPayload {
  command.Command command_to_run = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message ChangeFloatingPanesCoordinatesPayload {
  repeated PaneIdAndFloatingPaneCoordinates pane_ids_and_floating_panes_coordinates = 1;
}

message StackPanesPayload {
  repeated PaneId pane_ids = 1;
}

message SetFloatingPanePinnedPayload {
  PaneId pane_id = 1;
  bool should_be_pinned = 2;
}

message ChangeHostFolderPayload {
  string new_host_folder = 1;
}

message RebindKeysPayload {
  repeated KeyToRebind keys_to_rebind = 1;
  repeated KeyToUnbind keys_to_unbind = 2;
  bool write_config_to_disk = 3;
}

message KeyToRebind {
  input_mode.InputMode input_mode = 1;
  key.Key key = 2;
  repeated action.Action actions = 3;
}

message KeyToUnbind {
  input_mode.InputMode input_mode = 1;
  key.Key key = 2;
}

message LoadNewPluginPayload {
  string plugin_url = 1;
  repeated ContextItem plugin_config = 2;
  bool should_load_plugin_in_background = 3;
  bool should_skip_plugin_cache = 4;
}

message ReloadPluginPayload {
  uint32 plugin_id = 1;
}

message BreakPanesToTabWithIndexPayload {
  repeated PaneId pane_ids = 1;
  uint32 tab_index = 2;
  bool should_change_focus_to_target_tab = 3;
}

message BreakPanesToNewTabPayload {
  repeated PaneId pane_ids = 1;
  bool should_change_focus_to_new_tab = 2;
  optional string new_tab_name = 3;
}

message MovePaneWithPaneIdPayload {
  PaneId pane_id = 1;
}

message MovePaneWithPaneIdInDirectionPayload {
  PaneId pane_id = 1;
  resize.MoveDirection direction = 2;
}

message ClearScreenForPaneIdPayload {
  PaneId pane_id = 1;
}

message ScrollUpInPaneIdPayload {
  PaneId pane_id = 1;
}

message ScrollDownInPaneIdPayload {
  PaneId pane_id = 1;
}

message ScrollToTopInPaneIdPayload {
  PaneId pane_id = 1;
}

message ScrollToBottomInPaneIdPayload {
  PaneId pane_id = 1;
}

message PageScrollUpInPaneIdPayload {
  PaneId pane_id = 1;
}

message PageScrollDownInPaneIdPayload {
  PaneId pane_id = 1;
}

message TogglePaneIdFullscreenPayload {
  PaneId pane_id = 1;
}

message TogglePaneEmbedOrEjectForPaneIdPayload {
  PaneId pane_id = 1;
}

message CloseTabWithIndexPayload {
  uint32 tab_index = 1;
}

message WriteCharsToPaneIdPayload {
  string chars_to_write = 1;
  PaneId pane_id = 2;
}

message WriteToPaneIdPayload {
  bytes bytes_to_write = 1;
  PaneId pane_id = 2;
}

message EditScrollbackForPaneWithIdPayload {
  PaneId pane_id = 1;
}

message ResizePaneIdWithDirectionPayload {
  resize.Resize resize = 1;
  PaneId pane_id = 2;
}

message ReconfigurePayload {
  string config = 1;
  bool write_to_disk = 2;
}

message RerunCommandPanePayload {
  uint32 terminal_pane_id = 1;
}

message HidePaneWithIdPayload {
  PaneId pane_id = 1;
}

message ShowPaneWithIdPayload {
  PaneId pane_id = 1;
  bool should_float_if_hidden = 2;
}

message NewTabsWithLayoutInfoPayload {
  event.LayoutInfo layout_info = 1;
}

message KillSessionsPayload {
  repeated string session_names = 1;
}

message CliPipeOutputPayload {
  string pipe_name = 1;
  string output = 2;
}

message MessageToPluginPayload {
  optional string plugin_url = 1;
  repeated ContextItem plugin_config = 2;
  string message_name = 3;
  optional string message_payload = 4;
  repeated ContextItem message_args = 5;
  optional NewPluginArgs new_plugin_args = 6;
  optional uint32 destination_plugin_id = 7;
  optional FloatingPaneCoordinates floating_pane_coordinates = 8;
}

message NewPluginArgs {
    optional bool should_float = 1;
    optional PaneId pane_id_to_replace = 2;
    optional string pane_title = 3;
    optional string cwd = 4;
    bool skip_cache = 5;
}

message PaneId {
  PaneType pane_type = 1;
  uint32 id = 2;
}

enum PaneType {
  Terminal = 0;
  Plugin = 1;
}

message SwitchSessionPayload {
  optional string name = 1;
  optional uint32 tab_position = 2;
  optional uint32 pane_id = 3;
  optional bool pane_id_is_plugin = 4;
  optional event.LayoutInfo layout = 5;
  optional string cwd = 6;
}

message RequestPluginPermissionPayload {
  repeated plugin_permission.PermissionType permissions = 1;
}

message SubscribePayload {
  event.EventNameList subscriptions = 1;
}

message UnsubscribePayload {
  event.EventNameList subscriptions = 1;
}

message OpenFilePayload {
  file.File file_to_open = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message OpenCommandPanePayload {
  command.Command command_to_run = 1;
  optional FloatingPaneCoordinates floating_pane_coordinates = 2;
  repeated ContextItem context = 3;
}

message SwitchTabToPayload {
  uint32 tab_index = 1;
}

message SetTimeoutPayload {
  double seconds = 1;
}

message ExecCmdPayload {
  repeated string command_line = 1;
}

message RunCommandPayload {
  repeated string command_line = 1;
  repeated EnvVariable env_variables = 2;
  string cwd = 3;
  repeated ContextItem context = 4;
}

message WebRequestPayload {
  string url = 1;
  HttpVerb verb = 2;
  repeated event.Header headers = 3;
  bytes body = 4;
  repeated ContextItem context = 5;
}

enum HttpVerb {
  Get = 0;
  Post = 1;
  Put = 2;
  Delete = 3;
}

message EnvVariable {
  string name = 1;
  string value = 2;
}

message ContextItem {
  string name = 1;
  string value = 2;
}

message PluginMessagePayload {
  api.message.Message message = 1;
}

message ResizePayload {
  resize.Resize resize = 1;
}

message MovePayload {
  resize.MoveDirection direction = 1;
}

message PaneIdAndFloatingPaneCoordinates {
  PaneId pane_id = 1;
  FloatingPaneCoordinates floating_pane_coordinates = 2;
}

message IdAndNewName {
  uint32 id = 1; // pane id or tab index
  string new_name = 2;
}

message FloatingPaneCoordinates {
  optional FixedOrPercentValue x = 1;
  optional FixedOrPercentValue y = 2;
  optional FixedOrPercentValue width = 3;
  optional FixedOrPercentValue height = 4;
  optional bool pinned = 5;
}

message FixedOrPercentValue {
  FixedOrPercent type = 1;
  uint32 value = 2;
}

enum FixedOrPercent {
  Fixed = 0;
  Percent = 1;
}

message CreateTokenResponse {
  optional string token = 1;
  optional string token_label = 2;
  optional string error = 3;
}

message RevokeTokenResponse {
  bool successfully_revoked = 1;
  optional string error = 2;
}

message ListTokensResponse {
  // tokens/creation_times should be synchronized
  repeated string tokens = 1;
  repeated string creation_times = 2;
  optional string error = 3;
}

message RevokeAllWebTokensResponse {
  bool successfully_revoked = 1;
  optional string error = 2;
}

message RenameWebTokenResponse {
  bool successfully_renamed = 1;
  optional string error = 2;
}
