2024-06-22 20:11:10 +03:00
|
|
|
(** File contents as an array of lines, where each line is wrapped into a document (for rendering efficiency) *)
|
|
|
|
type file_contents = {
|
|
|
|
lines : Pretty.doc array;
|
|
|
|
offset : int;
|
|
|
|
}
|
|
|
|
|
2024-03-23 13:37:23 +03:00
|
|
|
(** A definition of a file tree. *)
|
|
|
|
type tree =
|
2024-06-22 20:11:10 +03:00
|
|
|
| File of string * file_contents lazy_t
|
2024-03-23 13:37:23 +03:00
|
|
|
| Dir of string * tree array
|
|
|
|
|
|
|
|
(** Return the name of a given tree node. *)
|
|
|
|
val file_name : tree -> string
|
|
|
|
|
|
|
|
(** Read directory contents recursively from a given file path. *)
|
|
|
|
val read_tree : string -> tree
|
|
|
|
|
|
|
|
(** A cursor for files inside a single directory. *)
|
2024-06-22 21:47:15 +03:00
|
|
|
type dir_cursor = {
|
2024-03-23 13:37:23 +03:00
|
|
|
pos : int;
|
|
|
|
files : tree array;
|
|
|
|
}
|
|
|
|
|
2024-06-22 21:47:15 +03:00
|
|
|
type cursor =
|
|
|
|
| Dir_cursor of dir_cursor
|
2024-06-23 15:42:54 +03:00
|
|
|
| File_cursor of file_contents
|
2024-06-22 21:47:15 +03:00
|
|
|
|
2024-03-23 13:37:23 +03:00
|
|
|
(** Return the currently selected file in file cursor. *)
|
2024-06-22 21:47:15 +03:00
|
|
|
val file_at : dir_cursor -> tree
|
2024-03-23 13:37:23 +03:00
|
|
|
|
|
|
|
(** A file tree zipper that allows to traverse the tree in four directions. *)
|
|
|
|
type zipper = {
|
2024-06-22 21:47:15 +03:00
|
|
|
parents : dir_cursor list;
|
2024-03-23 13:37:23 +03:00
|
|
|
current : cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
(** Constructs a zipper from the contents of a given directory. *)
|
|
|
|
val zip_it : tree array -> zipper
|
|
|
|
|
|
|
|
(** Returns the list of parents names in reverse order. *)
|
|
|
|
val zipper_parents : zipper -> string list
|
|
|
|
|
|
|
|
(** Move to the next file within the same directory. Cycles. *)
|
|
|
|
val go_down : zipper -> zipper
|
|
|
|
|
|
|
|
(** Move to the previous file within the same directory. Cycles. *)
|
|
|
|
val go_up : zipper -> zipper
|
|
|
|
|
|
|
|
(** Move to the directory under the current cursor. Doesn't move inside files or empty directories. *)
|
|
|
|
val go_next : zipper -> zipper
|
|
|
|
|
|
|
|
(** Move to the parent directory. *)
|
|
|
|
val go_back : zipper -> zipper
|