-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable window width, and possibility to hide the terminal window #6
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,41 @@ M.close = function() | |
end | ||
end | ||
|
||
-- Calculate the window width based on parent window and | ||
-- configuration. Numbers between 0 and 1 are interpreted | ||
-- as a percentage. | ||
local function get_window_size(config) | ||
local win_width = 0.5 | ||
|
||
local parent_width = vim.api.nvim_win_get_width(0) | ||
if config.windows.width > 1 then | ||
win_width = config.windows.width | ||
end | ||
|
||
if config.windows.width < 1 then | ||
win_width = math.floor(parent_width * config.windows.width) | ||
end | ||
|
||
if config.windows.width == 1 then | ||
win_width = parent_width | ||
end | ||
|
||
return win_width | ||
end | ||
Comment on lines
+41
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you extract this function to a new file? Could be a |
||
|
||
-- If the window should be 100% width, we have already hidden | ||
-- the terminal and should split below. If the terminal window | ||
-- is open we should split to the right of it. | ||
local function get_window_split(config) | ||
local split = "right" | ||
|
||
if config.windows.width == 1 then | ||
split = "below" | ||
end | ||
|
||
return split | ||
end | ||
|
||
M.open = function() | ||
M.close() | ||
|
||
|
@@ -59,9 +94,10 @@ M.open = function() | |
local config = setup.config | ||
|
||
local winnr = api.nvim_open_win(bufnr, false, { | ||
split = "right", | ||
split = get_window_split(config), | ||
win = term_winnr, | ||
height = config.windows.height, | ||
width = get_window_size(config), | ||
}) | ||
|
||
assert(winnr ~= 0, "Failed to create dap-view window") | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ local M = {} | |||||
|
||||||
---@class WindowsConfig | ||||||
---@field height integer | ||||||
---@field width number|integer Width of the window in either characters or percentage (as decimal: 0.75). Window size of 1 means 100% width, which will hide the terminal window. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
--- @alias SectionType '"breakpoints"' | '"exceptions"' | '"watches"' | '"repl"' | ||||||
|
||||||
|
@@ -22,6 +23,7 @@ M.config = { | |||||
}, | ||||||
windows = { | ||||||
height = 12, | ||||||
width = 0.5, | ||||||
}, | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,10 @@ M.term_buf_win_init = function() | |
|
||
util_buf.quit_buf_autocmd(state.term_bufnr, M.close_term_buf_win) | ||
|
||
if config.windows.width == 1 then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the latest main, what we would do instead is add (yet) another condition to the if that spawns the window. |
||
vim.api.nvim_win_hide(state.term_winnr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanna make a more throughout review later, but have you tested this with adapters other than |
||
end | ||
|
||
dap.defaults.fallback.terminal_win_cmd = function() | ||
return state.term_bufnr, state.term_winnr | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, can you add a type annotation for the param here?