diff --git a/nvim/api.go b/nvim/api.go index ab75dee5..69ef3956 100644 --- a/nvim/api.go +++ b/nvim/api.go @@ -921,6 +921,50 @@ func (b *Batch) CreateBuffer(listed bool, scratch bool, buffer *Buffer) { b.call("nvim_create_buf", buffer, listed, scratch) } +// OpenTerm opens a terminal instance in a buffer. +// +// By default (and currently the only option) the terminal will not be +// connected to an external process. Instead, input send on the channel +// will be echoed directly by the terminal. This is useful to disply +// ANSI terminal sequences returned as part of a rpc message, or similar. +// +// Note: to directly initiate the terminal using the right size, display the +// buffer in a configured window before calling this. For instance, for a +// floating display, first create an empty buffer using CreateBuffer, +// then display it using OpenWindow, and then call this function. +// Then "nvim_chan_send" cal be called immediately to process sequences +// in a virtual terminal having the intended size. +// +// The buffer arg is the buffer to use (expected to be empty). +// +// The opts arg is optional parameters. Reserved for future use. +func (v *Nvim) OpenTerm(buffer Buffer, opts map[string]interface{}) (int, error) { + var result int + err := v.call("nvim_open_term", &result, buffer, opts) + return result, err +} + +// OpenTerm opens a terminal instance in a buffer. +// +// By default (and currently the only option) the terminal will not be +// connected to an external process. Instead, input send on the channel +// will be echoed directly by the terminal. This is useful to disply +// ANSI terminal sequences returned as part of a rpc message, or similar. +// +// Note: to directly initiate the terminal using the right size, display the +// buffer in a configured window before calling this. For instance, for a +// floating display, first create an empty buffer using CreateBuffer, +// then display it using OpenWindow, and then call this function. +// Then "nvim_chan_send" cal be called immediately to process sequences +// in a virtual terminal having the intended size. +// +// The buffer arg is the buffer to use (expected to be empty). +// +// The opts arg is optional parameters. Reserved for future use. +func (b *Batch) OpenTerm(buffer Buffer, opts map[string]interface{}, result *int) { + b.call("nvim_open_term", result, buffer, opts) +} + // OpenWindow open a new window. // // Currently this is used to open floating and external windows. @@ -2611,6 +2655,26 @@ func (b *Batch) WindowConfig(window Window, config *WindowConfig) { b.call("nvim_win_get_config", config, window) } +// HideWindow closes the window and hide the buffer it contains (like ":hide" with a +// windowID). +// +// Like ":hide" the buffer becomes hidden unless another window is editing it, +// or "bufhidden" is "unload", "delete" or "wipe" as opposed to ":close" or +// CloseWindow, which will close the buffer. +func (v *Nvim) HideWindow(window Window) error { + return v.call("nvim_win_hide", nil, window) +} + +// HideWindow closes the window and hide the buffer it contains (like ":hide" with a +// windowID). +// +// Like ":hide" the buffer becomes hidden unless another window is editing it, +// or "bufhidden" is "unload", "delete" or "wipe" as opposed to ":close" or +// CloseWindow, which will close the buffer. +func (b *Batch) HideWindow(window Window) { + b.call("nvim_win_hide", nil, window) +} + // CloseWindow close a window. // // This is equivalent to |:close| with count except that it takes a window id. diff --git a/nvim/api_def.go b/nvim/api_def.go index c108f81b..d0267c26 100644 --- a/nvim/api_def.go +++ b/nvim/api_def.go @@ -178,20 +178,6 @@ func Eval(expr string) (result interface{}) { name(nvim_eval) } -// Notify the user with a message. -// -// Relays the call to vim.notify. By default forwards your message in the -// echo area but can be overriden to trigger desktop notifications. -// -// The msg arg is message to display to the user. -// -// The logLevel arg is the log level. -// -// The opts arg is reserved for future use. -func Notify(msg string, logLevel int, opts map[string]interface{}) (result interface{}) { - name(nvim_notify) -} - // StringWidth calculates the number of display cells occupied by `text`. // // counts as one cell. diff --git a/nvim/api_tool.go b/nvim/api_tool.go index 99ebf4a2..da6bfaa3 100644 --- a/nvim/api_tool.go +++ b/nvim/api_tool.go @@ -420,6 +420,7 @@ var specialAPIs = map[string]bool{ "nvim_exec_lua": true, "nvim_buf_call": true, "nvim_set_decoration_provider": true, + "nvim_notify": true, // implements underling nlua(vim.notify) "nvim_chan_send": true, // FUNC_API_LUA_ONLY } diff --git a/nvim/nvim.go b/nvim/nvim.go index 1ae066fc..286b7be8 100644 --- a/nvim/nvim.go +++ b/nvim/nvim.go @@ -673,6 +673,48 @@ func (b *Batch) ExecuteLua(code string, result interface{}, args ...interface{}) b.call("nvim_execute_lua", result, code, args) } +// Notify the user with a message. +// +// Relays the call to vim.notify. By default forwards your message in the +// echo area but can be overriden to trigger desktop notifications. +// +// The msg arg is message to display to the user. +// +// The logLevel arg is the LogLevel. +// +// The opts arg is reserved for future use. +func (v *Nvim) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) error { + if logLevel == ErrorLevel { + return v.WritelnErr(msg) + } + + chunks := []TextChunk{ + Text: msg, + } + return v.Echo(chunks, true, opts) +} + +// Notify the user with a message. +// +// Relays the call to vim.notify. By default forwards your message in the +// echo area but can be overriden to trigger desktop notifications. +// +// The msg arg is message to display to the user. +// +// The logLevel arg is the LogLevel. +// +// The opts arg is reserved for future use. +func (b *Batch) Notify(msg string, logLevel LogLevel, opts map[string]interface{}) { + if logLevel == ErrorLevel { + return b.WritelnErr(msg) + } + + chunks := []TextChunk{ + Text: msg, + } + return b.Echo(chunks, true, opts) +} + // decodeExt decodes a MsgPack encoded number to go int value. func decodeExt(p []byte) (int, error) { switch { diff --git a/nvim/types.go b/nvim/types.go index d5608613..86e24dc9 100644 --- a/nvim/types.go +++ b/nvim/types.go @@ -553,3 +553,16 @@ type OptionInfo struct { // FlagList whether the list of single char flags. FlagList bool `msgpack:"flaglist"` } + +// LogLevel represents a nvim log level. +type LogLevel int + +// list of LogLevels. +// +const ( + TraceLevel LogLevel = iota + DebugLevel + InfoLevel + WarnLevel + ErrorLevel +)