restman-0.7.7.0: Web request TUI program.
Safe HaskellNone
LanguageGHC2024

Lib

Description

For the data inclined, start with AppS in Types, which holds all internal RESTman state. For the logic inclined, start with handleEvent, which is the main entry point for state changes over time. startUI in UI is responsible for building the App record and wiring everything together.

Synopsis

Documentation

chooseCursor :: AppS -> [CursorLocation AppR] -> Maybe (CursorLocation AppR) Source #

Where to place the cursor? If overlay present, no cursor. Otherwise determined by focus

cleanPayload :: ByteString -> Text Source #

Sanitise a lazy ByteString response body for display in Vty.

Decodes to Text with lenient UTF-8 decoding, then:

  • Strips ESC (\ESC) and vertical-tab (\v) characters which would corrupt Vty output.
  • Expands tab characters to four spaces.

draw :: AppS -> [Widget AppR] Source #

Render.

Widget names are all AppR.

URL editor and label, then last response body at the top of the available space. No other widgets or layers.

focusAttr :: Attr -> Attr Source #

Apply focusStyle to the style component of an Attr, setting it explicitly if it was Default or KeepCurrent.

focusStyle :: Style -> Style Source #

Toggle the reverseVideo bit in a Style to indicate keyboard focus.

growWith Source #

Arguments

:: (Int -> Int -> Image)

How to generate wide by vert padding image

-> Int

minimum width

-> WideAlign

width-wise ("horizontal") alignment

-> Int

minimum vert ("height")

-> VertAlign

vertical alignment

-> Image

original, small image

-> Image

resulting, grown image

Grows an image to a minimum size by padding it, with original images being aligned as specified within the larger image.

handleEvent :: BrickEvent AppR Void -> EventM AppR AppS () Source #

State update in response to event.

Widget names are all Text. No application specific events, so event type is Void.

Global events handled here: * [Esc] (with any or no modifiers) and Ctrl+q (with any or no other modifiers) halts. * No application events are expected. * Mouse events are ignored.

Other Vty events are passed to handleEventLocal.

doRequest :: AppS -> IO AppS Source #

Construct and issue a wreq request from the application state, handle request failures that are raised as exceptions in IO, updating the application state (lastResponse) either from the response or the execption.

lbsToText :: ByteString -> Text Source #

Decode a lazy ByteString to strict Text using lenient UTF-8 decoding.

moveFocusNext :: AppS -> AppS Source #

App state change on [Tab] to advace the focus.

moveFocusPrev :: AppS -> AppS Source #

App state change on [S+Tab] to recede the focus

noSyntaxFound :: Text -> Image Source #

Render pre-cleaned Text as a plain (unsyntaxed) Vty Image, one line per row.

Used when no matching Syntax can be found for the response content type.

splitExtraSpace :: RangeInAlign -> Int -> (Int, Int) Source #

Second argument must be positive.

syntaxHighlightResponse :: Maybe ByteString -> Maybe ByteString -> Image Source #

Render an HTTP response body (or an empty-body signal) as a Vty Image with optional syntax highlighting based on the Content-Type header.

The incoming payload ByteString is passed through cleanPayload before rendering to strip characters that are incompatible with Vty's text rendering (e.g. ESC, vertical tab). Newlines are preserved — they are the line delimiters used by Vty's vertCat.

  • If the body is Nothing, a placeholder "-- No response body --" line is returned.
  • If no Content-Type is present, noSyntaxFound is used.
  • Otherwise the MIME type is looked up in the default extension map and the first matching skylighting Syntax is used by highlighted.