Skip to content

BrandonIrizarry/dirselect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

167 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

dirselect in action

This is a filepicker bubble, a bubble being a component for Bubble Tea applications. It was inspired by the official filepicker Bubble — much of the code is taken directly from that example.

I had started with the intention to pare down that filepicker to the simplicity of the shopping list tutorial found in the Bubble Tea README, but, as I learned more of the ropes, I began to realize why some of the design elements of the original filepicker were there in the first place.

This originally started out as a directory picker (hence the name "dirselect"), but I eventually decided to add the ability to select files as well.

Installation

go get github.com/BrandonIrizarry/dirselect

Example

Here's some code that opens dirselect, then echoes the user's selections back to the console.

package main

import (
	"fmt"
	"log"

	"github.com/BrandonIrizarry/dirselect"
	tea "github.com/charmbracelet/bubbletea"
)

func main() {
	ds, err := dirselect.New()
	if err != nil {
		log.Fatal(err)
	}

	p := tea.NewProgram(ds, tea.WithAltScreen())
	m, err := p.Run()
	if err != nil {
		log.Fatal(err)
	}

	ds2 := m.(dirselect.Model)

	fmt.Println("You selected:")
	for _, dir := range ds2.SelectedDirs {
		fmt.Println(dir)
	}
}

This happens to be the program whose execution is captured in the introductory demo GIF.

Motivation

I needed something customizable and lightweight for my Gogent project's potential TUI-based frontend. It's indeed possible to use the official filepicker for selecting directories, but visually unintuitive since you must have already entered a directory to select it. So I had the idea of introducing a checkbox-selection mechanism:

OK

/home/me/
      CoolProject/
      ↪ I want this directory
      
      AwesomeProject/

Better

/home/me/
     [x] CoolProject/ → I want this directory
     [ ] AwesomeProject/

This opens up one's inspiration to then consider the selection of multiple directories, which the model then provides to the client code.

Now the project has been extended to enable file selection as well, something I suspect could come in handy for fine-tuning exactly what a user chooses to present to an LLM as material to examine. That is, on the one hand, the normal case (as I was introduced to it) is to allow an LLM to view files inside some top-level project directory. However, it may be desirable to instead present it a single file, or else a project directory plus a few separate files for enriched context. We'll see how this idea goes.

About

Directory selection Bubble Tea bubble.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages