diff --git a/README.md b/README.md index 6708b7f..8249cb3 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,6 @@ > This project is young, expect breaking changes, and for now there's a nasty bug if you are on neovim stable [#125](https://github.com/neo451/feed.nvim/issues/125#issuecomment-2612966517), recommand to use nightly or wait for the coming release of 0.11 > > other than that usage should be fun and smooth, go ahead and enjoy! -> -> see [Roadmap](https://github.com/neo451/feed.nvim/wiki/Roadmap) for where this project goes. ## 🌟 Features @@ -69,9 +67,10 @@ For [lazy.nvim](https://github.com/folke/lazy.nvim): { "neo451/feed.nvim", cmd = "Feed" } ``` -### Health Check +### Initial Steps - run `:checkhealth feed` to see your installation status +- read tutorial below or read `:h feed.txt` @@ -86,9 +85,28 @@ Use `:Feed `, `:Feed update_feed ` to get the completion Use `:Feed`, `:Feed update_feed` to open menu and select +### List of commands + +| name | desc | bang | +| ------------------------------- | ----------------------------------------------------------------------------------- | ---- | +| `Feed ` | opens a index buffer, a list view based on the filter you passed in | no | +| `Feed index` | opens a index buffer, a list view based on your default filter | no | +| `Feed entry` | opens a entry buffer, a markdown view of the entry content | no | +| `Feed update` | updates all feeds in the database | no | +| `Feed update_feed ` | update a single feed in the database | no | +| `Feed sync` | sync the database with your config, removes feeds and entries (if bang) not present | yes | +| `Feed search ` | opens picker to live search your database | no | +| `Feed grep` | opens picker to live grep your database (experimental) | no | +| `Feed list` | opens a split to show info about all your feeds in database | no | +| `Feed log` | opens a split to show log | no | +| `Feed load_opml ` | import from an OPML file or url | no | +| `Feed export_opml ` | export to an OPML file | no | +| `Feed web ` | opens a server on a port and opens the web interface in browser | no | +| `Feed urlview` | opens a select UI to picker urls in entry buffer, to open in browser | no | + ## Keymaps -Press `?` in to get hints. +Press `?` in to get keymap hints. ### Index buffer @@ -104,7 +122,7 @@ Press `?` in to get hints. | refresh | `r` | | update | `R` | | search | `s` | -| yank_url | `y` | +| yank_url | `Y` | | untag | `-` | | tag | `+` | | quit | `q` | @@ -122,7 +140,7 @@ Press `?` in to get hints. | untag | `-` | | tag | `+` | | urlview | `r` | -| yank_url | `y` | +| yank_url | `Y` | | quit | `q` | ## Manage @@ -229,11 +247,11 @@ Latter two is resolved into ### Limit -- `##` means `limit`, limits the number of entries +- `#` means `limit`, limits the number of entries ### Examples -- `+blog +unread -star @6-months-ago ##10 zig !rust` +- `+blog +unread -star @6-months-ago #10 zig !rust` Only Shows 10 entries with tags blog and unread, without tag star, and are published within 6 month, making sure they have zig but not rust in the title. diff --git a/doc/feed.txt b/doc/feed.txt index 60306d3..65ff7a7 100644 --- a/doc/feed.txt +++ b/doc/feed.txt @@ -1,10 +1,11 @@ -*feed.txt* For 0.11 Last change: 2025 February 25 +*feed.txt* For 0.11 Last change: 2025 February 26 ============================================================================== Table of Contents *feed-table-of-contents* 1. Commands |feed-commands| - Sub commands and arguments |feed-commands-sub-commands-and-arguments| + - List of commands |feed-commands-list-of-commands| 2. Keymaps |feed-keymaps| - Index buffer |feed-keymaps-index-buffer| - Entry buffer |feed-keymaps-entry-buffer| @@ -19,7 +20,7 @@ Table of Contents *feed-table-of-contents* - Limit |feed-search-limit| - Examples |feed-search-examples| - Grep |feed-search-grep| -5. Layout |feed-layout| +5. Recipes |feed-recipes| 6. Lua API |feed-lua-api| 7. Custom Action |feed-custom-action| @@ -37,10 +38,52 @@ Use `:Feed `, `:Feed update_feed ` to get the completion Use `:Feed`, `:Feed update_feed` to open menu and select +LIST OF COMMANDS *feed-commands-list-of-commands* + + ---------------------------------------------------------------------------------------- + name desc bang + ------------------------------- ------------------------------------------------- ------ + Feed opens a index buffer, a list view based on the no + filter you passed in + + Feed index opens a index buffer, a list view based on your no + default filter + + Feed entry opens a entry buffer, a markdown view of the no + entry content + + Feed update updates all feeds in the database no + + Feed update_feed update a single feed in the database no + + Feed sync sync the database with your config, removes feeds yes + and entries (if bang) not present + + Feed search opens picker to live search your database no + + Feed grep opens picker to live grep your database no + (experimental) + + Feed list opens a split to show info about all your feeds no + in database + + Feed log opens a split to show log no + + Feed load_opml import from an OPML file or url no + + Feed export_opml export to an OPML file no + + Feed web opens a server on a port and opens the web no + interface in browser + + Feed urlview opens a select UI to picker urls in entry buffer, no + to open in browser + ---------------------------------------------------------------------------------------- + ============================================================================== 2. Keymaps *feed-keymaps* -Press `?` in to get hints. +Press `?` in to get keymap hints. INDEX BUFFER *feed-keymaps-index-buffer* @@ -50,13 +93,14 @@ INDEX BUFFER *feed-keymaps-index-buffer* hints ? dot_repeat . undo u + redo entry split browser b refresh r update R search s - yank_url y + yank_url Y untag - tag + quit q @@ -74,7 +118,7 @@ ENTRY BUFFER *feed-keymaps-entry-buffer* untag - tag + urlview r - yank_url y + yank_url Y quit q ============================================================================== @@ -197,12 +241,12 @@ DATE *feed-search-date* LIMIT *feed-search-limit* -- `##` means `limit`, limits the number of entries +- `#` means `limit`, limits the number of entries EXAMPLES *feed-search-examples* -- `+blog +unread -star @6-months-ago ##10 zig !rust` +- `+blog +unread -star @6-months-ago #10 zig !rust` Only Shows 10 entries with tags blog and unread, without tag star, and are published within 6 month, making sure they have zig but not rust in the title. @@ -239,9 +283,121 @@ one of the search backends: ============================================================================== -5. Layout *feed-layout* +5. Recipes *feed-recipes* -:TODO: +Change the highlight of the tags section and use emojis and mini.icons for tags ~ + +>lua + require("feed").setup({ + layout = { + tags = { + color = "String", + format = function(id, db) + local icons = { + news = "📰", + tech = "💻", + movies = "🎬", + games = "🎮", + music = "🎵", + podcast = "🎧", + books = "📚", + unread = "🆕", + read = "✅", + junk = "🚮", + star = "⭐", + } + + local get_icon = function(name) + if icons[name] then + return icons[name] + end + local has_mini, MiniIcons = pcall(require, "mini.icons") + if has_mini then + local icon = MiniIcons.get("filetype", name) + if icon then + return icon .. " " + end + end + return name + end + + local tags = vim.tbl_map(get_icon, db:get_tags(id)) + + return "[" .. table.concat(tags, ", ") .. "]" + end, + }, + }, + }) +< + +Custom function & keymap for podcast and w3m ~ + +>lua + local function play_podcast() + local link = require("feed").get_entry().link + if link:find("mp3") then + vim.ui.open(link) + -- any other player like: + -- vim.system({ "vlc.exe", link }) + else + vim.notify("not a podcast episode") + end + end + + local function show_in_w3m() + if not vim.fn.executable("w3m") then + vim.notify("w3m not installed") + return + end + local link = require("feed").get_entry().link + local w3m = require("feed.ui.window").new({ + relative = "editor", + col = math.floor(vim.o.columns * 0.1), + row = math.floor(vim.o.lines * 0.1), + width = math.floor(vim.o.columns * 0.8), + height = math.floor(vim.o.lines * 0.8), + border = "rounded", + style = "minimal", + title = "Feed w3m", + zindex = 10, + }) + vim.keymap.set({ "n", "t" }, "q", "q", { silent = true, buffer = w3m.buf }) + vim.fn.jobstart({ "w3m", link }, { term = true }) + vim.cmd("startinsert") + end + + require("feed").setup({ + keys = { + index = { + [play_podcast] = "p", + [show_in_w3m] = "w", + }, + }, + }) +< + +Custom colorscheme only set when viewing feeds ~ + +>lua + local og_color + + vim.api.nvim_create_autocmd("User", { + pattern = "FeedShowIndex", + callback = function() + if not og_color then + og_color = vim.g.colors_name + end + vim.cmd.colorscheme("kanagawa-lotus") + end, + }) + + vim.api.nvim_create_autocmd("User", { + pattern = "FeedQuitIndex", + callback = function() + vim.cmd.colorscheme(og_color) + end, + }) +< ============================================================================== diff --git a/docs/index.html b/docs/index.html index a4aa545..f4814a5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -23,6 +23,7 @@

