v0.1.2

Internal Packages

Last updated


This page documents the exported types and functions of internal/ui and internal/parser for anyone modifying or extending the source; both live under internal/ and cannot be imported from other modules.

internal/ui


TUI


  1. type TUI struct {
  2. App *tview.Application
  3. Pages *tview.Pages
  4. LeftView *tview.List
  5. RightView *tview.TextView
  6. HintView *tview.TextView
  7. Watcher *fsnotify.Watcher
  8. Filepath string
  9. Requests []*Request
  10. Mu sync.RWMutex
  11. }

FieldDescription
AppThe tview application; response rendering and hint updates from background goroutines go through App.QueueUpdateDraw
PagesCreated but never added to the layout; currently unused
LeftViewRequest list (API pane)
RightViewRequest preview and response (Info pane)
HintViewOne-row hint bar at the bottom
Watcherfsnotify watcher assigned by main
FilepathPath of the loaded .http file, set by parser.ReadFile
RequestsParse result; hold Mu when reading or writing
MuRead-write lock guarding Requests

Request


  1. type Request struct {
  2. Name string
  3. Method string
  4. URL string
  5. Headers map[string]string
  6. Body string
  7. }

The parse result of one .http request block; the last entry wins for duplicate Headers keys.

Functions and Methods


SymbolSignatureDescription
NewTUIfunc NewTUI() *TUIBuilds the two-pane layout and hint bar and registers global keys (<kbd>Tab</kbd>, <kbd>←</kbd>, <kbd>→</kbd>, <kbd>Ctrl+C</kbd>, <kbd>Esc</kbd>)
UpdateLeftViewfunc (t *TUI) UpdateLeftView()Rebuilds the list from Requests, binds <kbd>Enter</kbd> to send and cursor moves to preview, and previews the first request

internal/parser


SymbolSignatureDescription
ReadFilefunc ReadFile(t *ui.TUI, path string) ([]*ui.Request, error)Sets t.Filepath, parses the whole file, writes t.Requests under Mu, and calls UpdateLeftView on the calling goroutine; returns a wrapped error when opening or reading fails, leaving t.Requests unchanged
WatchFilefunc WatchFile(t *ui.TUI)Reads events and errors from t.Watcher until the channels close; fsnotify.Write/fsnotify.Create call ReloadFile after a 200ms debounce
ReloadFilefunc ReloadFile(t *ui.TUI)Shows Edited at, re-parses t.Filepath with ReadFile, then in the event loop sets the cursor to the list's current index (0 after the rebuild) and shows Reloaded at; on failure shows the error in red

See .http File Format for syntax and Hot Reload for reload behavior.
中文