Skip to content

Commit

Permalink
Add docs for condense_callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisant996 committed Apr 15, 2023
1 parent 24c8002 commit 4d768fa
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,33 @@ end
flexprompt.add_module("mfm", my_first_module)
```

## Abbreviation When Too Wide

Prompt modules can optionally return a callback function for use in case the
terminal is not wide enough for the full prompt to be displayed. If the prompt
is too wide, flexprompt calls each module's callback function to get an
abbreviated form of the module and uses that instead to help the prompt fit.

To provide a callback function, the prompt module should return a table with a
`condense_callback` field:

```lua
return {
-- Normal results; text and colors.
"full module text here",
"green",
"black",
-- Callback when short form is needed.
condense_callback = function ()
return {
"mini text",
"green",
"black",
}
end
}
```

## Async Prompt Filtering

Clink supports asynchronous prompt filtering, where the input line editor stays
Expand Down Expand Up @@ -555,7 +582,7 @@ local function collect_files_info()
end
```

## Step Two -- Make it collect the info asynchronously
### Step Two -- Make it collect the info asynchronously

Make a module that calls `flexprompt.prompt_info()`. We'll discuss the middle
two parameters later -- they can be empty strings if you don't need them.
Expand All @@ -582,7 +609,7 @@ end
flexprompt.add_module("files", files_module)
```

## Step Three -- [Optional] Maybe reset the cached prompt info
### Step Three -- [Optional] Maybe reset the cached prompt info

Async prompt filtering shows the previous prompt content until the async
collection function finishes.
Expand Down

0 comments on commit 4d768fa

Please sign in to comment.