diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-01-03 12:22:13 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2022-03-05 16:51:59 +0000 |
commit | 30e4cc3b3f2133e9a7170da9da8175832681f39a (patch) | |
tree | 76cca17f4b3389246743afc5febaeb11deeb20b1 /src/nvim/api/private/helpers.c | |
parent | 83fc914337100d03f2e41a3943ccf0107d893698 (diff) | |
download | rneovim-30e4cc3b3f2133e9a7170da9da8175832681f39a.tar.gz rneovim-30e4cc3b3f2133e9a7170da9da8175832681f39a.tar.bz2 rneovim-30e4cc3b3f2133e9a7170da9da8175832681f39a.zip |
feat(decorations): support signs
Add the following options to extmarks:
- sign_text
- sign_hl_group
- number_hl_group
- line_hl_group
- cursorline_hl_group
Note: ranges are unsupported and decorations are only applied to
start_row
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 35e8589255..8056950e26 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1643,3 +1643,39 @@ sctx_T api_set_sctx(uint64_t channel_id) } return old_current_sctx; } + +// adapted from sign.c:sign_define_init_text. +// TODO(lewis6991): Consider merging +int init_sign_text(char_u **sign_text, char_u *text) +{ + char_u *s; + + char_u *endp = text + (int)STRLEN(text); + + // Count cells and check for non-printable chars + int cells = 0; + for (s = text; s < endp; s += utfc_ptr2len(s)) { + if (!vim_isprintc(utf_ptr2char(s))) { + break; + } + cells += utf_ptr2cells(s); + } + // Currently must be empty, one or two display cells + if (s != endp || cells > 2) { + return FAIL; + } + if (cells < 1) { + return OK; + } + + // Allocate one byte more if we need to pad up + // with a space. + size_t len = (size_t)(endp - text + ((cells == 1) ? 1 : 0)); + *sign_text = vim_strnsave(text, len); + + if (cells == 1) { + STRCPY(*sign_text + len - 1, " "); + } + + return OK; +} |