Raxol.Commands.FileSystem (Raxol v2.0.1)
View SourceVirtual file system for terminal navigation and content display.
Provides familiar file system commands for navigating terminal buffers:
- ls - List directory contents
- cat - Display file content
- cd - Change current directory
- pwd - Print working directory
- mkdir - Create directory
Example
fs = FileSystem.new()
fs = FileSystem.mkdir(fs, "/documents")
fs = FileSystem.create_file(fs, "/documents/readme.txt", "Hello World")
{:ok, contents, _fs} = FileSystem.ls(fs, "/documents")
# => ["readme.txt"]
{:ok, content, _fs} = FileSystem.cat(fs, "/documents/readme.txt")
# => "Hello World"Virtual Filesystem
The filesystem is a tree structure stored in memory:
- Directories are maps with entries
- Files have content and metadata
- Paths are Unix-style (absolute or relative)
Summary
Functions
Display file contents.
Change current directory.
Create a new file with content.
Check if path exists.
Format file contents as a buffer.
Format directory listing as a buffer.
List directory contents.
Create a new directory.
Create a new virtual filesystem.
Print working directory.
Remove a file or empty directory.
Get file or directory metadata.
Get directory tree as nested structure.
Types
@type dir_entry() :: %{ type: :directory, entries: %{required(String.t()) => file_entry() | dir_entry()}, metadata: metadata() }
@type entry_type() :: :file | :directory
@type metadata() :: %{ type: entry_type(), created: DateTime.t(), modified: DateTime.t(), size: non_neg_integer() }
@type path() :: String.t()
Functions
Display file contents.
Change current directory.
Create a new file with content.
Check if path exists.
@spec format_cat(String.t(), non_neg_integer(), non_neg_integer()) :: Raxol.Core.Buffer.t()
Format file contents as a buffer.
@spec format_ls([String.t()], t(), path()) :: Raxol.Core.Buffer.t()
Format directory listing as a buffer.
List directory contents.
Create a new directory.
@spec new() :: t()
Create a new virtual filesystem.
Print working directory.
Remove a file or empty directory.
Get file or directory metadata.
Get directory tree as nested structure.