Raxol. Commands. FileSystem
(Raxol v2.6.0)
View Source
Pure functional in-memory virtual file system.
Every operation takes a filesystem struct and returns {:ok, result} or
{:error, reason}. The struct is immutable -- mutations return a new copy.
Internally uses a flat map keyed by absolute path for O(1) lookups.
Example
fs = FileSystem.new()
{:ok, fs} = FileSystem.mkdir(fs, "/docs")
{:ok, fs} = FileSystem.create_file(fs, "/docs/readme.txt", "Hello")
{:ok, entries} = FileSystem.ls(fs, "/docs")
{:ok, content} = FileSystem.cat(fs, "/docs/readme.txt")
Summary
Functions
Read the content of a file.
Change the current working directory. Supports absolute paths, relative
paths, .. (parent), and - (previous directory).
Create a file at path with content. Parent directory must exist.
Check if a path exists.
Format file content for terminal display. Returns a list of {line, line_number}
tuples, truncated to fit max_width and max_height.
Format ls output for terminal display. Returns a list of styled line tuples
{text, style} where style is :directory or :file.
List entries in a directory. Returns {:ok, entries} where entries
is a sorted list of child names.
Create a directory at path. Parent directories must exist.
Create a new filesystem with an empty root directory.
Return the current working directory.
Remove a file or empty directory at path.
Return metadata for the node at path.
Return a tree representation of the directory at path, limited to depth levels.
Returns {:ok, tree_node} where tree_node is {name, type, children}.
Types
@type node_type() :: :file | :directory
@type stat_info() :: %{ type: node_type(), size: non_neg_integer(), created_at: timestamp(), modified_at: timestamp(), path: String.t() }
@type t() :: %Raxol.Commands.FileSystem{ cwd: String.t(), nodes: %{required(String.t()) => node_entry()}, prev_dir: String.t() | nil }
@type timestamp() :: integer()
Functions
Read the content of a file.
Change the current working directory. Supports absolute paths, relative
paths, .. (parent), and - (previous directory).
Create a file at path with content. Parent directory must exist.
Check if a path exists.
@spec format_cat(String.t(), pos_integer(), pos_integer()) :: [ {String.t(), pos_integer()} ]
Format file content for terminal display. Returns a list of {line, line_number}
tuples, truncated to fit max_width and max_height.
Note: uses String.length/1 (grapheme count) for truncation. For CJK-accurate
display width, the render pipeline handles this via Raxol.UI.TextMeasure.
Format ls output for terminal display. Returns a list of styled line tuples
{text, style} where style is :directory or :file.
List entries in a directory. Returns {:ok, entries} where entries
is a sorted list of child names.
Create a directory at path. Parent directories must exist.
@spec new() :: t()
Create a new filesystem with an empty root directory.
Return the current working directory.
Remove a file or empty directory at path.
Return metadata for the node at path.
@spec tree(t(), String.t(), non_neg_integer()) :: {:ok, tree_node()} | {:error, atom()}
Return a tree representation of the directory at path, limited to depth levels.
Returns {:ok, tree_node} where tree_node is {name, type, children}.