foxygit / Hush Log in
commits tags

/src/app_mode.h · 1.82 KB

raw
#ifndef HUSH_APP_MODE_H
#define HUSH_APP_MODE_H

#include <stdbool.h>

/* Presentation/flow state -- deliberately kept out of EditorState, which is document-editing
   state. Threaded through main.c's loop and into render_frame alongside the other per-frame
   values (e.g. caretBlinkT) it already passes explicitly. */
typedef enum {
    MODE_EDITING,
    MODE_QUIT_CONFIRM,
    MODE_SHORTCUTS_HELP,
    MODE_SOURCE_VIEW, /* read-only raw-markdown preview, toggled with Ctrl+M */
    MODE_OPEN_PROMPT, /* typed-path "open a file" modal, toggled with Ctrl+O */
} AppMode;

typedef enum {
    MODAL_ACTION_NONE,
    MODAL_ACTION_SAVE_QUIT,
    MODAL_ACTION_DISCARD_QUIT,
    MODAL_ACTION_CANCEL,
    MODAL_ACTION_CLOSE_HELP,
    MODAL_ACTION_OPEN_CONFIRM,
} ModalAction;

/* MODE_OPEN_PROMPT's typed path, owned by main.c and read by render.c to draw the text field. */
typedef struct {
    char path[512];
    int len;
    bool showError; /* true if the last attempt to open `path` failed */
} OpenPromptState;

/* The left-margin "Turn Into" popup, anchored to ed->cursorBlock. Owned by main.c. */
typedef struct {
    bool open;
} TurnIntoMenuState;

/* The "@" quick-insert popup. `selectedIndex` indexes into the *filtered* row list (i.e. after
   skipping items block_type_menu_item_matches rejects), not BLOCK_TYPE_MENU_ITEMS directly.
   Owned by main.c. */
typedef struct {
    bool open;
    int selectedIndex;
} QuickInsertMenuState;

/* Out-params render_frame fills in for whichever block-type menu(s) the frame's click landed
   on; -1 means "no click this frame" for the BlockType-typed fields. */
typedef struct {
    int quickInsertClickedType;   /* BlockType cast to int, or -1 */
    bool turnIntoIconClicked;
    int turnIntoClickedType;      /* BlockType cast to int, or -1 */
    bool turnIntoClickedOutside;
} BlockTypeMenuClickResult;

#endif