|
34 | 34 | ---@param fit? boolean Optional parameter to control line fitting |
35 | 35 | ---@return number index The index of the added line |
36 | 36 | function Output:add_line(line, fit) |
37 | | - local win_width = state.windows and vim.api.nvim_win_get_width(state.windows.output_win) or config.ui.window_width |
38 | | - if fit and #line > win_width then |
39 | | - line = vim.fn.strcharpart(line, 0, win_width - 7) .. '...' |
40 | | - end |
41 | 37 | table.insert(self.lines, line) |
42 | 38 | return #self.lines |
43 | 39 | end |
|
63 | 59 | ---@param prefix? string Optional prefix for each line |
64 | 60 | function Output:add_lines(lines, prefix) |
65 | 61 | for _, line in ipairs(lines) do |
66 | | - prefix = prefix or '' |
67 | | - |
68 | 62 | if line == '' then |
69 | | - self:add_empty_line() |
| 63 | + table.insert(self.lines, '') |
70 | 64 | else |
71 | | - self:add_line(prefix .. line) |
| 65 | + prefix = prefix or '' |
| 66 | + table.insert(self.lines, prefix .. line) |
72 | 67 | end |
73 | 68 | end |
74 | 69 | end |
75 | 70 |
|
76 | 71 | ---Add an empty line if the last line is not empty |
77 | 72 | ---@return number? index The index of the added line, or nil if no line was added |
78 | 73 | function Output:add_empty_line() |
79 | | - local last_line = self.lines[#self.lines] |
80 | | - if not last_line or last_line ~= '' then |
81 | | - return self:add_line('') |
| 74 | + local line_count = #self.lines |
| 75 | + if line_count == 0 or self.lines[line_count] ~= '' then |
| 76 | + table.insert(self.lines, '') |
| 77 | + return line_count + 1 |
82 | 78 | end |
83 | 79 | return nil |
84 | 80 | end |
|
0 commit comments