Help us shape the future of Go! Take the 2026 Go Developer Survey

cliedit

package
v1.3.100 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cliedit cmd/skywire-cli/commands/edit/edit.go c4-vis-cli

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:    "edit [file]",
	Short:  "Terminal text editor (femto)",
	Long:   "Embedded terminal text editor with syntax highlighting (Ctrl+S save, Ctrl+Q quit)",
	Hidden: true,
	Args:   cobra.MaximumNArgs(1),
	Run: func(_ *cobra.Command, args []string) {
		var filename string
		var content string

		if len(args) == 1 {
			filename = args[0]
			data, err := os.ReadFile(filename)
			if err != nil {
				if !os.IsNotExist(err) {
					fmt.Fprintf(os.Stderr, "edit: %v\n", err)
					os.Exit(1)
				}

				content = ""
			} else {
				content = string(data)
			}
		} else {
			filename = "untitled"
			content = ""
		}

		buffer := femto.NewBufferFromString(content, filename)
		view := femto.NewView(buffer)

		if cs := loadColorscheme(); cs != nil {
			view.SetColorscheme(cs)
		}

		app := tview.NewApplication()
		view.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
			switch {
			case event.Key() == tcell.KeyCtrlQ:
				app.Stop()
				return nil
			case event.Key() == tcell.KeyCtrlS:
				if err := saveFile(filename, view); err != nil {
					fmt.Fprintf(os.Stderr, "\nedit: save error: %v\n", err)
				}
				return nil
			}
			return event
		})

		app.SetRoot(view, true)
		if err := app.Run(); err != nil {
			fmt.Fprintf(os.Stderr, "edit: %v\n", err)
			os.Exit(1)
		}
	},
}

RootCmd is the edit command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL