mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-06-13 16:25:04 +00:00
csvview: init
This commit is contained in:
parent
7783ca61b7
commit
6f6b34a0b9
6 changed files with 153 additions and 0 deletions
50
modules/plugins/utility/csvview/config.nix
Normal file
50
modules/plugins/utility/csvview/config.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
options,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.nvim.binds) mkKeymap;
|
||||
|
||||
cfg = config.vim.utility.csvview;
|
||||
|
||||
keys = cfg.mappings;
|
||||
inherit (options.vim.utility.csvview) mappings;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim = {
|
||||
lazy.plugins.csvview-nvim = {
|
||||
package = "csvview-nvim";
|
||||
setupModule = "csvview";
|
||||
inherit (cfg) setupOpts;
|
||||
|
||||
cmd = ["CsvViewEnable" "CsvViewDisable" "CsvViewToggle" "CsvViewInfo"];
|
||||
|
||||
keys = [
|
||||
(mkKeymap "n" keys.toggle "<cmd>CsvViewToggle<CR>" {desc = mappings.toggle.description;})
|
||||
];
|
||||
};
|
||||
|
||||
# csvview.nvim has no built-in auto-enable, so drive it with a FileType
|
||||
# autocommand. The `is_enabled` guard keeps this idempotent so
|
||||
# re-firing FileType (e.g. `:e!`, `:set ft=csv`) doesn't warn about an
|
||||
# already-attached buffer.
|
||||
autocmds = mkIf cfg.autoEnable [
|
||||
{
|
||||
event = ["FileType"];
|
||||
pattern = ["csv" "tsv"];
|
||||
callback = mkLuaInline ''
|
||||
function(args)
|
||||
if not require("csvview").is_enabled(args.buf) then
|
||||
require("csvview").enable()
|
||||
end
|
||||
end
|
||||
'';
|
||||
desc = "Automatically enable CSV view for CSV/TSV files";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
80
modules/plugins/utility/csvview/csvview.nix
Normal file
80
modules/plugins/utility/csvview/csvview.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.types) bool int str listOf enum;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption;
|
||||
inherit (config.vim.lib) mkMappingOption;
|
||||
in {
|
||||
options.vim.utility.csvview = {
|
||||
enable = mkEnableOption "View CSV/TSV files as aligned tables [csvview.nvim]";
|
||||
|
||||
autoEnable =
|
||||
mkEnableOption ''
|
||||
Automatically enable the CSV view when opening CSV/TSV files.
|
||||
''
|
||||
// {default = true;};
|
||||
|
||||
mappings = {
|
||||
toggle = mkMappingOption "Toggle CSV view [csvview]" "<leader>tc";
|
||||
};
|
||||
|
||||
# Note: These defaults are a subset of the csvview default configuration, as defined in
|
||||
# [https://github.com/hat0uma/csvview.nvim/blob/5c22774c3ecc7f8883af5d143b366e45b1f0875d/README.md?plain=1#L97]
|
||||
# which I think users would most likely want to modify
|
||||
setupOpts = mkPluginSetupOption "csvview.nvim" {
|
||||
parser = {
|
||||
async_chunksize = mkOption {
|
||||
type = int;
|
||||
default = 50;
|
||||
description = "Number of lines processed per asynchronous parsing cycle. If the UI freezes, try reducing this value.";
|
||||
};
|
||||
|
||||
comments = mkOption {
|
||||
type = listOf str;
|
||||
default = [];
|
||||
description = ''
|
||||
List of comment prefixes. Lines starting with one of these are
|
||||
treated as comments and excluded from table rendering, e.g.
|
||||
`["#" "//"]`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
view = {
|
||||
min_column_width = mkOption {
|
||||
type = int;
|
||||
default = 5;
|
||||
description = "Minimum width of a column";
|
||||
};
|
||||
|
||||
spacing = mkOption {
|
||||
type = int;
|
||||
default = 2;
|
||||
description = "Spacing between columns";
|
||||
};
|
||||
|
||||
display_mode = mkOption {
|
||||
type = enum ["highlight" "border"];
|
||||
default = "highlight";
|
||||
description = ''
|
||||
Display method for the column delimiter.
|
||||
|
||||
- `highlight`: highlight the delimiter character.
|
||||
- `border`: render the delimiter as a vertical border.
|
||||
'';
|
||||
};
|
||||
|
||||
sticky_header = {
|
||||
enabled = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
description = "Keep the header row visible at the top while scrolling";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
6
modules/plugins/utility/csvview/default.nix
Normal file
6
modules/plugins/utility/csvview/default.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./csvview.nix
|
||||
./config.nix
|
||||
];
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
imports = [
|
||||
./binds
|
||||
./ccc
|
||||
./csvview
|
||||
./diffview
|
||||
./direnv
|
||||
./fzf-lua
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue