Fig Docs
  • 🏠Welcome to Fig
  • 👋Get Started
    • Download and Install
    • `fig home`
      • My Apps
      • The Sidebar
      • Settings
    • The Fig App Store
    • Hotkeys
  • 💪Autocomplete
  • 😀The Fig CLI
    • 1. Fig Overrides
    • 2. Fig Aliases
    • 3. $FIGPATH
    • 4. Fig Apps
  • 📖Interactive Runbooks
    • Form Elements
      • Input
      • Textarea
      • Dropdown
      • Checkboxes
      • Buttons
    • Templating & Interpolation
    • Scripting Language (Psilo)
      • Full List of Functions
    • Running Runbooks
    • Full Examples
  • ⚒️ Build your own CLI
    • `fig build`
    • .fig Files
  • 🧰Build your own App
    • Get Started
    • App Lifecycle
    • Key Concepts
      • Running Shell Commands
      • Reading Environment Variables
      • Accessing Files & Saving Data
      • Loading Local Resources
    • Window Managment
      • Setting Window Properties
      • Repositioning the Window
      • Focusing & Blurring the Window
    • Advanced
      • Creating a Pseudo-Terminal Session
  • Other
    • Fig for Teams
    • Security & Privacy
    • FAQ
    • Contact Us
  • Interactive Runbooks
Powered by GitBook
On this page
  • User Assets
  • Icons from File Path
  • Icons by Type
  • Icons for PID
  • Sizing Assets
  1. Build your own App
  2. Key Concepts

Loading Local Resources

User Assets

It is possible to load local assets from the file system using the file:// URL scheme. This makes it possible to display images in a user's directory or visualize other assets that are don't lend themselves well to the terminal's text based formatting.

The following example displays all .png files in on our Desktop.

<html>
    <script>
        fig.init = (input) => {
          preview()
        }
        
    let preview = () => {
      fig.execute('ls -1', (out) => {
            let files = out.split('\n')
            let pngs = files.filter(p => p.endsWith(".png"))
            console.log(pngs)
            let thumbnails = pngs.map(p => { return `<img draggable = "true" src = "file://${fig.env.HOME}/Desktop/${p}"></img>`}).join("")
            console.log(thumbnails)
​
            document.getElementById("view").innerHTML = thumbnails
            console.log(document.body.innerHTML)
      })
    }
    </script>
    <style>
        img {
            height: 50px;
            width: 50px;
            object-fit: cover;
        }
​
    </style>
    <body>
        <div id = "view">
        </div>
    </body>
</html>
​

Using the fig:// URL scheme, you can load native assets for file icons and processes. There are a few different types of assets that can accessed this way.

Icons from File Path

Prefixing a file path with fig:// creates a reference to the native icon for that file, just like what would be displayed in Finder.

<img src = "fig:///Users/user/folder/file.ext">

Icons by Type

You might also want to get an icon for a file type, rather than by path. This is often used when displaying icons for files on a remote machine.

fig://icon?type=png

Icons for PID

To display icons for running processes, use the icon path with the pid as a query parameter.

fig://icon?pid=2834

Sizing Assets

For any fig:// URL, you can specify the size of the asset using query parameters. (The default size is 32px by 32px.)

fig://path/to/file?w=64&h=64

PreviousAccessing Files & Saving DataNextWindow Managment

Last updated 4 years ago

🧰