cli/clicore -> cli.

This commit is contained in:
Qi Xiao 2019-08-26 16:40:33 +01:00
parent 76a2130fff
commit 85a75c7722
20 changed files with 44 additions and 48 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/clitypes"
"github.com/elves/elvish/cli/codearea"
"github.com/elves/elvish/cli/combobox"
@ -19,7 +19,7 @@ type Config struct {
Store histutil.Store
}
func Start(app *clicore.App, cfg Config) {
func Start(app *cli.App, cfg Config) {
if cfg.Store == nil {
app.Notify("no history store")
return
@ -48,7 +48,7 @@ func Start(app *clicore.App, cfg Config) {
}
})
}
app.MutateAppState(func(s *clicore.State) { s.Listing = &w })
app.MutateAppState(func(s *cli.State) { s.Listing = &w })
}
type items []histutil.Entry

View File

@ -5,7 +5,7 @@ import (
"strconv"
"strings"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/clitypes"
"github.com/elves/elvish/cli/codearea"
"github.com/elves/elvish/cli/combobox"
@ -21,7 +21,7 @@ type Config struct {
Wordifier func(string) []string
}
func Start(app *clicore.App, cfg Config) {
func Start(app *cli.App, cfg Config) {
if cfg.Store == nil {
app.Notify("no history store")
return
@ -56,7 +56,7 @@ func Start(app *clicore.App, cfg Config) {
s.CodeBuffer.InsertAtDot(text)
})
}
app.MutateAppState(func(s *clicore.State) { s.Listing = &w })
app.MutateAppState(func(s *cli.State) { s.Listing = &w })
}
type items struct {

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/clitypes"
"github.com/elves/elvish/cli/combobox"
"github.com/elves/elvish/cli/layout"
@ -24,7 +24,7 @@ type Store interface {
Chdir(dir string) error
}
func Start(app *clicore.App, cfg Config) {
func Start(app *cli.App, cfg Config) {
if cfg.Store == nil {
app.Notify("no dir history store")
return
@ -49,7 +49,7 @@ func Start(app *clicore.App, cfg Config) {
app.Notify(err.Error())
}
}
app.MutateAppState(func(s *clicore.State) { s.Listing = &w })
app.MutateAppState(func(s *cli.State) { s.Listing = &w })
}
func filter(dirs []storedefs.Dir, p string) items {

View File

@ -1,4 +1,4 @@
package clicore
package cli
import (
"fmt"

View File

@ -1,4 +1,4 @@
package clicore
package cli
import (
"errors"

View File

@ -1,6 +0,0 @@
// Package clicore defines the core of Elvish's interactive line editor. It is
// language-agnostic and can be used to build editors for other languages.
//
// The center of this package is the App type. Most other types are either
// states managed by the App or dependencies of the App.
package clicore

View File

@ -1,4 +1,4 @@
package clicore
package cli
import "github.com/elves/elvish/styled"

2
cli/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package cli implements a generic interactive line editor.
package cli

View File

@ -1,4 +1,4 @@
package clicore
package cli
import "sync"

View File

@ -1,4 +1,4 @@
package clicore
package cli
import (
"fmt"

View File

@ -1,4 +1,4 @@
// Package prompt provides an implementation of the clicore.Prompt interface.
// Package prompt provides an implementation of the cli.Prompt interface.
package prompt
import (

View File

@ -1,4 +1,4 @@
package clicore
package cli
import (
"fmt"

View File

@ -1,6 +1,6 @@
// +build !windows,!plan9
package clicore
package cli
import (
"testing"

View File

@ -5,12 +5,12 @@ import (
"unicode"
"unicode/utf8"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/codearea"
"github.com/elves/elvish/util"
)
var bufferBuiltinsData = map[string]func(*clicore.App){
var bufferBuiltinsData = map[string]func(*cli.App){
"move-left": makeMove(moveDotLeft),
"move-right": makeMove(moveDotRight),
"move-left-word": makeMove(moveDotLeftWord),
@ -37,7 +37,7 @@ var bufferBuiltinsData = map[string]func(*clicore.App){
"kill-eol": makeKill(moveDotEOL),
}
func bufferBuiltins(app *clicore.App) map[string]interface{} {
func bufferBuiltins(app *cli.App) map[string]interface{} {
m := make(map[string]interface{})
for name, fn := range bufferBuiltinsData {
m[name] = func() { fn(app) }
@ -50,8 +50,8 @@ func bufferBuiltins(app *clicore.App) map[string]interface{} {
// the editor state.
type pureMover func(buffer string, dot int) int
func makeMove(m pureMover) func(*clicore.App) {
return func(app *clicore.App) {
func makeMove(m pureMover) func(*cli.App) {
return func(app *cli.App) {
app.CodeArea.MutateCodeAreaState(func(s *codearea.State) {
buf := &s.CodeBuffer
buf.Dot = m(buf.Content, buf.Dot)
@ -59,8 +59,8 @@ func makeMove(m pureMover) func(*clicore.App) {
}
}
func makeKill(m pureMover) func(*clicore.App) {
return func(app *clicore.App) {
func makeKill(m pureMover) func(*cli.App) {
return func(app *cli.App) {
app.CodeArea.MutateCodeAreaState(func(s *codearea.State) {
buf := &s.CodeBuffer
newDot := m(buf.Content, buf.Dot)

View File

@ -4,7 +4,7 @@ import (
"fmt"
"os"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/histutil"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vars"
@ -19,7 +19,7 @@ import (
//
// TODO: Rename ReadLine to ReadCode and remove Close.
type Editor struct {
app *clicore.App
app *cli.App
ns eval.Ns
}
@ -50,7 +50,7 @@ func (d dirStore) Dirs() ([]storedefs.Dir, error) {
// NewEditor creates a new editor from input and output terminal files.
func NewEditor(in, out *os.File, ev *eval.Evaler, st storedefs.Store) *Editor {
ns := eval.NewNs()
app := clicore.NewApp(clicore.NewTTY(in, out))
app := cli.NewApp(cli.NewTTY(in, out))
app.Config.Highlighter = makeHighlighter(ev)

View File

@ -5,14 +5,14 @@ import (
"os/exec"
"strings"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cliedit/highlight"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/parse"
"github.com/elves/elvish/util"
)
func makeHighlighter(ev *eval.Evaler) clicore.Highlighter {
func makeHighlighter(ev *eval.Evaler) cli.Highlighter {
return highlight.NewHighlighter(highlight.Dep{
Check: func(n *parse.Chunk) error { return check(ev, n) },
HasCommand: func(cmd string) bool { return hasCommand(ev, cmd) },

View File

@ -1,14 +1,14 @@
package cliedit
import (
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vals"
"github.com/elves/elvish/eval/vars"
"github.com/xiaq/persistent/hashmap"
)
func initInsert(ev *eval.Evaler, app *clicore.App) eval.Ns {
func initInsert(ev *eval.Evaler, app *cli.App) eval.Ns {
abbr := vals.EmptyMap
app.CodeArea.Abbreviations = makeMapIterator(&abbr)

View File

@ -4,7 +4,7 @@ import (
"github.com/elves/elvish/cli/addons/histlist"
"github.com/elves/elvish/cli/addons/lastcmd"
"github.com/elves/elvish/cli/addons/location"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/histutil"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vars"
@ -30,7 +30,7 @@ func initListing() (*bindingMap, eval.Ns) {
}
// Initializes states for the histlist mode and its API.
func initHistlist(app *clicore.App, ev *eval.Evaler, lsBinding *bindingMap, store histutil.Store) eval.Ns {
func initHistlist(app *cli.App, ev *eval.Evaler, lsBinding *bindingMap, store histutil.Store) eval.Ns {
m := emptyBindingMap
binding := newMapBinding(app, ev, &m, lsBinding)
return eval.Ns{
@ -41,7 +41,7 @@ func initHistlist(app *clicore.App, ev *eval.Evaler, lsBinding *bindingMap, stor
}
// Initializes states for the lastcmd mode and its API.
func initLastcmd(app *clicore.App, ev *eval.Evaler, lsBinding *bindingMap, store histutil.Store) eval.Ns {
func initLastcmd(app *cli.App, ev *eval.Evaler, lsBinding *bindingMap, store histutil.Store) eval.Ns {
m := emptyBindingMap
binding := newMapBinding(app, ev, &m, lsBinding)
return eval.Ns{
@ -52,7 +52,7 @@ func initLastcmd(app *clicore.App, ev *eval.Evaler, lsBinding *bindingMap, store
})
}
func initLocation(app *clicore.App, ev *eval.Evaler, lsBinding *bindingMap, store location.Store) eval.Ns {
func initLocation(app *cli.App, ev *eval.Evaler, lsBinding *bindingMap, store location.Store) eval.Ns {
m := emptyBindingMap
binding := newMapBinding(app, ev, &m, lsBinding)
return eval.Ns{

View File

@ -7,7 +7,7 @@ import (
"os/user"
"sync"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/prompt"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vals"
@ -16,7 +16,7 @@ import (
"github.com/elves/elvish/util"
)
func makePrompt(nt notifier, ev *eval.Evaler, ns eval.Ns, computeInit eval.Callable, name string) clicore.Prompt {
func makePrompt(nt notifier, ev *eval.Evaler, ns eval.Ns, computeInit eval.Callable, name string) cli.Prompt {
compute := computeInit
ns[name] = vars.FromPtr(&compute)
return prompt.New(func() styled.Text {

View File

@ -4,7 +4,7 @@ import (
"os"
"testing"
"github.com/elves/elvish/cli/clicore"
"github.com/elves/elvish/cli"
"github.com/elves/elvish/cli/term"
"github.com/elves/elvish/store"
"github.com/elves/elvish/store/storedefs"
@ -44,13 +44,13 @@ func testMain(m *testing.M) int {
return m.Run()
}
func setup() (*clicore.App, clicore.TTYCtrl) {
tty, ttyControl := clicore.NewFakeTTY()
app := clicore.NewApp(tty)
func setup() (*cli.App, cli.TTYCtrl) {
tty, ttyControl := cli.NewFakeTTY()
app := cli.NewApp(tty)
return app, ttyControl
}
func cleanup(tty clicore.TTYCtrl, codeCh <-chan string) {
func cleanup(tty cli.TTYCtrl, codeCh <-chan string) {
// Causes BasicMode to quit
tty.Inject(term.K('\n'))
// Wait until ReadCode has finished execution