Skip to content

Commit

Permalink
add the ability to choose to turn off the border
Browse files Browse the repository at this point in the history
  • Loading branch information
huynle committed Feb 3, 2024
1 parent 07a6bcc commit 8649ddc
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 10 deletions.
53 changes: 53 additions & 0 deletions lua/ogpt/common/layout.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local NuiLayout = require("nui.layout")

Popup = NuiLayout:extend("OgptLayout")

function Popup:init(options, box)
Popup.super.init(self, options, box)
end

function Popup:mount()
-- self._.type = ""
Popup.super.mount(self)
-- if self._.loading or self._.mounted then
-- return
-- end
--
-- self._.loading = true
--
-- local type = self._.type
--
-- if type == "float" then
-- local info = self._.float
--
-- local container = info.container
-- if is_component(container) and not is_component_mounted(container) then
-- container:mount()
-- self:update(get_layout_config_relative_to_component(container))
-- end
--
-- if not self.bufnr then
-- self.bufnr = vim.api.nvim_create_buf(false, true)
-- assert(self.bufnr, "failed to create buffer")
-- end
--
-- self:_open_window()
-- end
--
-- self:_process_layout()
--
-- if type == "float" then
-- float_layout.mount_box(self._.box)
--
-- apply_workaround_for_float_relative_position_issue_18925(self)
-- end
--
-- if type == "split" then
-- split_layout.mount_box(self._.box)
-- end
--
-- self._.loading = false
-- self._.mounted = true
end

return Popup
13 changes: 13 additions & 0 deletions lua/ogpt/common/popup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local NuiPopup = require("nui.popup")
local Config = require("ogpt.config")

Popup = NuiPopup:extend("OgptPopup")

function Popup:init(options)
if Config.options.chat.edgy and options.border then
options.border = nil
end
Popup.super.init(self, options)
end

return Popup
3 changes: 2 additions & 1 deletion lua/ogpt/common/popup_window.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local Config = require("ogpt.config")
local event = require("nui.utils.autocmd").event
local Utils = require("ogpt.utils")
Expand Down Expand Up @@ -78,6 +78,7 @@ end
function PopupWindow:mount(opts)
opts = vim.tbl_extend("force", self.options, opts or {})
PopupWindow.super.mount(self)
self.border:unmount()

self:update_popup_size(opts)

Expand Down
2 changes: 2 additions & 0 deletions lua/ogpt/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function M.defaults()
cycle_windows = "<Tab>",
use_output_as_input = "<C-u>",
},
edgy = false,
},
popup = {
position = 1,
Expand Down Expand Up @@ -168,6 +169,7 @@ function M.defaults()
border_left_sign = "|",
border_right_sign = "|",
max_line_length = 120,
edgy = true,
sessions_window = {
active_sign = " 󰄵 ",
inactive_sign = " 󰄱 ",
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/flows/actions/completions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function CompletionAction:on_result(answer, usage)
if self.strategy ~= STRATEGY_DISPLAY then
vim.api.nvim_buf_set_text(bufnr, start_row - 1, start_col - 1, end_row - 1, end_col, lines)
else
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local ui = vim.tbl_deep_extend("keep", self.ui, {
position = 1,
size = {
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/flows/actions/edits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local utils = require("ogpt.utils")
local Config = require("ogpt.config")
local Layout = require("nui.layout")
local Split = require("nui.split")
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local ChatInput = require("ogpt.input")
local Parameters = require("ogpt.parameters")

Expand Down
8 changes: 6 additions & 2 deletions lua/ogpt/flows/chat/base.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local Object = require("ogpt.common.object")
local Layout = require("nui.layout")
local Popup = require("nui.popup")
local Layout = require("ogpt.common.layout")
local Popup = require("ogpt.common.popup")

local ChatInput = require("ogpt.input")
local Config = require("ogpt.config")
Expand Down Expand Up @@ -743,6 +743,10 @@ function Chat:open()

-- initialize
self.layout:mount()
if Config.options.chat.edgy then
-- self.layout:hide()
-- self.layout:_close_window()
end
self:welcome()
self:set_events()
end
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/flows/chat/sessions.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}
M.vts = {}

local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local Config = require("ogpt.config")
local Session = require("ogpt.flows.chat.session")
local Utils = require("ogpt.utils")
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/flows/chat/system_window.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local Config = require("ogpt.config")

local SystemWindow = Popup:extend("SystemWindow")
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/flows/code_completions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ M.complete = function()
},
}, function(answer, usage)
set_loading(false)
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
answer = M.extract_snippet(answer)

local lines = Utils.split_string_by_line(answer)
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/input.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local Text = require("nui.text")
local defaults = require("nui.utils").defaults
local is_type = require("nui.utils").is_type
Expand Down
2 changes: 1 addition & 1 deletion lua/ogpt/parameters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local action_state = require("telescope.actions.state")
local M = {}
M.vts = {}

local Popup = require("nui.popup")
local Popup = require("ogpt.common.popup")
local Config = require("ogpt.config")

local namespace_id = vim.api.nvim_create_namespace("OGPTNS")
Expand Down

0 comments on commit 8649ddc

Please sign in to comment.