feed.nvim

  • Commands
  • Keymaps
  • -
  • Layout
  • +
  • Recipes
  • Lua API
  • Custom Action
  • @@ -62,8 +63,95 @@

    Sub commands and arguments

    To execute actions available in the current context, or give arguments to the command, use the following syntax:

    Use :Feed <Tab>, :Feed update_feed <Tab> to get the completion

    Use :Feed<Enter>, :Feed update_feed<Enter> to open menu and select

    +

    List of commands

    + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    namedescbang
    Feed <query>opens a index buffer, a list view based on the filter you passed inno
    Feed indexopens a index buffer, a list view based on your default filterno
    Feed entryopens a entry buffer, a markdown view of the entry contentno
    Feed updateupdates all feeds in the databaseno
    Feed update_feed <feed_url>update a single feed in the databaseno
    Feed syncsync the database with your config, removes feeds and entries (if bang) not presentyes
    Feed search <query>opens picker to live search your databaseno
    Feed grepopens picker to live grep your database (experimental)no
    Feed listopens a split to show info about all your feeds in databaseno
    Feed logopens a split to show logno
    Feed load_opml <filepath/url>import from an OPML file or urlno
    Feed export_opml <filepath>export to an OPML fileno
    Feed web <port>opens a server on a port and opens the web interface in browserno
    Feed urlviewopens a select UI to picker urls in entry buffer, to open in browserno

    Keymaps

    -

    Press ? in to get hints.

    +

    Press ? in to get keymap hints.

    Index buffer

    @@ -86,42 +174,46 @@

    Index buffer

    + + + + - + - + - + - + - + - + - + - + - + - + @@ -174,7 +266,7 @@

    Entry buffer

    - + @@ -259,11 +351,11 @@

    Date

    Limit

      -
    • ## means limit, limits the number of entries
    • +
    • # means limit, limits the number of entries

    Examples

      -
    • +blog +unread -star @6-months-ago ##10 zig !rust
    • +
    • +blog +unread -star @6-months-ago #10 zig !rust

    Only Shows 10 entries with tags blog and unread, without tag star, and are published within 6 month, making sure they have zig but not rust in the title.

      @@ -293,8 +385,121 @@

      Grep

    • fzf-lua
    • mini.pick
    -

    Layout

    -

    :TODO:

    +

    Recipes

    +
    + +Change the highlight of the tags section and use emojis and mini.icons for tags + +
    require("feed").setup({
    +   layout = {
    +      tags = {
    +         color = "String",
    +         format = function(id, db)
    +            local icons = {
    +               news = "📰",
    +               tech = "💻",
    +               movies = "🎬",
    +               games = "🎮",
    +               music = "🎵",
    +               podcast = "🎧",
    +               books = "📚",
    +               unread = "🆕",
    +               read = "✅",
    +               junk = "🚮",
    +               star = "⭐",
    +            }
    +
    +            local get_icon = function(name)
    +               if icons[name] then
    +                  return icons[name]
    +               end
    +               local has_mini, MiniIcons = pcall(require, "mini.icons")
    +               if has_mini then
    +                  local icon = MiniIcons.get("filetype", name)
    +                  if icon then
    +                     return icon .. " "
    +                  end
    +               end
    +               return name
    +            end
    +
    +            local tags = vim.tbl_map(get_icon, db:get_tags(id))
    +
    +            return "[" .. table.concat(tags, ", ") .. "]"
    +         end,
    +      },
    +   },
    +})
    +
    +
    + +Custom function & keymap for podcast and w3m + +
    local function play_podcast()
    +   local link = require("feed").get_entry().link
    +   if link:find("mp3") then
    +      vim.ui.open(link)
    +   -- any other player like:
    +   -- vim.system({ "vlc.exe", link })
    +   else
    +      vim.notify("not a podcast episode")
    +   end
    +end
    +
    +local function show_in_w3m()
    +   if not vim.fn.executable("w3m") then
    +      vim.notify("w3m not installed")
    +      return
    +   end
    +   local link = require("feed").get_entry().link
    +   local w3m = require("feed.ui.window").new({
    +      relative = "editor",
    +      col = math.floor(vim.o.columns * 0.1),
    +      row = math.floor(vim.o.lines * 0.1),
    +      width = math.floor(vim.o.columns * 0.8),
    +      height = math.floor(vim.o.lines * 0.8),
    +      border = "rounded",
    +      style = "minimal",
    +      title = "Feed w3m",
    +      zindex = 10,
    +   })
    +   vim.keymap.set({ "n", "t" }, "q", "<cmd>q<cr>", { silent = true, buffer = w3m.buf })
    +   vim.fn.jobstart({ "w3m", link }, { term = true })
    +   vim.cmd("startinsert")
    +end
    +
    +require("feed").setup({
    +   keys = {
    +      index = {
    +         [play_podcast] = "p",
    +         [show_in_w3m] = "w",
    +      },
    +   },
    +})
    +
    +
    + +Custom colorscheme only set when viewing feeds + +
    local og_color
    +
    +vim.api.nvim_create_autocmd("User", {
    +   pattern = "FeedShowIndex",
    +   callback = function()
    +      if not og_color then
    +         og_color = vim.g.colors_name
    +      end
    +      vim.cmd.colorscheme("kanagawa-lotus")
    +   end,
    +})
    +
    +vim.api.nvim_create_autocmd("User", {
    +   pattern = "FeedQuitIndex",
    +   callback = function()
    +      vim.cmd.colorscheme(og_color)
    +   end,
    +})
    +

    Lua API

    :TODO:

    Custom Action

    diff --git a/lua/feed/commands.lua b/lua/feed/commands.lua index d048132..aaa3364 100644 --- a/lua/feed/commands.lua +++ b/lua/feed/commands.lua @@ -6,14 +6,13 @@ local feedlist = ut.feedlist local M = {} -M.server = { - doc = "opens server", +M.web = { + doc = "opens server and web interface", impl = function(port) port = port or Config.web.port require("feed.server").open(port) vim.ui.open("http://0.0.0.0:" .. port) end, - context = { all = true }, } M.load_opml = { @@ -25,7 +24,6 @@ M.load_opml = { ui.input({ prompt = "path or url to your opml: ", completion = "file_in_path" }, ui.load_opml) end end, - context = { all = true }, } M.export_opml = { @@ -37,91 +35,71 @@ M.export_opml = { ui.input({ prompt = "export your opml to: ", completion = "file_in_path" }, ui.export_opml) end end, - context = { all = true }, } M.search = { doc = "search the database by time, tags or regex", impl = ui.search, - context = { all = true }, } M.grep = { doc = "full-text search through the entry contents", impl = ui.grep, - context = { all = true }, } M.refresh = { doc = "refresh the index buffer", impl = ui.refresh, - context = { index = true }, } M.log = { doc = "show log", impl = ui.show_log, - context = { all = true }, } M.browser = { doc = "open entry link in browser with vim.ui.open", impl = ui.show_browser, - context = { index = true, entry = true }, } M.full = { doc = "fetch the full text", impl = ui.show_full, - context = { entry = true }, } M.split = { doc = "show entry in split", impl = ui.show_split, - context = { index = true }, } M.entry = { doc = "show entry in new buffer", impl = ui.show_entry, - context = { index = true }, } M.index = { doc = "show search results in new buffer", impl = ui.show_index, - context = { all = true }, } M.next = { doc = "show next search result", impl = ui.show_next, - context = { entry = true }, } M.prev = { doc = "show previous search result", impl = ui.show_prev, - context = { entry = true }, } M.hints = { doc = "show keymap hints", impl = ui.show_hints, - context = { entry = true, index = true }, } M.quit = { doc = "quit current view", impl = ui.quit, - context = { entry = true, index = true }, -} - -M.open_url = { - doc = "open url under cursor", - impl = ui.open_url, - context = { entry = true }, } M.yank_url = { @@ -129,19 +107,16 @@ M.yank_url = { impl = function() vim.fn.setreg("+", ui.get_entry().link) end, - context = { index = true, entry = true }, } M.undo = { doc = "undo", impl = ui.undo, - context = { index = true }, } M.redo = { doc = "redo", impl = ui.redo, - context = { index = true }, } M.dot = { @@ -149,7 +124,6 @@ M.dot = { impl = function() ui.dot() end, - context = { index = true }, } M.tag = { @@ -161,7 +135,6 @@ M.tag = { ui.input({ prompt = "Tag: " }, ui.tag) end end, - context = { index = true, entry = true }, } --- TODO: make tag untag visual line mode @@ -174,19 +147,16 @@ M.untag = { ui.input({ prompt = "Untag: " }, ui.untag) end end, - context = { index = true, entry = true }, } M.urlview = { doc = "list all links in entry and open selected", impl = ui.show_urls, - context = { entry = true }, } M.list = { doc = "list all feeds", impl = ui.show_feeds, - context = { all = true }, } M.update = { @@ -208,7 +178,6 @@ M.update = { end, }) end, - context = { all = true }, } M.update_feed = { @@ -229,7 +198,6 @@ M.update_feed = { complete = function() return feedlist(db.feeds, true) end, - context = { all = true }, } M["sync!"] = { @@ -237,7 +205,6 @@ M["sync!"] = { impl = function() db:hard_sync() end, - context = { all = true }, } M.sync = { @@ -245,27 +212,60 @@ M.sync = { impl = function() db:soft_sync() end, - context = { all = true }, +} + +local entry_cmds = { + "urlview", + "next", + "prev", + "full", + "browser", +} + +local index_cmds = { + "web", + "untag", + "load_opml", + "update", + "sync!", + "tag", + "index", + "update_feed", + "list", + "quit", + "grep", + "browser", + "export_opml", + "split", + "log", + "search", + "sync", +} + +local general_cmds = { + "index", + "search", + "update", + "sync", + "sync!", + "update_feed", + "list", + "grep", + "web", + "browser", + "load_opml", + "export_opml", + "log", } function M._list_commands() - local choices = vim.iter(vim.tbl_keys(M)):filter(function(v) - return v:sub(0, 1) ~= "_" and not vim.list_contains({ "dot", "redo", "undo" }, v) - end) if ut.in_entry() then - choices = choices:filter(function(v) - return M[v].context.entry or M[v].context.all - end) + return entry_cmds elseif ut.in_index() then - choices = choices:filter(function(v) - return M[v].context.index or M[v].context.all - end) + return index_cmds else - choices = choices:filter(function(v) - return M[v].context.all - end) + return general_cmds end - return choices:totable() end function M._load_command(args) diff --git a/lua/feed/config.lua b/lua/feed/config.lua index 7074775..8049d0a 100644 --- a/lua/feed/config.lua +++ b/lua/feed/config.lua @@ -6,7 +6,7 @@ ---@field rsshub? { instance: string, export: string } move all options here as a enum?? ---@field layout? table ---@field progress? { backend: "mini.notify" | "snacks" | "fidget" | "native" } ----@field search? { backend: "telescope" | "mini.pick" | "fzf-lua", default_query: string } +---@field search? { backend: "telescope" | "mini.pick" | "fzf-lua", sort_order: "ascending" | "descending", default_query: string } ---@field data? { backend: "local" | "ttrss" } ---@field options? { entry: { wo: vim.wo|{}, bo: vim.bo|{} }, index: { wo: vim.wo|{}, bo: vim.bo|{} } } @@ -27,10 +27,7 @@ local default = { ---@type string[] curl_params = {}, ---@type table[] - layout = { - padding = { - enabled = false, - }, + ui = { order = { "date", "feed", "tags", "title" }, winbar_right = { "query", "last_updated" }, date = { @@ -59,6 +56,34 @@ local default = { }, }, + winbar = { + order = { "date", "feed", "tags", "title", "%=%<", "query", "last_updated" }, + date = { + width = 10, + color = "FeedDate", + }, + feed = { + width = 25, + color = "FeedTitle", + }, + tags = { + width = 20, + color = "FeedTags", + }, + title = { + color = "FeedTitle", + }, + progress = { + color = "FeedDate", + }, + query = { + color = "FeedLabel", + }, + last_updated = { + color = "FeedDate", + }, + }, + picker = { order = { "feed", "tags", "title" }, feed = { @@ -78,6 +103,7 @@ local default = { search = { default_query = "@2-weeks-ago +unread ", + sort_order = "descending", backend = { "mini.pick", "telescope", @@ -118,7 +144,7 @@ local default = { refresh = "r", update = "R", search = "s", - yank_url = "y", + yank_url = "Y", untag = "-", tag = "+", quit = "q", @@ -133,7 +159,7 @@ local default = { untag = "-", tag = "+", urlview = "r", - yank_url = "y", + yank_url = "Y", quit = "q", }, }, diff --git a/lua/feed/db/local.lua b/lua/feed/db/local.lua index 94e0545..b076d29 100644 --- a/lua/feed/db/local.lua +++ b/lua/feed/db/local.lua @@ -196,7 +196,11 @@ end function M:sort() table.sort(self.index, function(a, b) - return a[2] > b[2] + if Config.search.sort_order == "ascending" then + return a[2] < b[2] + else + return a[2] > b[2] + end end) end @@ -213,8 +217,8 @@ function M:rm(id) end self:save_feeds() self:save_index() - pcall(Path.rm, self.dir / "data" / id) - pcall(Path.rm, self.dir / "object" / id) + Path.rm(self.dir / "data" / id) + Path.rm(self.dir / "object" / id) rawset(self, id, nil) rawset(mem, id, nil) end @@ -349,16 +353,17 @@ function M:filter(str) end local ret = iter:fold({}, function(acc, id) - if not mem[id] then - mem[id] = Path.load(self.dir / "object" / id) - end acc[#acc + 1] = id return acc end) if q.must_have then table.sort(ret, function(a, b) - return self[a].time > self[b].time + if Config.search.sort_order == "ascending" then + return self[a].time < self[b].time + else + return self[a].time > self[b].time + end end) end diff --git a/lua/feed/ui.lua b/lua/feed/ui.lua index 2bd7678..440dc5b 100644 --- a/lua/feed/ui.lua +++ b/lua/feed/ui.lua @@ -14,8 +14,6 @@ local redo_history = state.redo_history local hl = vim.hl or vim.highlight local api, fn, fs = vim.api, vim.fn, vim.fs -local og = {} - local M = { state = state, } @@ -87,6 +85,19 @@ local body_transforms = { -- TODO: allow user } +local function hl_entry(buf) + for i, t in ipairs({ + { 7, "FeedTitle" }, + { 8, "FeedAuthor" }, + { 6, "FeedFeed" }, + { 6, "FeedLink" }, + { 6, "FeedDate" }, + }) do + local j, hi = t[1], t[2] + hl.range(buf, ns_entry, hi, { i - 1, j }, { i - 1, 200 }) + end +end + ---@param buf integer ---@param body string ---@param id string @@ -128,18 +139,9 @@ local function render_entry(buf, body, id) api.nvim_buf_set_lines(buf, i - 1, i, false, { v }) end - for i, t in ipairs({ - { 7, "FeedTitle" }, - { 8, "FeedAuthor" }, - { 6, "FeedFeed" }, - { 6, "FeedLink" }, - { 6, "FeedDate" }, - }) do - local j, hi = t[1], t[2] - hl.range(buf, ns_entry, hi, { i - 1, j }, { i - 1, 200 }) - end vim.bo[buf].modifiable = false + hl_entry(buf) image_attach(buf) mark_read(id) @@ -153,7 +155,7 @@ end local function hl_index(buf) for linenr = 1, #state.entries do local acc = 0 - local layout = Config.layout + local layout = Config.ui for _, name in ipairs(layout.order) do local sect = layout[name] local width = sect.width or 100 @@ -187,7 +189,7 @@ M.show_index = function() local lines = {} for i, id in ipairs(state.entries) do - lines[i] = Format.entry(id, Config.layout, db) + lines[i] = Format.entry(id, Config.ui, db) end table.insert(lines, "") api.nvim_buf_set_lines(buf, 0, -1, false, lines) diff --git a/lua/feed/ui/bar.lua b/lua/feed/ui/bar.lua index 3a1e527..1f94397 100644 --- a/lua/feed/ui/bar.lua +++ b/lua/feed/ui/bar.lua @@ -10,7 +10,7 @@ function _G._feed_bar_component(name) return cmp[name]() end -local layout = config.layout +local layout = config.winbar local hi_pattern = "%%#%s#%s%%*" setmetatable(cmp, { @@ -40,17 +40,13 @@ end ---@return string function M.show_winbar() local buf = {} - for _, name in ipairs(layout.order) do - buf[#buf + 1] = "%{%v:lua._feed_bar_component('" .. name .. "')%}" - end - - buf[#buf + 1] = "%=%<" - - for _, name in ipairs(layout.winbar_right) do - buf[#buf + 1] = "%{%v:lua._feed_bar_component('" .. name .. "')%}" + if not layout[name] then + buf[#buf + 1] = name + else + buf[#buf + 1] = "%{%v:lua._feed_bar_component('" .. name .. "')%}" + end end - return table.concat(buf, " ") end diff --git a/lua/feed/ui/window.lua b/lua/feed/ui/window.lua index 9824f13..ff04666 100644 --- a/lua/feed/ui/window.lua +++ b/lua/feed/ui/window.lua @@ -53,11 +53,7 @@ function M.new(opts, enter) opts.show = vim.F.if_nil(opts.show, true) opts.enter = vim.F.if_nil(enter, true) - if Config.layout.padding.enabled then - opts.wo.statuscolumn = " " - else - opts.wo.statuscolumn = "" - end + opts.wo.statuscolumn = "" id = id + 1 local self = setmetatable({ opts = opts, diff --git a/tests/test_db.lua b/tests/test_db.lua index 1ffa4e9..7ac3f47 100644 --- a/tests/test_db.lua +++ b/tests/test_db.lua @@ -1,4 +1,5 @@ local date = require("feed.parser.date") +local ut = require("feed.utils") local eq = MiniTest.expect.equality local sha = vim.fn.sha256 local db = require("feed.db") @@ -54,9 +55,12 @@ T["new"]["adds entries to db and in memory, with id as key/filename, and content } local key = sha(entry.link) db[key] = entry + local fp = tostring(db.dir / "data" / key) + ut.save_file(fp, "dataaaaaaa") eq(entry.time, db[key].time) eq(entry.link, db[key].link) eq(entry.title, db[key].title) + eq("dataaaaaaa", ut.read_file(fp)) end T["new"]["rm all refs in the db"] = function() @@ -66,6 +70,8 @@ T["new"]["rm all refs in the db"] = function() time = 1, } local id = sha(entry.link) + local fp = tostring(db.dir / "data" / id) + ut.save_file(fp, "to remove") db[id] = entry db:tag(id, { "star", "read" }) db:rm(id) diff --git a/tests/test_format.lua b/tests/test_format.lua index 16103b1..4882e7a 100644 --- a/tests/test_format.lua +++ b/tests/test_format.lua @@ -1,48 +1,26 @@ -local M = require("feed.ui.format") local eq = MiniTest.expect.equality -local db = require("feed.db") local T = MiniTest.new_set() -local layout = require("feed.config").layout +local layout = require("feed.config").ui -local db = { - ["1"] = { - title = "title", - feed = "https://neovim.io/news.xml", - author = "author", - link = "link", - time = os.time({ year = 2025, month = 1, day = 1 }), - }, - feeds = { - ["https://neovim.io/news.xml"] = { - title = "neovim", - tags = { "nvim" }, - }, - }, - tags = { - star = { - ["1"] = true, - }, - }, +local db = require("feed.db") +db = db.new("~/.feed.nvim.test/") +db.feeds["https://neovim.io/news.xml"] = { + title = "neovim", + tags = { "nvim" }, } -db.__index = db +db.tags.star["1"] = true -function db:get_tags(id) - local ret = {} - -- 1. auto tag no [read] as [unread] - if not (self.tags.read and self.tags.read[id]) then - ret = { "unread" } - end +db["1"] = { + title = "title", + feed = "https://neovim.io/news.xml", + author = "author", + link = "link", + time = os.time({ year = 2025, month = 1, day = 1 }), +} - -- 2. get tags from tags.lua - for tag, tagees in pairs(self.tags) do - if tagees[id] then - ret[#ret + 1] = tag - end - end - return ret -end +local M = require("feed.ui.format") T["format"] = MiniTest.new_set({})
    u
    redo<C-r>
    entry <CR>
    split <M-CR>
    browser b
    refresh r
    update R
    search s
    yank_urlyY
    untag -
    tag +
    quit q
    yank_urlyY
    quit