Minga.Dired (Minga v0.1.0)

Copy Markdown View Source

Pure data structure and functions for Oil.nvim-style directory buffers.

A Dired listing is an editable buffer where each line is a filename. Saving the buffer diffs current content against the original entry list and applies the resulting file operations (renames, deletes, creates).

Layer 0: pure functions, no process dependencies.

Summary

Types

entry()

@type entry() :: Minga.Dired.Entry.t()

operation()

@type operation() ::
  {:rename, String.t(), String.t()}
  | {:delete, String.t()}
  | {:create, String.t()}
  | {:mkdir, String.t()}

sort_key()

@type sort_key() :: :name | :size | :date | :extension

t()

@type t() :: %Minga.Dired{
  directory: String.t(),
  entries: [entry()],
  show_details: boolean(),
  show_hidden: boolean(),
  sort_by: sort_key()
}

Functions

diff_operations(original_entries, current_names, directory)

@spec diff_operations([entry()], [String.t()], String.t()) :: [operation()]

entry_at_line(dired, line)

@spec entry_at_line(t(), non_neg_integer()) :: entry() | nil

format_entry(entry, show_details \\ false)

@spec format_entry(entry(), boolean()) :: String.t()

format_listing(dired)

@spec format_listing(t()) :: String.t()

next_sort_key(atom)

@spec next_sort_key(sort_key()) :: sort_key()

parent_directory(path)

@spec parent_directory(String.t()) :: String.t()

parse_listing(text)

@spec parse_listing(String.t()) :: [String.t()]

read_directory(path, opts \\ [])

@spec read_directory(
  String.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}

refresh(dired)

@spec refresh(t()) :: {:ok, t()} | {:error, term()}

with_show_details(dired, show_details)

@spec with_show_details(t(), boolean()) :: {:ok, t()} | {:error, term()}

with_show_hidden(dired, show_hidden)

@spec with_show_hidden(t(), boolean()) :: {:ok, t()} | {:error, term()}

with_sort_by(dired, sort_by)

@spec with_sort_by(t(), sort_key()) :: {:ok, t()} | {:error, term()}