@@ -80,6 +80,7 @@ local display_floating_window = function(lines)
80
80
local editor_height = vim .api .nvim_get_option (" lines" )
81
81
local editor_width = vim .api .nvim_get_option (" columns" )
82
82
local win_height = math.min (math.floor (editor_height * 0.75 ), # lines )
83
+ win_height = math.max (win_height , 1 )
83
84
local longest_line_length = (function ()
84
85
local res = 0
85
86
for _ , line in ipairs (lines ) do
@@ -89,9 +90,9 @@ local display_floating_window = function(lines)
89
90
end )()
90
91
local win_width =
91
92
math.min (math.floor (editor_width * 0.75 ), longest_line_length )
93
+ win_width = math.max (win_width , 1 )
92
94
local row = math.floor ((editor_height - win_height ) / 2 )
93
95
local col = math.floor ((editor_width - win_width ) / 2 )
94
-
95
96
local win = vim .api .nvim_open_win (buf_id , true , {
96
97
relative = " editor" ,
97
98
width = win_width ,
@@ -105,9 +106,22 @@ local display_floating_window = function(lines)
105
106
return nil , " Failed to open floating window."
106
107
end
107
108
vim .api .nvim_buf_set_option (buf_id , " modifiable" , false )
109
+ vim .api .nvim_buf_set_option (buf_id , " modified" , false )
110
+
111
+ vim .api .nvim_create_augroup (
112
+ " CrazywallCloseBufferOnWindowClose" ,
113
+ { clear = true }
114
+ )
108
115
109
- local default_bg = vim .api .nvim_get_hl (0 , { name = ' Normal' }).background
110
- vim .api .nvim_set_hl (0 , ' NormalFloat' , { bg = default_bg })
116
+ vim .api .nvim_create_autocmd (" WinLeave" , {
117
+ group = " CrazywallCloseBufferOnWindowClose" ,
118
+ pattern = " *" ,
119
+ callback = function ()
120
+ if vim .fn .bufnr (" %" ) == buf_id then
121
+ vim .cmd (' b#|bwipeout! ' .. buf_id )
122
+ end
123
+ end ,
124
+ })
111
125
112
126
return buf_id
113
127
end
@@ -266,7 +280,7 @@ end, {
266
280
end
267
281
return {}
268
282
end ,
269
- desc = " Folds a file with crazywall , skipping the confirmation window." ,
283
+ desc = " Applies crazywall to a file , skipping the confirmation window." ,
270
284
})
271
285
272
286
vim .api .nvim_create_user_command (" CrazywallDry" , function (opts )
@@ -308,10 +322,10 @@ vim.api.nvim_create_user_command("CrazywallDry", function(opts)
308
322
nil ,
309
323
true ,
310
324
false ,
311
- (output_style == " plan-only " or output_style == " both" )
325
+ (output_style == " planonly " or output_style == " both" )
312
326
and streams .STDOUT
313
327
or streams .NONE ,
314
- (output_style == " text-only " or output_style == " both" )
328
+ (output_style == " textonly " or output_style == " both" )
315
329
and streams .STDOUT
316
330
or streams .NONE ,
317
331
true ,
@@ -328,13 +342,29 @@ vim.api.nvim_create_user_command("CrazywallDry", function(opts)
328
342
return display_err (err )
329
343
end
330
344
331
- _ , err =
332
- display_floating_window (utils .str .split_lines_to_list (tostring (plan )))
345
+ local text = {}
346
+ if output_style == " planonly" or output_style == " both" then
347
+ table.insert (text , " Plan (dry-run):" )
348
+ for line in utils .str .split_lines (tostring (plan )) do
349
+ table.insert (text , line )
350
+ end
351
+ end
352
+ if output_style == " textonly" or output_style == " both" then
353
+ if # text ~= 0 then
354
+ table.insert (text , " " )
355
+ end
356
+ table.insert (text , " Text (dry-run):" )
357
+ for line in utils .str .split_lines (utils .str .join_lines (ctx .lines )) do
358
+ table.insert (text , line )
359
+ end
360
+ end
361
+
362
+ _ , err = display_floating_window (text )
333
363
if err then
334
364
return nil , err
335
365
end
336
366
337
- vim .cmd (' setlocal nowrap' )
367
+ vim .cmd (" setlocal nowrap" )
338
368
end , {
339
369
nargs = " *" ,
340
370
complete = function (_ , line )
@@ -353,7 +383,7 @@ end, {
353
383
end
354
384
return {}
355
385
end ,
356
- desc = " Folds a file with crazywall , skipping the confirmation window." ,
386
+ desc = " Applies crazywall to a file , skipping the confirmation window." ,
357
387
})
358
388
359
389
M .setup = function (opts )
@@ -370,6 +400,4 @@ M.setup = function(opts)
370
400
current_config_name = opts .default_config_name or current_config_name
371
401
end
372
402
373
- M .foo = 42
374
-
375
403
return M
0 commit comments