console

package
v0.0.0-...-1adbf8b Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const TmplExt = ".tmpl"

TmplExt is the filename extension for templates.

Variables

View Source
var CypherLexer = lexers.Register(MustNewLazyLexer(
	&Config{
		Name:            "Cypher",
		Aliases:         []string{"cypher"},
		Filenames:       []string{"*.cyp", "*.cypher"},
		MimeTypes:       []string{},
		CaseInsensitive: true,
	},
	func() Rules {
		return Rules{
			"root": {
				Include("comment"),
				Include("keywords"),
				Include("clauses"),
				Include("relations"),
				Include("strings"),
				Include("whitespace"),
				Include("barewords"),
			},
			"comment": {
				{Pattern: `^.*//.*\n`, Type: CommentSingle},
			},
			"keywords": {
				{Pattern: `(create|order|match|limit|set|skip|start|return|with|where|delete|foreach|not|by|true|false)\b`, Type: Keyword},
			},
			"clauses": {
				{Pattern: `(all|any|as|asc|ascending|assert|call|case|create|create\s+index|create\s+unique|delete|desc|descending|distinct|drop\s+constraint\s+on|drop\s+index\s+on|end|ends\s+with|fieldterminator|foreach|in|is\s+node\s+key|is\s+null|is\s+unique|limit|load\s+csv\s+from|match|merge|none|not|null|on\s+match|on\s+create|optional\s+match|order\s+by|remove|return|set|skip|single|start|starts\s+with|then|union|union\s+all|unwind|using\s+periodic\s+commit|yield|where|when|with)\b`, Type: Keyword},
			},
			"relations": {
				{Pattern: `(-\[)(.*?)(\]->)`, Type: ByGroups(Operator, UsingSelf("root"), Operator)},
				{Pattern: `(<-\[)(.*?)(\]-)`, Type: ByGroups(Operator, UsingSelf("root"), Operator)},
				{Pattern: `(-\[)(.*?)(\]-)`, Type: ByGroups(Operator, UsingSelf("root"), Operator)},
				{Pattern: `-->|<--|\[|\]`, Type: Operator},
				{Pattern: `<|>|<>|=|<=|=>|\(|\)|\||:|,|;`, Type: Punctuation},
				{Pattern: `[.*{}]`, Type: Punctuation},
			},
			"strings": {
				{Pattern: `"(?:\\[tbnrf\'"\\]|[^\\"])*"`, Type: LiteralString},
				{Pattern: "`(?:``|[^`])+`", Type: NameVariable},
			},
			"whitespace": {
				{Pattern: `\s+`, Type: TextWhitespace},
			},
			"barewords": {
				{Pattern: `[a-z]\w*`, Type: Name},
				{Pattern: `\d+`, Type: LiteralNumber},
			},
		}
	},
))

CypherLexer highlights syntax tokens using Chroma.

View Source
var TmplDir = filepath.Join(internal.Must(os.UserConfigDir()), "persephone", "templates")

Functions

func ChangeFmt

func ChangeFmt(f string)

ChangeFmt creates a new Writer.

func FailureIcon

func FailureIcon() string

func Input

func Input(msg string, def string) (res string)

Input prompts the user to input a single message.

func NewSpinner

func NewSpinner() *spinner.Spinner

NewSpinner creates a new default Spinner, which writes to stderr. Additional options can be set before it is started.

func OnFormatChange

func OnFormatChange(ls ...FmtChangeListener)

func Pwd

func Pwd(msg string) (res string)

Pwd is like Input but does not echo the input.

func Query

func Query(r graph.Request) error

Query executes a statement and returns the result.

func SetFormatter

func SetFormatter(i any, f formatter.Func)

func SuccessIcon

func SuccessIcon() string

func TmplFileName

func TmplFileName(name string) string

TmplFileName returns the basename of the template with the give name. This ensures that the returned name does not contain a file separator, and ends with the template file extension.

func WarningIcon

func WarningIcon() string

func Write

func Write(i any)

Write outputs the given value using the formatting Writer.

func WriteErr

func WriteErr(err error)

WriteErr formats the error message and writes it to stdout.

func WriteResult

func WriteResult(rs []graph.Result) error

WriteResult outputs the Result using a formatting Writer.

Types

type FmtChangeListener

type FmtChangeListener func(i FormatInfo)

type FormatInfo

type FormatInfo struct {
	Format string
	Sep    string
}

type NamedTemplate

type NamedTemplate struct {
	Name       string `json:"Name" view:"Name" yaml:"Name"`
	Tmpl       string `json:"Template" view:"Template" yaml:"Template"`
	Persistent bool   `json:"Persistent" view:"Persistent" yaml:"Persistent"`
}

NamedTemplate holds metadata of a template.

func (NamedTemplate) String

func (t NamedTemplate) String() string

String returns the template name.

type TmplMgr

type TmplMgr struct {
	TmplsByPath map[string]*template.Template
}

TmplMgr loads and saves templates.

func GetTmplMgr

func GetTmplMgr() *TmplMgr

GetTmplMgr returns the default template manager or creates a new one.

func NewTmplMgr

func NewTmplMgr() *TmplMgr

NewTmplMgr creates a new template manager. It manages two transient and persistent templates. Persistent templates are stored in the filesystem at an absolute path.

func (*TmplMgr) Get

func (tm *TmplMgr) Get(path string) (t *template.Template)

Get returns the parsed Template for the given path.

func (*TmplMgr) Load

func (tm *TmplMgr) Load() error

Load parses all template in TmplDir. Already loaded templates with the same name are replaced.

func (*TmplMgr) Set

func (tm *TmplMgr) Set(path, text string) (t *template.Template, err error)

Set creates or replaces a template with the given text. path can be an absolute path or a basename without slashes. If it is an absolute path, the template is saved in that file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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