github.com/aretext/aretext@v1.3.0/state/workingdir.go (about)

     1  package state
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  )
     8  
     9  // SetWorkingDirectory changes the working directory to the specified path.
    10  func SetWorkingDirectory(s *EditorState, dirPath string) {
    11  	err := os.Chdir(dirPath)
    12  	if err != nil {
    13  		log.Printf("Error changing working directory to %q: %s", dirPath, err)
    14  		SetStatusMsg(s, StatusMsg{
    15  			Style: StatusMsgStyleError,
    16  			Text:  fmt.Sprintf("Error changing working directory: %s", err),
    17  		})
    18  		return
    19  	}
    20  
    21  	log.Printf("Changed working directory to %q", dirPath)
    22  	SetStatusMsg(s, StatusMsg{
    23  		Style: StatusMsgStyleSuccess,
    24  		Text:  fmt.Sprintf("Changed working directory to \"%s\"", dirPath),
    25  	})
    26  }