Module

Pathy.Printer

#Printer

type Printer = { current :: NonEmptyString, escaper :: Escaper, root :: Maybe NonEmptyString -> String, sep :: NonEmptyString, up :: NonEmptyString }

A Printer defines options for printing paths.

  • root is a function used to construct the initial segment of paths.
  • current is a representation of the current directory.
  • up is a representation of going up to the parent directory.
  • sep is the string to separate path segments by.
  • escaper specified how to deal with printing reserved names and characters.

#posixPrinter

posixPrinter :: Printer

A printer for POSIX paths.

#windowsPrinter

windowsPrinter :: Printer

A printer for Windows paths.

#printPath

printPath :: forall a b. IsRelOrAbs a => IsDirOrFile b => Printer -> SandboxedPath a b -> String

Prints a SandboxedPath into its canonical String representation, using the specified printer. The printed path will always be absolute, as this is the only way to ensure the path is safely referring to the intended location.

#unsafePrintPath

unsafePrintPath :: forall a b. IsRelOrAbs a => IsDirOrFile b => Printer -> SandboxedPath a b -> String

Prints a SandboxedPath into its canonical String representation, using the specified printer. This will print a relative path if b ~ Rel, which depending on how the resulting string is used, may be unsafe.

#debugPrintPath

debugPrintPath :: forall a b. Warn (Text "debugPrintPath usage") => IsRelOrAbs a => IsDirOrFile b => Printer -> Path a b -> String

Prints a path exactly according to its representation. This should only be used for debug purposes. Using this function will raise a warning at compile time as a reminder!

#Escaper

newtype Escaper

An Escaper encodes segments or characters which have reserved meaning within names in a path.

Constructors

Instances

#slashEscaper

slashEscaper :: Escaper

An escaper that replaces all '/' characters in a name with '-'s.

#dotEscaper

dotEscaper :: Escaper

An escaper that replaces names "." and ".." with "$dot" and "$dot$dot".

#posixEscaper

posixEscaper :: Escaper

An escaper that removes all slashes, converts ".." into "$dot$dot", and converts "." into "$dot".

#windowsEscaper

windowsEscaper :: Escaper

An escaper that attempts to encode all reserved names and characters for windows-style paths.

#escape

escape :: forall name. Newtype name NonEmptyString => Escaper -> name -> String

Prints a name as a String using the specified escaper.

Modules