-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathrun-logger.lua
More file actions
57 lines (45 loc) · 1.27 KB
/
run-logger.lua
File metadata and controls
57 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local class = require('java-core.utils.class')
---@class java.RunLogger
---@field window number
local RunLogger = class()
function RunLogger:_init()
self.window = -1
end
---Opens the log window with the given run buffer
---@param buffer number
function RunLogger:create(buffer)
vim.cmd('sp | winc J | res 15 | buffer ' .. buffer)
self.window = vim.api.nvim_get_current_win()
vim.wo[self.window].number = false
vim.wo[self.window].relativenumber = false
vim.wo[self.window].signcolumn = 'no'
self:scroll_to_bottom()
end
function RunLogger:set_buffer(buffer)
if self:is_opened() then
vim.api.nvim_win_set_buf(self.window, buffer)
else
self:create(buffer)
end
self:scroll_to_bottom()
end
function RunLogger:scroll_to_bottom()
local buffer = vim.api.nvim_win_get_buf(self.window)
local line_count = vim.api.nvim_buf_line_count(buffer)
vim.api.nvim_win_set_cursor(self.window, { line_count, 0 })
end
---Returns true if the log window is opened
---@return boolean
function RunLogger:is_opened()
if not self.window then
return false
end
return vim.api.nvim_win_is_valid(self.window)
end
---Closes the log window if opened
function RunLogger:close()
if self.window and vim.api.nvim_win_is_valid(self.window) then
vim.api.nvim_win_hide(self.window)
end
end
return RunLogger